]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
console: Fix may be uninitialized in this function.
authorRadosław Korzeniewski <radoslaw@korzeniewski.net>
Wed, 3 Mar 2021 16:43:28 +0000 (17:43 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:00 +0000 (09:03 +0100)
bacula/src/console/console.c

index 24f4b110a6835cc3d7b9f60c4e647c2b479e115b..cca99ea9fbd1892e854b87b7d2cae34ed90ec35b 100644 (file)
@@ -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;