]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
options: Fix allocating the script option
authorRoy Marples <roy@marples.name>
Fri, 20 Dec 2019 22:05:59 +0000 (22:05 +0000)
committerRoy Marples <roy@marples.name>
Fri, 20 Dec 2019 22:05:59 +0000 (22:05 +0000)
When passing PARSE_STRING_NULL we expect to store the string
NULL terminated. As such, allocate space for it an ensure we have
space for it.

src/if-options.c

index f3f12316a2b3f0cf64c68848439f94c8ebbc0306..3c7c706edce502616e40b8f579cbbc4c3983c7f5 100644 (file)
@@ -393,8 +393,16 @@ parse_str(char *sbuf, size_t slen, const char *str, int flags)
                        str++;
                }
        }
-       if (flags == PARSE_STRING_NULL && sbuf)
-               *sbuf = '\0';
+       if (flags == PARSE_STRING_NULL) {
+               l++;
+               if (sbuf != NULL) {
+                       if (l > slen) {
+                               errno = ENOBUFS;
+                               return -1;
+                       }
+                       *sbuf = '\0';
+               }
+       }
        return (ssize_t)l;
 }