changeset 4907:589ea51b1e08 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 f34373025895
children cc40e6ce1d5a
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:30:35 2019 +0000
+++ b/src/if-options.c	Fri Dec 20 22:05:59 2019 +0000
@@ -391,8 +391,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;
 }