osdep/linux/getroot: Add missing strdup() failure checks
If strdup() fails, it returns NULL and passing NULL further down to the code can lead to segmentation fault or an undefined behavior. Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com> Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com> Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
parent
f8c48cbedc
commit
72b4c99376
@ -991,6 +991,8 @@ grub_util_get_raid_grub_dev (const char *os_dev)
|
||||
char *p, *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md_d") - 1);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
@ -1006,6 +1008,8 @@ grub_util_get_raid_grub_dev (const char *os_dev)
|
||||
char *p, *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md/d") - 1);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
@ -1019,6 +1023,8 @@ grub_util_get_raid_grub_dev (const char *os_dev)
|
||||
char *p , *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md") - 1);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
@ -1032,6 +1038,8 @@ grub_util_get_raid_grub_dev (const char *os_dev)
|
||||
char *p , *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md/") - 1);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
@ -1046,6 +1054,8 @@ grub_util_get_raid_grub_dev (const char *os_dev)
|
||||
char *p , *q;
|
||||
|
||||
p = strdup (os_dev + sizeof ("/dev/md/") - 1);
|
||||
if (p == NULL)
|
||||
return NULL;
|
||||
|
||||
q = strchr (p, 'p');
|
||||
if (q)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user