From b91f421118ff9c12955295bc88fc19ef09c4a019 Mon Sep 17 00:00:00 2001 From: Zheng Bao Date: Sat, 28 Oct 2023 16:20:04 +0800 Subject: amdfwtool: Check sanity before filling the data array Change-Id: I8284c35a0124ba4588d199024e28d3445c681896 Signed-off-by: Zheng Bao wq Reviewed-on: https://review.coreboot.org/c/coreboot/+/78763 Reviewed-by: Martin L Roth Tested-by: build bot (Jenkins) --- util/amdfwtool/data_parse.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'util') diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c index 728feae053..5e06d974b0 100644 --- a/util/amdfwtool/data_parse.c +++ b/util/amdfwtool/data_parse.c @@ -618,11 +618,16 @@ static int is_valid_entry(char *oneline, regmatch_t match[N_MATCHES]) match[4]: Optional directory level to be dropped match[6]: Optional hash table ID to put the hash for the entry */ - oneline[match[FW_TYPE].rm_eo] = '\0'; - oneline[match[FW_FILE].rm_eo] = '\0'; - oneline[match[OPT_LEVEL].rm_eo] = '\0'; - oneline[match[OPT_HASH_TABLE_ID].rm_eo] = '\0'; - oneline[match[OPT_FWID_TYPE].rm_eo] = '\0'; + if (match[FW_TYPE].rm_eo != -1) + oneline[match[FW_TYPE].rm_eo] = '\0'; + if (match[FW_FILE].rm_eo != -1) + oneline[match[FW_FILE].rm_eo] = '\0'; + if (match[OPT_LEVEL].rm_eo != -1) + oneline[match[OPT_LEVEL].rm_eo] = '\0'; + if (match[OPT_HASH_TABLE_ID].rm_eo != -1) + oneline[match[OPT_HASH_TABLE_ID].rm_eo] = '\0'; + if (match[OPT_FWID_TYPE].rm_eo != -1) + oneline[match[OPT_FWID_TYPE].rm_eo] = '\0'; retval = 1; } else { retval = 0; -- cgit v1.2.3