Jonathon Hall has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/67619 )
Change subject: flashrom.c: Don't crash when programmer parameter string is NULL ......................................................................
flashrom.c: Don't crash when programmer parameter string is NULL
After commit 3b8b93e, invoking flashrom with no programmer parameters would crash due to calling strdup(NULL) in programmer_init().
extract_param() also crashed if the programmer parameter string was NULL.
Test: Build flashrom on Librem Mini v2, test with -p internal, -p internal:laptop=this_is_not_a_laptop, verify no crashes. Read firmware. Also tested with -p ft2232_spi:type=2232H, verify type parameter is respected.
Change-Id: Ie13bdcf63c23d912dc9b774ae279f1ae5883e287 Signed-off-by: Jonathon Hall jonathon.hall@puri.sm --- M flashrom.c 1 file changed, 26 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/19/67619/1
diff --git a/flashrom.c b/flashrom.c index ec16d04..c0f4289 100644 --- a/flashrom.c +++ b/flashrom.c @@ -168,7 +168,10 @@ programmer_may_write = true;
msg_pdbg("Initializing %s programmer\n", prog->name); - const struct programmer_cfg cfg = { .params = strdup(param) }; + struct programmer_cfg cfg = { .params = NULL }; + if(param) { + cfg.params = strdup(param); + } int ret = prog->init(&cfg); ret = get_param_residue(cfg.params, ret); free(cfg.params); @@ -243,7 +246,7 @@ return NULL; } /* No programmer parameters given. */ - if (*haystack == NULL) + if (haystack == NULL || *haystack == NULL) return NULL; param_pos = strstr(*haystack, needle); do {