From: Radosław Korzeniewski Date: Wed, 3 Mar 2021 16:43:28 +0000 (+0100) Subject: console: Fix may be uninitialized in this function. X-Git-Tag: Release-11.3.2~683 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=204fe3c67e2d83e86f4e6fd0646de3bc6f19692c;p=thirdparty%2Fbacula.git console: Fix may be uninitialized in this function. --- diff --git a/bacula/src/console/console.c b/bacula/src/console/console.c index 24f4b110a..cca99ea9f 100644 --- a/bacula/src/console/console.c +++ b/bacula/src/console/console.c @@ -441,8 +441,11 @@ get_first_keyword() static char * get_previous_keyword(int current_point, int nb) { - int i, end=-1, start, inquotes=0; - char *s=NULL; + int i; + int end = -1; + int start = -1; + int inquotes = 0; + char *s = NULL; while (nb-- >= 0) { /* first we look for a space before the current word */ @@ -477,6 +480,11 @@ get_previous_keyword(int current_point, int nb) } } + if (start == -1 || end == -1) { + // something went wrong during scan + return NULL; + } + s = (char *)malloc(end - start + 2); memcpy(s, rl_line_buffer + start, end - start + 1); s[end - start + 1] = 0;