]> 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:08:41 +0000 (22:08 +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 ebe22e015566a7a16e1ee4b93595e1c504827ee7..467bd367d2f2236c91e0d680543a126544c535bb 100644 (file)
@@ -391,8 +391,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;
 }