Adding a failure check after grub_malloc()
cover Adding a failure check after grub_malloc()
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
grub-core/normal/completion.c | 3 +++ grub-core/partmap/msdos.c | 3 +++ grub-core/mmap/mmap.c | 3 +++ grub-core/lib/legacy_parse.c | 3 +++ 4 files changed
Signature · 7 lines
2.31.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 1/4 normal: Adding a grub_malloc failure check in completion.c
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.
--- grub-core/normal/completion.c | 3 +++ 1 file changed, 3 insertions(+)
grub-core/normal/completion.c +3 -0
@@ -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++) {
Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c
Quoted 7 lines · Avnish Chouhan
This patch adds a NULL check in
grub_malloc(). Missing a failure check after callinggrub_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 <[email protected]>
Thanks,
Sudhakar
Quoted 26 lines
---
grub-core/normal/completion.c| 3 +++1 file changed, 3 insertions(+)grub-core/normal/completion.c +3
-0@@ -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++) {Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 2/4 Adding a grub_malloc failure check in msdos.c
In reply to Avnish ChouhanAdding 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.
--- grub-core/partmap/msdos.c | 3 +++ 1 file changed, 3 insertions(+)
grub-core/partmap/msdos.c +3 -0
@@ -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,
Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 2/4] Adding a grub_malloc failure check in msdos.c
Quoted 9 lines · Avnish Chouhan
Adding a NULL check in
grub_malloc(). Missing a failure check after callinggrub_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 <[email protected]>
Thanks,
Sudhakar
Quoted 26 lines
---
grub-core/partmap/msdos.c| 3 +++1 file changed, 3 insertions(+)grub-core/partmap/msdos.c +3
-0@@ -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,Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 3/4 Adding a grub_malloc failure check in mmap.c
In reply to Avnish ChouhanAdding 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.
--- grub-core/mmap/mmap.c | 3 +++ 1 file changed, 3 insertions(+)
grub-core/mmap/mmap.c +3 -0
@@ -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;
Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 3/4] Adding a grub_malloc failure check in mmap.c
Quoted 10 lines · 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 <[email protected]>
Thanks,
Sudhakar
Quoted 26 lines
---
grub-core/mmap/mmap.c| 3 +++1 file changed, 3 insertions(+)grub-core/mmap/mmap.c +3
-0@@ -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;Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
PATCH 4/4 Adding a grub_malloc failure check in legacy_parse.c
In reply to Avnish ChouhanAdding 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.
--- grub-core/lib/legacy_parse.c | 3 +++ 1 file changed, 3 insertions(+)
grub-core/lib/legacy_parse.c +3 -0
@@ -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 ;
Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Re: [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c
Quoted 10 lines · 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 <[email protected]>
Thanks,
Sudhakar
Quoted 26 lines
---
grub-core/lib/legacy_parse.c| 3 +++1 file changed, 3 insertions(+)grub-core/lib/legacy_parse.c +3
-0@@ -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 ;Signature · 7 lines
2.47.1 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 11 lines · Avnish Chouhan
This patch series adds a NULL check after calling
grub_malloc(). Missing a failure check after callinggrub_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)
Quoted 5 lines
Avnish Chouhan (4):
normal: Adding agrub_mallocfailure check incompletion.cAdding agrub_mallocfailure check inmsdos.cAdding agrub_mallocfailure check inmmap.cAdding agrub_mallocfailure check inlegacy_parse.c
For all patches Reviewed-by: Daniel Kiper <[email protected]>...
Thank you for fixing these issues!
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel