changeset 4540:5307a544c5ca draft

script: Fix a memory error
author Roy Marples <roy@marples.name>
date Wed, 19 Jun 2019 18:59:44 +0100
parents 3d212cac74d3
children 331b92976059
files src/script.c
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/script.c	Wed Jun 19 10:42:30 2019 +0000
+++ b/src/script.c	Wed Jun 19 18:59:44 2019 +0100
@@ -491,7 +491,7 @@
 			nenv++;
 	}
 	if (ctx->script_envlen < nenv) {
-		env = reallocarray(ctx->script_env, nenv, sizeof(*env));
+		env = reallocarray(ctx->script_env, nenv + 1, sizeof(*env));
 		if (env == NULL)
 			goto eexit;
 		ctx->script_env = env;
@@ -500,7 +500,7 @@
 	bufp = buf;
 	envp = ctx->script_env;
 	*envp++ = bufp++;
-	envp--; /* Avoid setting the last \0 to an invalid pointer */
+	endp--; /* Avoid setting the last \0 to an invalid pointer */
 	for (; bufp < endp; bufp++) {
 		if (*bufp == '\0')
 			*envp++ = bufp + 1;