From: Roy Marples Date: Wed, 12 Feb 2014 11:16:22 +0000 (+0000) Subject: PATH_MAX is too much, lets be more precise X-Git-Tag: v6.3.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1681b126096ebfacf3f4da9b4c677af54a97bcd0;p=thirdparty%2Fdhcpcd.git PATH_MAX is too much, lets be more precise --- diff --git a/bpf.c b/bpf.c index 6617f060..7e48efb1 100644 --- 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 c9eaf469..ff9411bf 100644 --- 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 322ad0dd..a7d873cd 100644 --- 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; diff --git a/if-options.c b/if-options.c index 3a5b6c0f..2e0f2eeb 100644 --- a/if-options.c +++ b/if-options.c @@ -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); diff --git a/if-options.h b/if-options.h index 138c0bdc..bba7f9d3 100644 --- a/if-options.h +++ b/if-options.h @@ -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; diff --git a/script.c b/script.c index ec99c5fd..13e2a8d8 100644 --- 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);