From: Jo-Philipp Wich Date: Fri, 8 Aug 2008 13:45:09 +0000 (+0000) Subject: * luci/libs: properly handle overflows in luci.ip.add() X-Git-Tag: 0.8.0~493 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=a87b197aa8082bdd3c440c76f97088b190dd8dd4;p=project%2Fluci.git * luci/libs: properly handle overflows in luci.ip.add() --- diff --git a/libs/core/luasrc/ip.lua b/libs/core/luasrc/ip.lua index 2fe71297d9..761a781100 100644 --- a/libs/core/luasrc/ip.lua +++ b/libs/core/luasrc/ip.lua @@ -382,8 +382,10 @@ function cidr.add( self, amount ) local add = ( #shorts > 0 ) and table.remove( shorts, #shorts ) or 0 if ( data[pos] + add ) > 0xFFFF then data[pos] = ( data[pos] + add ) % 0xFFFF - if pos > 2 then + if pos > 1 then data[pos-1] = data[pos-1] + ( add - data[pos] ) + else + return nil end else data[pos] = data[pos] + add