]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
PATH_MAX is too much, lets be more precise
authorRoy Marples <roy@marples.name>
Wed, 12 Feb 2014 11:16:22 +0000 (11:16 +0000)
committerRoy Marples <roy@marples.name>
Wed, 12 Feb 2014 11:16:22 +0000 (11:16 +0000)
bpf.c
dhcp.h
dhcp6.h
if-options.c
if-options.h
script.c

diff --git a/bpf.c b/bpf.c
index 6617f060bfa3608e315c5d4b51d756d3fadeb2a3..7e48efb15d52ff60a17c0ec6226cdafea6bed20a 100644 (file)
--- a/bpf.c
+++ b/bpf.c
@@ -64,11 +64,11 @@ ipv4_opensocket(struct interface *ifp, int protocol)
 #ifdef _PATH_BPF
        fd = open(_PATH_BPF, O_RDWR | O_CLOEXEC | O_NONBLOCK);
 #else
-       char device[PATH_MAX];
+       char device[32];
        int n = 0;
 
        do {
-               snprintf(device, PATH_MAX, "/dev/bpf%d", n++);
+               snprintf(device, sizeof(device), "/dev/bpf%d", n++);
                fd = open(device, O_RDWR | O_CLOEXEC | O_NONBLOCK);
        } while (fd == -1 && errno == EBUSY);
 #endif
diff --git a/dhcp.h b/dhcp.h
index c9eaf46926acebf3d5e8b79f26066357201cd4e1..ff9411bfecabedf8756229633ef3d8aa226dce72 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -228,7 +228,7 @@ struct dhcp_state {
        struct in_addr net;
        struct in_addr dst;
 
-       char leasefile[PATH_MAX];
+       char leasefile[sizeof(LEASEFILE) + IF_NAMESIZE];
        time_t start_uptime;
 
        unsigned char *clientid;
diff --git a/dhcp6.h b/dhcp6.h
index 322ad0dd79fba9a8fac9a42bec0dbd83a62042e1..a7d873cd0e13eee61c69d878337a739570c6275b 100644 (file)
--- a/dhcp6.h
+++ b/dhcp6.h
@@ -198,7 +198,7 @@ struct dhcp6_state {
        uint32_t lowpl;
        uint32_t sla;
        uint8_t sla_set;
-       char leasefile[PATH_MAX];
+       char leasefile[sizeof(LEASEFILE6) + IF_NAMESIZE];
        const char *reason;
 
        struct authstate auth;
index 3a5b6c0f1b116c448129c81b9dde592738f3950f..2e0f2eeb030978576511d0d311a99f4e6b2c6e38 100644 (file)
@@ -632,7 +632,10 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                ifo->options |= DHCPCD_BACKGROUND;
                break;
        case 'c':
-               strlcpy(ifo->script, arg, sizeof(ifo->script));
+               free(ifo->script);
+               ifo->script = strdup(arg);
+               if (ifo->script == NULL)
+                       syslog(LOG_ERR, "%s: %m", __func__);
                break;
        case 'd':
                ifo->options |= DHCPCD_DEBUG;
@@ -1824,7 +1827,6 @@ read_config(struct dhcpcd_ctx *ctx,
        ifo->metric = -1;
        ifo->auth.options |= DHCPCD_AUTH_REQUIRE;
        TAILQ_INIT(&ifo->auth.tokens);
-       strlcpy(ifo->script, SCRIPT, sizeof(ifo->script));
 
        ifo->vendorclassid[0] = dhcp_vendor((char *)ifo->vendorclassid + 1,
            sizeof(ifo->vendorclassid) - 1);
@@ -2042,6 +2044,7 @@ free_options(struct if_options *ifo)
                        free(ifo->config);
                }
                ipv4_freeroutes(ifo->routes);
+               free(ifo->script);
                free(ifo->arping);
                free(ifo->blacklist);
                free(ifo->fallback);
index 138c0bdc5dd9abb8c676942da133bac30c08bb0c..bba7f9d34b678aec04124c85f3716b6ad8174d84 100644 (file)
@@ -146,7 +146,7 @@ struct if_options {
        char **config;
 
        char **environ;
-       char script[PATH_MAX];
+       char *script;
 
        char hostname[HOSTNAME_MAX_LEN + 1]; /* We don't store the length */
        int fqdn;
index ec99c5fdcb7e0e11d2fc25728a5ac6a1ad3e05b6..13e2a8d8cd26da3dd55874def2c7ce329df2c4e8 100644 (file)
--- a/script.c
+++ b/script.c
@@ -511,7 +511,7 @@ send_interface(int fd, const struct interface *iface)
 int
 script_runreason(const struct interface *ifp, const char *reason)
 {
-       char *const argv[2] = { UNCONST(ifp->options->script), NULL };
+       char *argv[2];
        char **env = NULL, **ep;
        char *path, *bigenv;
        ssize_t e, elen = 0;
@@ -520,11 +520,13 @@ script_runreason(const struct interface *ifp, const char *reason)
        const struct fd_list *fd;
        struct iovec iov[2];
 
-       if (ifp->options->script == NULL ||
-           ifp->options->script[0] == '\0' ||
-           strcmp(ifp->options->script, "/dev/null") == 0)
+       if (ifp->options->script &&
+           (ifp->options->script[0] == '\0' ||
+           strcmp(ifp->options->script, "/dev/null") == 0))
                return 0;
 
+       argv[0] = ifp->options->script ? ifp->options->script : UNCONST(SCRIPT);
+       argv[1] = NULL;
        syslog(LOG_DEBUG, "%s: executing `%s' %s",
            ifp->name, argv[0], reason);