[coreboot-gerrit] Patch set updated for coreboot: libpayload/libc: Fix memset/sizeof usage

Jonathan Neuschäfer (j.neuschaefer@gmx.net) gerrit at coreboot.org
Tue Apr 5 21:37:23 CEST 2016


Jonathan Neuschäfer (j.neuschaefer at gmx.net) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14244

-gerrit

commit 1aba292c52013861d9be1a7e4c1c4d00c9e7fd11
Author: Jonathan Neuschäfer <j.neuschaefer at gmx.net>
Date:   Tue Apr 5 21:36:34 2016 +0200

    libpayload/libc: Fix memset/sizeof usage
    
    Since r is a pointer, memset(r, 0, sizeof(r)) would only zero the first
    4 (or 8) bytes of the newly allocated struct align_region_t.
    
    An alternative to this patch would be to use calloc, or introduce a new
    zalloc (zeroed allocation; a single-element calloc) and use that.
    
    Change-Id: Ic3e3487ce749eeebf6c4836e62b8a305ad766e7e
    Found-by: Coverity (ID 1291160)
    Signed-off-by: Jonathan Neuschäfer <j.neuschaefer at gmx.net>
---
 payloads/libpayload/libc/malloc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c
index 7099e47..b7ac1a7 100644
--- a/payloads/libpayload/libc/malloc.c
+++ b/payloads/libpayload/libc/malloc.c
@@ -366,7 +366,7 @@ static struct align_region_t *allocate_region(int alignment, int num_elements,
 	if (r == NULL)
 		return NULL;
 
-	memset(r, 0, sizeof(r));
+	memset(r, 0, sizeof(*r));
 
 	if (num_elements != 0) {
 		r->alignment = alignment;



More information about the coreboot-gerrit mailing list