Skip to contentSkip to conversation

Initialize local relocator subchunk struct to all zeros

PATCH In review Ross Philipson 4 participants 4 messages Jul 14, 2022 – Jul 19, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Initialize local relocator subchunk struct to all zeros

The way the code is written the tofree variable would never be passed to the free_subchunk() function uninitialized. Coverity cannot determine this and flags the situation as "Using uninitialized value...". The fix is just to initialize the local struct.

Fixes CID 314016
---
 grub-core/lib/relocator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/lib/relocator.c +1 -1
index 68ef128..bfcc70d 100644
@@ -989,7 +989,7 @@ malloc_in_range (struct grub_relocator *rel,
 	if (j != 0 && events[j - 1].pos != events[j].pos)
 	  {
 	    grub_addr_t alloc_start, alloc_end;
-	    struct grub_relocator_subchunk tofree;
+	    struct grub_relocator_subchunk tofree = {0};
 	    struct grub_relocator_subchunk *curschu = &tofree;
 	    if (!oom)
 	      curschu = &res->subchunks[cural];
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Ross,

This looks good to me.

Quoted 8 lines · Ross Philipson

The way the code is written the tofree variable would never be passed to the free_subchunk() function uninitialized. Coverity cannot determine this and flags the situation as "Using uninitialized value...". The fix is just to initialize the local struct.

Fixes CID 314016

Thanks,

Darren.

Quoted 19 lines
---
 grub-core/lib/relocator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/lib/relocator.c +1 -1
index 68ef128..bfcc70d 100644
@@ -989,7 +989,7 @@ malloc_in_range (struct grub_relocator *rel,
 	if (j != 0 && events[j - 1].pos != events[j].pos)
 	  {
 	    grub_addr_t alloc_start, alloc_end;
-	    struct grub_relocator_subchunk tofree;
+	    struct grub_relocator_subchunk tofree = {0};
 	    struct grub_relocator_subchunk *curschu = &tofree;
 	    if (!oom)
 	      curschu = &res->subchunks[cural];
Signature · 1 line
1.8.3.1
Tested-by
#2 lore raw
Quoted 10 lines · Darren Kenny

Hi Ross,

This looks good to me.

Quoted 5 lines · Ross Philipson

The way the code is written the tofree variable would never be passed to the free_subchunk() function uninitialized. Coverity cannot determine this and flags the situation as "Using uninitialized value...". The fix is just to initialize the local struct.

Quoted 5 lines
Quoted 3 lines
Fixes CID 314016

I ran this through a private Coverity scan which marked the bug as eliminated and didn't have any issues running it on a VM.

Alec Brown

Quoted 24 lines

Thanks,

Darren.

Quoted 19 lines
---
 grub-core/lib/relocator.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
grub-core/lib/relocator.c +1 -1
index 68ef128..bfcc70d 100644
@@ -989,7 +989,7 @@ malloc_in_range (struct grub_relocator *rel,
 	if (j != 0 && events[j - 1].pos != events[j].pos)
 	  {
 	    grub_addr_t alloc_start, alloc_end;
-	    struct grub_relocator_subchunk tofree;
+	    struct grub_relocator_subchunk tofree = {0};
 	    struct grub_relocator_subchunk *curschu = &tofree;
 	    if (!oom)
 	      curschu = &res->subchunks[cural];
Signature · 1 line
1.8.3.1
Reviewed-by
#3 lore raw
Quoted 13 lines · Alec Brown
Quoted 12 lines · Darren Kenny

Hi Ross,

This looks good to me.

Quoted 7 lines · Ross Philipson

The way the code is written the tofree variable would never be passed to the free_subchunk() function uninitialized. Coverity cannot determine this and flags the situation as "Using uninitialized value...". The fix is just to initialize the local struct.

Fixes CID 314016
Quoted 8 lines
Quoted 3 lines
Quoted 1 line

I ran this through a private Coverity scan which marked the bug as eliminated and didn't have any issues running it on a VM.

Daniel