summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2019-12-20 22:05:59 +0000
committerRoy Marples <roy@marples.name>2019-12-20 22:05:59 +0000
commitf4793642b461282c49ecf9ad8311f79bc9b4f70c (patch)
treec7527fd727db2f485cd850dd087bf44309f12162
parent8a24073ed0fac6adaea0837aef428fd35a175c43 (diff)
downloaddhcpcd-f4793642b461282c49ecf9ad8311f79bc9b4f70c.tar.xz
options: Fix allocating the script option
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.
-rw-r--r--src/if-options.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/if-options.c b/src/if-options.c
index f3f12316..3c7c706e 100644
--- a/src/if-options.c
+++ b/src/if-options.c
@@ -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;
}