Mercurial > hg > dhcpcd
changeset 4908:297aab88bdd2 draft
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.
| author | Roy Marples <roy@marples.name> |
|---|---|
| date | Fri, 20 Dec 2019 22:05:59 +0000 |
| parents | 54922ff09805 |
| children | 647f69cff6bb |
| files | src/if-options.c |
| diffstat | 1 files changed, 10 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/if-options.c Fri Dec 20 11:38:14 2019 +0000 +++ b/src/if-options.c Fri Dec 20 22:05:59 2019 +0000 @@ -393,8 +393,16 @@ 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; }
