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

View file

@ -284,6 +284,7 @@ complete_file (void)
/* Cut away the filename part. */ /* Cut away the filename part. */
dirfile = grub_strrchr (dir, '/'); dirfile = grub_strrchr (dir, '/');
if (dirfile)
dirfile[1] = '\0'; dirfile[1] = '\0';
/* Iterate the directory. */ /* Iterate the directory. */