]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
normal/completion: Fix possible NULL pointer dereference
authorPeter Jones <pjones@redhat.com>
Wed, 4 Mar 2020 11:58:44 +0000 (12:58 +0100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 10 Mar 2020 20:40:23 +0000 (21:40 +0100)
Coverity Scan reports that the grub_strrchr() function can return NULL if
the character is not found. Check if that's the case for dirfile pointer.

Signed-off-by: Peter Jones <pjones@redhat.com>
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/normal/completion.c

index 596102848c14d5e82fbf5628cf5d81fe728312e3..c07100a8de3e4337844a57ad6b085174ff10ef4c 100644 (file)
@@ -284,7 +284,8 @@ complete_file (void)
 
       /* Cut away the filename part.  */
       dirfile = grub_strrchr (dir, '/');
-      dirfile[1] = '\0';
+      if (dirfile)
+       dirfile[1] = '\0';
 
       /* Iterate the directory.  */
       (fs->fs_dir) (dev, dir, iterate_dir, NULL);