From f4793642b461282c49ecf9ad8311f79bc9b4f70c Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 20 Dec 2019 22:05:59 +0000 Subject: [PATCH] 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. --- src/if-options.c | 12 ++++++++++-- 1 file 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; } -- 2.47.2