From: Avnish Chouhan Date: Mon, 10 Nov 2025 14:57:22 +0000 (+0530) Subject: osdep/linux/getroot: Add missing strdup() failure checks X-Git-Tag: grub-2.14~65 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72b4c99376f7c6e6002dfbd7164194f346121871;p=thirdparty%2Fgrub.git 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 Reviewed-by: Sudhakar Kuppusamy Reviewed-by: Daniel Kiper --- diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c index 38fe110fe..d71c373c3 100644 --- a/grub-core/osdep/linux/getroot.c +++ b/grub-core/osdep/linux/getroot.c @@ -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)