]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Test we are given an interface in dhcpcd.conf before allocating a new interface
authorRoy Marples <roy@marples.name>
Tue, 13 Dec 2016 20:12:06 +0000 (20:12 +0000)
committerRoy Marples <roy@marples.name>
Tue, 13 Dec 2016 20:12:06 +0000 (20:12 +0000)
block.
Fixes [fb7e08848b].

While here, use reallocarray(3).
Also, fix strskipwhite to return a NULL if the start of the string to the end
is white space and adjust logic accordingly to reduce binary size.

if-options.c

index 6b88982a4d5274bdb214dfde126e18cd45e16ccf..12e1070c51e4ec47ae9dab66161b67809d50920d 100644 (file)
@@ -614,12 +614,12 @@ static char *
 strskipwhite(const char *s)
 {
 
-       if (s == NULL)
+       if (s == NULL || *s == '\0')
                return NULL;
        while (*s == ' ' || *s == '\t') {
+               s++;
                if (*s == '\0')
                        return NULL;
-               s++;
        }
        return UNCONST(s);
 }
@@ -1249,7 +1249,7 @@ parse_option(struct dhcpcd_ctx *ctx, const char *ifname, struct if_options *ifo,
                break;
 #ifdef INET
        case O_ARPING:
-               while (arg && *arg != '\0') {
+               while (arg != NULL) {
                        fp = strwhite(arg);
                        if (fp)
                                *fp++ = '\0';
@@ -2389,7 +2389,7 @@ read_config(struct dhcpcd_ctx *ctx,
                        if (line)
                                line = strskipwhite(line);
                        /* Trim trailing whitespace */
-                       if (line && *line) {
+                       if (line) {
                                p = line + strlen(line) - 1;
                                while (p != line &&
                                    (*p == ' ' || *p == '\t') &&
@@ -2465,7 +2465,7 @@ read_config(struct dhcpcd_ctx *ctx,
                if (line)
                        line = strskipwhite(line);
                /* Trim trailing whitespace */
-               if (line && *line) {
+               if (line) {
                        p = line + strlen(line) - 1;
                        while (p != line &&
                            (*p == ' ' || *p == '\t') &&
@@ -2482,15 +2482,20 @@ read_config(struct dhcpcd_ctx *ctx,
                        char **n;
 
                        new_block = 1;
-                       if (ifname && line && strcmp(line, ifname) == 0)
+                       if (line == NULL) {
+                               /* No interface given */
+                               skip = 1;
+                               continue;
+                       }
+                       if (ifname && strcmp(line, ifname) == 0)
                                skip = 0;
                        else
                                skip = 1;
                        if (ifname)
                                continue;
 
-                       n = realloc(ctx->ifcv,
-                           sizeof(char *) * ((size_t)ctx->ifcc + 1));
+                       n = reallocarray(ctx->ifcv,
+                           (size_t)ctx->ifcc + 1, sizeof(char *));
                        if (n == NULL) {
                                logger(ctx, LOG_ERR, "%s: %m", __func__);
                                continue;