package: avoid the use of eval to parse ipcalc.sh output

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: e4bd3de1be ("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>
This commit is contained in:
Leon M. Busch-George 2023-06-18 20:17:27 +02:00
parent 59e681eea1
commit 6b23836071
7 changed files with 16 additions and 10 deletions

View File

@ -315,6 +315,11 @@ include() {
done done
} }
ipcalc() {
set -- $(ipcalc.sh "$@")
[ $? -eq 0 ] && export -- "$@"
}
find_mtd_index() { find_mtd_index() {
local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')" local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
local INDEX="${PART##mtd}" local INDEX="${PART##mtd}"

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=netifd PKG_NAME:=netifd
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git

View File

@ -18,13 +18,13 @@ setup_interface () {
proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}" proto_add_ipv4_address "$ip" "${subnet:-255.255.255.0}"
# TODO: apply $broadcast # TODO: apply $broadcast
local ip_net local ip_net IP PREFIX NETWORK NETMASK BROADCAST
eval "$(ipcalc.sh "$ip/$mask")";ip_net="$NETWORK" ipcalc "$ip/$mask" && ip_net="$NETWORK"
local i local i
for i in $router; do for i in $router; do
local gw_net 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" [ "$ip_net" != "$gw_net" ] && proto_add_ipv4_route "$i" 32 "" "$ip"
proto_add_ipv4_route 0.0.0.0 0 "$i" "$ip" proto_add_ipv4_route 0.0.0.0 0 "$i" "$ip"

View File

@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=6rd PKG_NAME:=6rd
PKG_RELEASE:=12 PKG_RELEASE:=13
PKG_LICENSE:=GPL-2.0 PKG_LICENSE:=GPL-2.0
include $(INCLUDE_DIR)/package.mk include $(INCLUDE_DIR)/package.mk

View File

@ -40,8 +40,8 @@ proto_6rd_setup() {
# Determine the relay prefix. # Determine the relay prefix.
local ip4prefixlen="${ip4prefixlen:-0}" local ip4prefixlen="${ip4prefixlen:-0}"
local ip4prefix local ip4prefix IP PREFIX NETWORK NETMASK BROADCAST
eval "$(ipcalc.sh "$ipaddr/$ip4prefixlen")";ip4prefix=$NETWORK ipcalc "$ipaddr/$ip4prefixlen" && ip4prefix="$NETWORK"
# Determine our IPv6 address. # Determine our IPv6 address.
local ip6subnet=$(6rdcalc "$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen") local ip6subnet=$(6rdcalc "$ip6prefix/$ip6prefixlen" "$ipaddr/$ip4prefixlen")

View File

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dnsmasq PKG_NAME:=dnsmasq
PKG_UPSTREAM_VERSION:=2.89 PKG_UPSTREAM_VERSION:=2.89
PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION))) 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:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/ PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/

View File

@ -1,6 +1,8 @@
#!/bin/sh /etc/rc.common #!/bin/sh /etc/rc.common
# Copyright (C) 2007-2012 OpenWrt.org # Copyright (C) 2007-2012 OpenWrt.org
. /lib/functions.sh
START=19 START=19
USE_PROCD=1 USE_PROCD=1
@ -509,7 +511,6 @@ dhcp_boot_add() {
dhcp_option_add "$cfg" "$networkid" "$force" dhcp_option_add "$cfg" "$networkid" "$force"
} }
dhcp_add() { dhcp_add() {
local cfg="$1" local cfg="$1"
local dhcp6range="::" local dhcp6range="::"
@ -587,7 +588,7 @@ dhcp_add() {
fi fi
# make sure the DHCP range is not empty # 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" [ "$dynamicdhcpv4" = "0" ] && END="static"
xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}" xappend "--dhcp-range=$tags$nettag$START,$END,$NETMASK,$leasetime${options:+ $options}"