[openwrt/openwrt] base-files: ipcalc.sh: fail when network is too small
LEDE Commits
lede-commits at lists.infradead.org
Tue Feb 7 12:09:35 PST 2023
ansuel pushed a commit to openwrt/openwrt.git, branch master:
https://git.openwrt.org/a40a96e54b0d047d14d99bb715ee2dd94458acb6
commit a40a96e54b0d047d14d99bb715ee2dd94458acb6
Author: Leon M. George <leon at georgemail.eu>
AuthorDate: Fri May 6 00:02:52 2022 +0200
base-files: ipcalc.sh: fail when network is too small
It's possible to move range boundaries in a way that the start address
lies behind the end address.
Detect this condition and exit with an error message.
Signed-off-by: Leon M. George <leon at georgemail.eu>
---
package/base-files/files/bin/ipcalc.sh | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/package/base-files/files/bin/ipcalc.sh b/package/base-files/files/bin/ipcalc.sh
index 66d37952de..b21b6e28dc 100755
--- a/package/base-files/files/bin/ipcalc.sh
+++ b/package/base-files/files/bin/ipcalc.sh
@@ -44,13 +44,14 @@ BEGIN {
}
network=and(ipaddr,netmask)
+ prefix=32-bitcount(compl32(netmask))
broadcast=or(network,compl32(netmask))
print "IP="int2ip(ipaddr)
print "NETMASK="int2ip(netmask)
print "BROADCAST="int2ip(broadcast)
print "NETWORK="int2ip(network)
- print "PREFIX="32-bitcount(compl32(netmask))
+ print "PREFIX="prefix
# range calculations:
# ipcalc <ip> <netmask> <start> <num>
@@ -68,6 +69,11 @@ BEGIN {
if (end>limit) end=limit
if (end==ipaddr) end=ipaddr-1
+ if (start>end) {
+ print "network ("int2ip(network)"/"prefix") too small" > "/dev/stderr"
+ exit(1)
+ }
+
if (ipaddr > start && ipaddr < end) {
print "ipaddr inside range" > "/dev/stderr"
exit(1)
More information about the lede-commits
mailing list