]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
script: Fix a memory error
authorRoy Marples <roy@marples.name>
Wed, 19 Jun 2019 17:59:44 +0000 (18:59 +0100)
committerRoy Marples <roy@marples.name>
Wed, 19 Jun 2019 17:59:44 +0000 (18:59 +0100)
src/script.c

index 1952a04f347ddd1882a4bb587bc2a1d630bbedc2..8297eda6860675ed84d37515be6aeb8f066def55 100644 (file)
@@ -491,7 +491,7 @@ dumplease:
                        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 @@ dumplease:
        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;