normal/completion: Fix possible NULL pointer dereference

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>
This commit is contained in:
Peter Jones 2020-03-04 12:58:44 +01:00 committed by Daniel Kiper
parent 8d88ae92b5
commit f0f97576e0
1 changed files with 2 additions and 1 deletions

View 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);