diff --git a/src/tools.c b/src/tools.c index 3796c98b11b1..5f44a2f0c768 100644 --- a/src/tools.c +++ b/src/tools.c @@ -5751,11 +5751,12 @@ uint32_t parse_line(char *in, char *out, size_t *outlen, char **args, int *nbarg /* end of output string */ EMIT_CHAR(0); - /* don't add empty arg after trailing spaces. Note that args[arg] - * may contain some distances relative to NULL if was NULL, - * so we test instead of args[arg]. + /* Don't add an empty arg after trailing spaces. Note that args[arg] + * may contain some distances relative to NULL if was NULL, or + * pointers beyond the end of in case is too short, thus + * we must not dereference it. */ - if (arg < argsmax && out && *(args[arg])) + if (arg < argsmax && args[arg] != out + outpos - 1) arg++; if (quote) {