From: Roy Marples Date: Thu, 8 Aug 2019 19:40:34 +0000 (+0100) Subject: script: assert that the env strings are correctly terminated X-Git-Tag: v8.0.3~26 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9def0200d01289675ac097cbdbde3f907930cc7f;p=thirdparty%2Fdhcpcd.git script: assert that the env strings are correctly terminated --- diff --git a/src/script.c b/src/script.c index 74aef1b1..f2ee8b27 100644 --- a/src/script.c +++ b/src/script.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -477,12 +478,21 @@ dumplease: fp = NULL; #endif + /* Count the terminated env strings. + * Assert that the terminations are correct. */ nenv = 0; endp = buf + buf_pos; for (bufp = buf; bufp < endp; bufp++) { - if (*bufp == '\0') + if (*bufp == '\0') { +#ifndef NDEBUG + if (bufp + 1 < endp) + assert(*(bufp + 1) != '\0'); +#endif nenv++; + } } + assert(*--bufp == '\0'); + if (ctx->script_envlen < nenv) { env = reallocarray(ctx->script_env, nenv + 1, sizeof(*env)); if (env == NULL)