From: Joan Lledó <jlle...@member.fsf.org>

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.
---
 src/dhcp-common.c | 7 ++++++-
 src/script.c      | 6 +++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/dhcp-common.c b/src/dhcp-common.c
index 14d2d92a..3679b79e 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[IF_NAMESIZE];
        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 + 1, sizeof(escaped_ifname) - 1,
+                       OT_ESCFILE,
+                       (const uint8_t *)ifp->name, IF_NAMESIZE);
+
        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 0149aee9..aceef7ba 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[IF_NAMESIZE];
        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 + 1, sizeof(escaped_ifname) - 1,
+                       OT_ESCFILE,
+                       (const uint8_t *)ifp->name, IF_NAMESIZE);
+               if (efprintf(fp, "interface=%s", escaped_ifname) == -1)
                        goto eexit;
                if (protocols[protocol] != NULL) {
                        if (efprintf(fp, "protocol=%s",
-- 
2.50.1


Reply via email to