Light has uploaded this change for review.
flashrom.c: Initialize dynamically allocated memory using calloc
In flashrom_image_write variables curcontents and oldcontents are
dynamically allocated using malloc. These could remain uninitialized and
when later used in need_erase could result in undefined behaviour. So
allocate them using calloc to initialize them to zeroes or if allocating
using malloc separately initialize them using a loop.
Change-Id: I6b9269129968fb3b55b0d2a2e384c8a1aeba43ab
Signed-off-by: Aarya Chaumal <aarya.chaumal@gmail.com>
---
M flashrom.c
M writeprotect_ranges.c
2 files changed, 2 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/47/62747/1
diff --git a/flashrom.c b/flashrom.c
index ac61259..f1fe651 100644
--- a/flashrom.c
+++ b/flashrom.c
@@ -2036,10 +2036,10 @@
uint8_t *const newcontents = buffer;
const uint8_t *const refcontents = refbuffer;
- uint8_t *const curcontents = malloc(flash_size);
+ uint8_t *const curcontents = calloc(1, flash_size);
uint8_t *oldcontents = NULL;
if (verify_all)
- oldcontents = malloc(flash_size);
+ oldcontents = calloc(1, flash_size);
if (!curcontents || (verify_all && !oldcontents)) {
msg_gerr("Out of memory!\n");
goto _free_ret;
diff --git a/writeprotect_ranges.c b/writeprotect_ranges.c
index b389126..dacce32 100644
--- a/writeprotect_ranges.c
+++ b/writeprotect_ranges.c
@@ -14,7 +14,6 @@
* GNU General Public License for more details.
*/
-#include <assert.h>
#include "writeprotect.h"
#include "chipdrivers.h"
@@ -27,8 +26,6 @@
size_t bp = 0;
size_t bp_max = 0;
- assert(bits->bp_bit_count > 1);
-
for (size_t i = 0; i < bits->bp_bit_count; i++) {
bp |= bits->bp[i] << i;
bp_max |= 1 << i;
To view, visit change 62747. To unsubscribe, or for help writing mail filters, visit settings.