From: Joan Lledó <[email protected]>
dhcpcd creates some directory entries which names are or include interface
names.
In the Hurd, interface names can include invalid characters like `/`. So those
must be escaped.
---
hooks/01-test | 2 +-
hooks/20-resolv.conf | 4 ++--
hooks/50-dhcpcd-compat | 2 +-
hooks/50-ntp.conf | 4 ++--
hooks/50-yp.conf | 2 +-
hooks/dhcpcd-run-hooks.in | 6 +++---
src/dhcp-common.c | 7 ++++++-
src/script.c | 11 +++++++++--
8 files changed, 25 insertions(+), 13 deletions(-)
diff --git a/hooks/01-test b/hooks/01-test
index 99499425..0f5f962d 100644
--- a/hooks/01-test
+++ b/hooks/01-test
@@ -5,7 +5,7 @@ if [ "$reason" = "TEST" ]; then
set | while read line; do
case "$line" in
interface=*|pid=*|reason=*|protocol=*|profile=*|skip_hooks=*)
- echo "$line";;
+ printf '%s\n' "$line";;
esac
done
# Interface flags
diff --git a/hooks/20-resolv.conf b/hooks/20-resolv.conf
index bd0b0df5..f50c695a 100644
--- a/hooks/20-resolv.conf
+++ b/hooks/20-resolv.conf
@@ -57,7 +57,7 @@ build_resolv_conf()
# Assemble resolv.conf using our head and tail files
[ -f "$cf" ] && rm -f "$cf"
[ -d "$resolv_conf_dir" ] || mkdir -p "$resolv_conf_dir"
- echo "$header" > "$cf"
+ printf '%s\n' "$header" > "$cf"
if [ -f /etc/resolv.conf.head ]; then
cat /etc/resolv.conf.head >> "$cf"
else
@@ -217,7 +217,7 @@ if $if_configured; then
if $have_resolvconf && [ "$reason" = NOCARRIER_ROAMING ]; then
# avoid calling resolvconf -c on CARRIER unless we roam
mkdir -p "$nocarrier_roaming_dir"
- echo " " >"$nocarrier_roaming_dir/$interface"
+ printf ' \n' >"$nocarrier_roaming_dir/$interface"
"$resolvconf" -C "$interface.*"
elif $have_resolvconf && [ "$reason" = CARRIER ]; then
# Not all resolvconf implementations support -c
diff --git a/hooks/50-dhcpcd-compat b/hooks/50-dhcpcd-compat
index 0d6256e6..4895857e 100644
--- a/hooks/50-dhcpcd-compat
+++ b/hooks/50-dhcpcd-compat
@@ -34,7 +34,7 @@ if [ "$r" != "down" ]; then
for x in IPADDR INTERFACE NETMASK BROADCAST NETWORK DHCPSID GATEWAYS \
DNSSERVERS DNSDOMAIN DNSSEARCH NISDOMAIN NISSERVERS \
NTPSERVERS GATEWAY DNS; do
- eval echo "$x=\'\$$x\'" >> /var/lib/dhcpcd-"$INTERFACE".info
+ eval printf '%s\n' "$x=\'\$$x\'" >>
/var/lib/dhcpcd-"$INTERFACE".info
done
fi
diff --git a/hooks/50-ntp.conf b/hooks/50-ntp.conf
index cbaa3744..f927ccf0 100644
--- a/hooks/50-ntp.conf
+++ b/hooks/50-ntp.conf
@@ -93,9 +93,9 @@ build_ntp_conf()
fi
if [ -n "$servers" ]; then
- echo "$signature_base${header:+ $from }$header" >> "$cf"
+ printf '%s\n' "$signature_base${header:+ $from }$header" >>
"$cf"
printf %s "$servers" >> "$cf"
- echo "$signature_base_end${header:+ $from }$header" >> "$cf"
+ printf '%s\n' "$signature_base_end${header:+ $from }$header" >>
"$cf"
else
[ -e "$ntp_conf" ] && [ -e "$cf" ] || return
fi
diff --git a/hooks/50-yp.conf b/hooks/50-yp.conf
index c5cdad90..d9afdfe0 100644
--- a/hooks/50-yp.conf
+++ b/hooks/50-yp.conf
@@ -11,7 +11,7 @@ make_yp_conf()
[ -z "${new_nis_domain}${new_nis_servers}" ] && return 0
cf=/etc/yp.conf."$ifname"
rm -f "$cf"
- echo "$signature" > "$cf"
+ printf '%s\n' "$signature" > "$cf"
prefix=
if [ -n "$new_nis_domain" ]; then
if ! valid_domainname "$new_nis_domain"; then
diff --git a/hooks/dhcpcd-run-hooks.in b/hooks/dhcpcd-run-hooks.in
index 91df64b1..169dc97d 100644
--- a/hooks/dhcpcd-run-hooks.in
+++ b/hooks/dhcpcd-run-hooks.in
@@ -25,7 +25,7 @@ uniqify()
*) result="$result${result:+ }$i";;
esac
done
- echo "$result"
+ printf '%s\n' "$result"
}
# List interface config files in a directory.
@@ -175,8 +175,8 @@ syslog()
[ -n "$lvl" ] && shift
[ -n "$*" ] || return 0
case "$lvl" in
- err|error) echo "$interface: $*" >&2;;
- *) echo "$interface: $*";;
+ err|error) printf '%s: %s\n' "$interface" "$*" >&2;;
+ *) printf '%s: %s\n' "$interface" "$*";;
esac
if command -v logger >/dev/null 2>&1; then
logger -i -p daemon."$lvl" -t dhcpcd-run-hooks "$interface: $*"
diff --git a/src/dhcp-common.c b/src/dhcp-common.c
index 14d2d92a..70daf0e6 100644
--- a/src/dhcp-common.c
+++ b/src/dhcp-common.c
@@ -853,6 +853,7 @@ int
dhcp_set_leasefile(char *leasefile, size_t len, int family,
const struct interface *ifp)
{
+ char escaped_ifname[PATH_MAX];
char ssid[1 + (IF_SSIDLEN * 4) + 1]; /* - prefix and NUL terminated. */
if (ifp->name[0] == '\0') {
@@ -869,6 +870,10 @@ dhcp_set_leasefile(char *leasefile, size_t len, int family,
return -1;
}
+ print_string(escaped_ifname, sizeof(escaped_ifname),
+ OT_ESCFILE,
+ (const uint8_t *)ifp->name, strlen(ifp->name));
+
if (ifp->wireless) {
ssid[0] = '-';
print_string(ssid + 1, sizeof(ssid) - 1,
@@ -878,7 +883,7 @@ dhcp_set_leasefile(char *leasefile, size_t len, int family,
ssid[0] = '\0';
return snprintf(leasefile, len,
family == AF_INET ? LEASEFILE : LEASEFILE6,
- ifp->name, ssid);
+ escaped_ifname, ssid);
}
void
diff --git a/src/script.c b/src/script.c
index 51e7ccf2..02349fb7 100644
--- a/src/script.c
+++ b/src/script.c
@@ -232,6 +232,7 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface
*ifp,
const struct interface *ifp2;
int af;
bool is_stdin = ifp->name[0] == '\0';
+ char escaped_ifname[PATH_MAX];
const char *if_up, *if_down;
rb_tree_t ifaces;
struct rt *rt;
@@ -348,7 +349,10 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface
*ifp,
#endif
if (!is_stdin) {
- if (efprintf(fp, "interface=%s", ifp->name) == -1)
+ print_string(escaped_ifname, sizeof(escaped_ifname),
+ OT_ESCFILE,
+ (const uint8_t *)ifp->name, strlen(ifp->name));
+ if (efprintf(fp, "interface=%s", escaped_ifname) == -1)
goto eexit;
if (protocols[protocol] != NULL) {
if (efprintf(fp, "protocol=%s",
@@ -407,7 +411,10 @@ make_env(struct dhcpcd_ctx *ctx, const struct interface
*ifp,
if (rt != RB_TREE_MIN(&ifaces) &&
fprintf(fp, "%s", " ") == -1)
goto eexit;
- if (fprintf(fp, "%s", rt->rt_ifp->name) == -1)
+ print_string(escaped_ifname, sizeof(escaped_ifname),
+ OT_ESCFILE,
+ (const uint8_t *)rt->rt_ifp->name,
strlen(rt->rt_ifp->name));
+ if (fprintf(fp, "%s", escaped_ifname) == -1)
goto eexit;
}
rt_headclear(&ifaces, AF_UNSPEC);
--
2.50.1