From 204fe3c67e2d83e86f4e6fd0646de3bc6f19692c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rados=C5=82aw=20Korzeniewski?= Date: Wed, 3 Mar 2021 17:43:28 +0100 Subject: [PATCH] console: Fix may be uninitialized in this function. --- bacula/src/console/console.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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; -- 2.47.3