* [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
@ 2025-10-28 16:31 ` Avnish Chouhan
2025-11-02 14:54 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 2/4] Adding a grub_malloc failure check in msdos.c Avnish Chouhan
` (3 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Avnish Chouhan @ 2025-10-28 16:31 UTC (permalink / raw)
To: grub-devel; +Cc: daniel.kiper, Avnish Chouhan
This patch adds a NULL check in grub_malloc(). Missing a failure check
after calling grub_malloc() can lead to undefined behavior. If the allocation
fails and returns NULL, subsequent dereferencing or writing to the pointer
will likely result in a runtime error such as a segmentation fault.
Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
---
grub-core/normal/completion.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
index 18cadfa..4058e0a 100644
--- a/grub-core/normal/completion.c
+++ b/grub-core/normal/completion.c
@@ -490,6 +490,9 @@ grub_normal_do_completion (char *buf, int *restore,
spaces++;
ret = grub_malloc (match_len - current_len + grub_strlen (suffix) + spaces + 1);
+ if (ret == NULL)
+ goto fail;
+
newstr = ret;
for (escstr = match + current_len; *escstr; escstr++)
{
--
2.47.1
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c
2025-10-28 16:31 ` [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c Avnish Chouhan
@ 2025-11-02 14:54 ` Sudhakar Kuppusamy
0 siblings, 0 replies; 10+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-02 14:54 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: daniel.kiper, Avnish Chouhan
On 28 Oct 2025, at 10:01 PM, Avnish Chouhan <avnish@linux.ibm.com> wrote:
>
> This patch adds a NULL check in grub_malloc(). Missing a failure check
> after calling grub_malloc() can lead to undefined behavior. If the allocation
> fails and returns NULL, subsequent dereferencing or writing to the pointer
> will likely result in a runtime error such as a segmentation fault.
>
> Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Thanks,
Sudhakar
> ---
> grub-core/normal/completion.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
> index 18cadfa..4058e0a 100644
> --- a/grub-core/normal/completion.c
> +++ b/grub-core/normal/completion.c
> @@ -490,6 +490,9 @@ grub_normal_do_completion (char *buf, int *restore,
> spaces++;
>
> ret = grub_malloc (match_len - current_len + grub_strlen (suffix) + spaces + 1);
> + if (ret == NULL)
> + goto fail;
> +
> newstr = ret;
> for (escstr = match + current_len; *escstr; escstr++)
> {
> --
> 2.47.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 2/4] Adding a grub_malloc failure check in msdos.c
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
2025-10-28 16:31 ` [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c Avnish Chouhan
@ 2025-10-28 16:32 ` Avnish Chouhan
2025-11-02 14:57 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 3/4] Adding a grub_malloc failure check in mmap.c Avnish Chouhan
` (2 subsequent siblings)
4 siblings, 1 reply; 10+ messages in thread
From: Avnish Chouhan @ 2025-10-28 16:32 UTC (permalink / raw)
To: grub-devel; +Cc: daniel.kiper, Avnish Chouhan
Adding a NULL check in grub_malloc(). Missing a failure check after calling grub_malloc() can lead to
undefined behavior. If the allocation fails and returns NULL, subsequent
dereferencing or writing to the pointer will likely result in a runtime
error such as a segmentation fault.
Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
---
grub-core/partmap/msdos.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c
index c85bb74..bf92617 100644
--- a/grub-core/partmap/msdos.c
+++ b/grub-core/partmap/msdos.c
@@ -348,6 +348,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
* area.
*/
embed_signature_check = grub_malloc (GRUB_DISK_SECTOR_SIZE);
+ if (embed_signature_check == NULL)
+ return grub_errno;
+
for (i = 0; i < *nsectors; i++)
{
if (grub_disk_read (disk, (*sectors)[i], 0, GRUB_DISK_SECTOR_SIZE,
--
2.47.1
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 2/4] Adding a grub_malloc failure check in msdos.c
2025-10-28 16:32 ` [PATCH 2/4] Adding a grub_malloc failure check in msdos.c Avnish Chouhan
@ 2025-11-02 14:57 ` Sudhakar Kuppusamy
0 siblings, 0 replies; 10+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-02 14:57 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: daniel.kiper, Avnish Chouhan
> On 28 Oct 2025, at 10:02 PM, Avnish Chouhan <avnish@linux.ibm.com> wrote:
>
> Adding a NULL check in grub_malloc(). Missing a failure check after calling grub_malloc() can lead to
> undefined behavior. If the allocation fails and returns NULL, subsequent
> dereferencing or writing to the pointer will likely result in a runtime
> error such as a segmentation fault.
>
> Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Thanks,
Sudhakar
> ---
> grub-core/partmap/msdos.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c
> index c85bb74..bf92617 100644
> --- a/grub-core/partmap/msdos.c
> +++ b/grub-core/partmap/msdos.c
> @@ -348,6 +348,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
> * area.
> */
> embed_signature_check = grub_malloc (GRUB_DISK_SECTOR_SIZE);
> + if (embed_signature_check == NULL)
> + return grub_errno;
> +
> for (i = 0; i < *nsectors; i++)
> {
> if (grub_disk_read (disk, (*sectors)[i], 0, GRUB_DISK_SECTOR_SIZE,
> --
> 2.47.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 3/4] Adding a grub_malloc failure check in mmap.c
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
2025-10-28 16:31 ` [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c Avnish Chouhan
2025-10-28 16:32 ` [PATCH 2/4] Adding a grub_malloc failure check in msdos.c Avnish Chouhan
@ 2025-10-28 16:32 ` Avnish Chouhan
2025-11-02 14:58 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c Avnish Chouhan
2025-11-05 19:11 ` [PATCH 0/4] Adding a failure check after grub_malloc() Daniel Kiper
4 siblings, 1 reply; 10+ messages in thread
From: Avnish Chouhan @ 2025-10-28 16:32 UTC (permalink / raw)
To: grub-devel; +Cc: daniel.kiper, Avnish Chouhan
Adding a failure check after calling grub_malloc() as it can lead to
undefined behavior. If the allocation fails and returns NULL, subsequent
dereferencing or writing to the pointer will likely result in a runtime
error such as a segmentation fault.
Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
---
grub-core/mmap/mmap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
index c8c8312..8f03b77 100644
--- a/grub-core/mmap/mmap.c
+++ b/grub-core/mmap/mmap.c
@@ -242,6 +242,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
else
{
struct mm_list *n = grub_malloc (sizeof (*n));
+ if (n == NULL)
+ return grub_errno;
+
n->val = ctx.scanline_events[i].memtype;
n->present = 1;
n->next = present[ctx.scanline_events[i].priority].next;
--
2.47.1
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 3/4] Adding a grub_malloc failure check in mmap.c
2025-10-28 16:32 ` [PATCH 3/4] Adding a grub_malloc failure check in mmap.c Avnish Chouhan
@ 2025-11-02 14:58 ` Sudhakar Kuppusamy
0 siblings, 0 replies; 10+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-02 14:58 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: daniel.kiper, Avnish Chouhan
> On 28 Oct 2025, at 10:02 PM, Avnish Chouhan <avnish@linux.ibm.com> wrote:
>
> Adding a failure check after calling grub_malloc() as it can lead to
> undefined behavior. If the allocation fails and returns NULL, subsequent
> dereferencing or writing to the pointer will likely result in a runtime
> error such as a segmentation fault.
>
> Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Thanks,
Sudhakar
> ---
> grub-core/mmap/mmap.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c
> index c8c8312..8f03b77 100644
> --- a/grub-core/mmap/mmap.c
> +++ b/grub-core/mmap/mmap.c
> @@ -242,6 +242,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
> else
> {
> struct mm_list *n = grub_malloc (sizeof (*n));
> + if (n == NULL)
> + return grub_errno;
> +
> n->val = ctx.scanline_events[i].memtype;
> n->present = 1;
> n->next = present[ctx.scanline_events[i].priority].next;
> --
> 2.47.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
` (2 preceding siblings ...)
2025-10-28 16:32 ` [PATCH 3/4] Adding a grub_malloc failure check in mmap.c Avnish Chouhan
@ 2025-10-28 16:32 ` Avnish Chouhan
2025-11-02 15:00 ` Sudhakar Kuppusamy
2025-11-05 19:11 ` [PATCH 0/4] Adding a failure check after grub_malloc() Daniel Kiper
4 siblings, 1 reply; 10+ messages in thread
From: Avnish Chouhan @ 2025-10-28 16:32 UTC (permalink / raw)
To: grub-devel; +Cc: daniel.kiper, Avnish Chouhan
Adding a failure check after calling grub_malloc() as it can lead to
undefined behavior. If the allocation fails and returns NULL, subsequent
dereferencing or writing to the pointer will likely result in a runtime
error such as a segmentation fault.
Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
---
grub-core/lib/legacy_parse.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c
index fa0131a..8995309 100644
--- a/grub-core/lib/legacy_parse.c
+++ b/grub-core/lib/legacy_parse.c
@@ -508,6 +508,9 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
char *ret;
int len = grub_strlen (buf);
ret = grub_malloc (len + 2);
+ if (ret == NULL)
+ return NULL;
+
grub_memcpy (ret, buf, len);
if (len && ret[len - 1] == '\n')
ret[len] = 0;
--
2.47.1
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c
2025-10-28 16:32 ` [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c Avnish Chouhan
@ 2025-11-02 15:00 ` Sudhakar Kuppusamy
0 siblings, 0 replies; 10+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-02 15:00 UTC (permalink / raw)
To: The development of GNU GRUB; +Cc: daniel.kiper, Avnish Chouhan
> On 28 Oct 2025, at 10:02 PM, Avnish Chouhan <avnish@linux.ibm.com> wrote:
>
> Adding a failure check after calling grub_malloc() as it can lead to
> undefined behavior. If the allocation fails and returns NULL, subsequent
> dereferencing or writing to the pointer will likely result in a runtime
> error such as a segmentation fault.
>
> Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Thanks,
Sudhakar
> ---
> grub-core/lib/legacy_parse.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c
> index fa0131a..8995309 100644
> --- a/grub-core/lib/legacy_parse.c
> +++ b/grub-core/lib/legacy_parse.c
> @@ -508,6 +508,9 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
> char *ret;
> int len = grub_strlen (buf);
> ret = grub_malloc (len + 2);
> + if (ret == NULL)
> + return NULL;
> +
> grub_memcpy (ret, buf, len);
> if (len && ret[len - 1] == '\n')
> ret[len] = 0;
> --
> 2.47.1
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/4] Adding a failure check after grub_malloc()
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
` (3 preceding siblings ...)
2025-10-28 16:32 ` [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c Avnish Chouhan
@ 2025-11-05 19:11 ` Daniel Kiper
4 siblings, 0 replies; 10+ messages in thread
From: Daniel Kiper @ 2025-11-05 19:11 UTC (permalink / raw)
To: Avnish Chouhan; +Cc: grub-devel
On Tue, Oct 28, 2025 at 10:01:58PM +0530, Avnish Chouhan wrote:
> This patch series adds a NULL check after calling grub_malloc().
> Missing a failure check after calling grub_malloc() can lead to undefined
> behavior. If the allocation fails and returns NULL, subsequent dereferencing
> or writing to the pointer will likely result in a runtime error such as
> a segmentation fault.
>
> Patch 1/4 (0001-normal-Adding-a-grub_malloc-failure-check-in-completion-c.patch)
> Patch 2/4 (0002-Adding-a-grub_malloc-failure-check-in-msdos-c.patch)
> Patch 3/4 (0003-Adding-a-grub_malloc-failure-check-in-mmap-c.patch)
> Patch 4/4 (0004-Adding-a-grub_malloc-failure-check-in-legacy_parse-c.patch)
>
> Avnish Chouhan (4):
> normal: Adding a grub_malloc failure check in completion.c
> Adding a grub_malloc failure check in msdos.c
> Adding a grub_malloc failure check in mmap.c
> Adding a grub_malloc failure check in legacy_parse.c
For all patches Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>...
Thank you for fixing these issues!
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 10+ messages in thread