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:08:41 +0000
commitccbd6e8d7b562004d34d05c84c560a2383d2f9da (patch)
treedaf91472886b8816b369a783df90d42882d63433
parent0cb0f52019974b3bba81fadcbb49173e67975d58 (diff)
downloaddhcpcd-ccbd6e8d7b562004d34d05c84c560a2383d2f9da.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 ebe22e01..467bd367 100644
--- a/src/if-options.c
+++ b/src/if-options.c
@@ -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;
}