package: avoid the use of eval to parse ipcalc.sh output
authorLeon M. Busch-George <leon@georgemail.eu>
Sun, 18 Jun 2023 18:17:27 +0000 (20:17 +0200)
committerLeon M. Busch-George <leon@georgemail.eu>
Mon, 25 Sep 2023 13:02:49 +0000 (15:02 +0200)
Add a function 'ipcalc' to /lib/functions.sh that sets variables more
safely using export.
With this new function, dnsmasq also handles the return value of ipcalc
correctly.

Fixes: e4bd3de1be8e ("dnsmasq: refuse to add empty DHCP range")
Co-Authored-By: Philip Prindeville <philipp@redfish-solutions.com>
Signed-off-by: Leon M. Busch-George <leon@georgemail.eu>
package/base-files/files/lib/functions.sh
package/network/config/netifd/Makefile
package/network/config/netifd/files/lib/netifd/dhcp.script
package/network/ipv6/6rd/Makefile
package/network/ipv6/6rd/files/6rd.sh
package/network/services/dnsmasq/Makefile
package/network/services/dnsmasq/files/dnsmasq.init

index 4b1b838572a0cd6060856d44fcf9e5da4d14c697..bbdecbbc47586dc8a0376b0215ce415dff9c03b7 100644 (file)
@@ -315,6 +315,11 @@ include() {
        done
 }
 
+ipcalc() {
+       set -- $(ipcalc.sh "$@")
+       [ $? -eq 0 ] && export -- "$@"
+}
+
 find_mtd_index() {
        local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
        local INDEX="${PART##mtd}"
index e60e5920983f2f70072c0679bdba40ef089b2169..811d745a6fcd621720abb6954e98b0d5ed495297 100644 (file)
@@ -1,7 +1,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=netifd
-PKG_RELEASE:=1
+PKG_RELEASE:=2
 
 PKG_SOURCE_PROTO:=git
 PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git
index 6fcf139beba34b56266206373417cc6cba604366..db8deac9e67157e9c2c2ae67adb09ad614256aa4 100755 (executable)
@@ -18,13 +18,13 @@ setup_interface () {
        proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
        # TODO: apply $broadcast
 
-       local ip_net
-       eval "$(ipcalc.sh "$ip/$mask")";ip_net="$NETWORK"
+       local ip_net IP PREFIX NETWORK NETMASK BROADCAST
+       ipcalc "$ip/$mask" && ip_net="$NETWORK"
 
        local i
        for i in $router; do
                local gw_net
-               eval "$(ipcalc.sh "$i/$mask")";gw_net="$NETWORK"
+               ipcalc "$i/$mask" && gw_net="$NETWORK"
 
                [ "$ip_net" != "$gw_net" ] && proto_add_ipv4_route "$i" 32 "" "$ip"
                proto_add_ipv4_route 0.0.0.0 0 "$i" "$ip"
index e2ca4e12003c53dac82bf45a857797b8f043f48e..3ab8198ef312de394ac9bbae78ed54818c1b9ef2 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=6rd
-PKG_RELEASE:=12
+PKG_RELEASE:=13
 PKG_LICENSE:=GPL-2.0
 
 include $(INCLUDE_DIR)/package.mk
index 62a20314d9322b56a3785f9f4b5adf7523a2460d..dad61118fe675af34c1edc25c05f9561ef8f6fa3 100644 (file)
@@ -40,8 +40,8 @@ proto_6rd_setup() {
 
        # Determine the relay prefix.
        local ip4prefixlen="${ip4prefixlen:-0}"
-       local ip4prefix
-       eval "$(ipcalc.sh "$ipaddr/$ip4prefixlen")";ip4prefix=$NETWORK
+       local ip4prefix IP PREFIX NETWORK NETMASK BROADCAST
+       ipcalc "$ipaddr/$ip4prefixlen" && ip4prefix="$NETWORK"
 
        # Determine our IPv6 address.
        local ip6subnet=$(6rdcalc "$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen")
index 4272398a927440129b4b9733db372fff83ab2fca..54b95d414deea7db2712fbb42f9a1fab5d8ede56 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=dnsmasq
 PKG_UPSTREAM_VERSION:=2.89
 PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
-PKG_RELEASE:=4
+PKG_RELEASE:=5
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
 PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/
index 2a3327b0c6f2638f7d092d5b3b3d6e48a2a5472f..184e7ff0ed571b62bde2a1268fb3b74a9420e7c6 100755 (executable)
@@ -1,6 +1,8 @@
 #!/bin/sh /etc/rc.common
 # Copyright (C) 2007-2012 OpenWrt.org
 
+. /lib/functions.sh
+
 START=19
 
 USE_PROCD=1
@@ -509,7 +511,6 @@ dhcp_boot_add() {
        dhcp_option_add "$cfg" "$networkid" "$force"
 }
 
-
 dhcp_add() {
        local cfg="$1"
        local dhcp6range="::"
@@ -587,7 +588,7 @@ dhcp_add() {
        fi
 
        # make sure the DHCP range is not empty
-       if [ "$dhcpv4" != "disabled" ] && eval "$(ipcalc.sh "${subnet%%/*}" "$netmask" "$start" "$limit")" ; then
+       if [ "$dhcpv4" != "disabled" ] && ipcalc "${subnet%%/*}" "$netmask" "$start" "$limit" ; then
                [ "$dynamicdhcpv4" = "0" ] && END="static"
 
                xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"