base-files: ipcalc.sh: don't include own address in range
authorLeon M. George <leon@georgemail.eu>
Thu, 5 May 2022 21:47:47 +0000 (23:47 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Tue, 7 Feb 2023 20:05:56 +0000 (21:05 +0100)
Make sure our own address doesn't lie in the calculated range.

Signed-off-by: Leon M. George <leon@georgemail.eu>
package/base-files/files/bin/ipcalc.sh

index 9b2c4d2afc851f32ad90b73f0bf15761278615e9..66d37952de8ee02a37320efdebe7fabfc6513ab9 100755 (executable)
@@ -61,10 +61,17 @@ BEGIN {
        start=or(network,and(ip2int(ARGV[3]),compl32(netmask)))
        limit=network+1
        if (start<limit) start=limit
+       if (start==ipaddr) start=ipaddr+1
 
        end=start+ARGV[4]
        limit=or(network,compl32(netmask))-1
        if (end>limit) end=limit
+       if (end==ipaddr) end=ipaddr-1
+
+       if (ipaddr > start && ipaddr < end) {
+               print "ipaddr inside range" > "/dev/stderr"
+               exit(1)
+       }
 
        print "START="int2ip(start)
        print "END="int2ip(end)