aboutsummaryrefslogtreecommitdiff
path: root/util/amdfwtool/data_parse.c
diff options
context:
space:
mode:
authorZheng Bao <fishbaozi@gmail.com>2022-03-01 17:18:00 +0800
committerFelix Held <felix-coreboot@felixheld.de>2022-03-09 14:02:21 +0000
commit4df5af87bea4761a35415caab7f85658ee0d0ea1 (patch)
treecab7afa7ccbaa54b8278ceec4d7819d1296837c8 /util/amdfwtool/data_parse.c
parent0e545b252da4bf0f017b29572cfc4e2d80db313b (diff)
amdfwtool: Clear struct match before regular expression matching
If it is not cleared and the number of strings is fewer than last iteration, the match[3] will keep the last value, which actually should be empty. Add assert to make sure the level is a legal value. BUG=b:222038278 Change-Id: If14e0923fbb1648d83784eb5dc1411c93227db5a Signed-off-by: Zheng Bao <fishbaozi@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/62482 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
Diffstat (limited to 'util/amdfwtool/data_parse.c')
-rw-r--r--util/amdfwtool/data_parse.c24
1 files changed, 19 insertions, 5 deletions
diff --git a/util/amdfwtool/data_parse.c b/util/amdfwtool/data_parse.c
index a6b73ee1ec..7f1bc3a1f3 100644
--- a/util/amdfwtool/data_parse.c
+++ b/util/amdfwtool/data_parse.c
@@ -428,10 +428,15 @@ int get_input_file_line(FILE *f, char line[], int line_buf_size)
return OK;
}
-static int is_valid_entry(char *oneline, regmatch_t *match)
+#define N_MATCHES 4
+static int is_valid_entry(char *oneline, regmatch_t match[N_MATCHES])
{
- int retval;
+ int retval, index;
+ for (index = 0; index < N_MATCHES; index++) {
+ match[index].rm_so = -1;
+ match[index].rm_eo = -1;
+ }
if (regexec(&entries_line_expr, oneline, 3, match, 0) == 0) {
oneline[match[1].rm_eo] = '\0';
oneline[match[2].rm_eo] = '\0';
@@ -467,7 +472,6 @@ static int skip_comment_blank_line(char *oneline)
return retval;
}
-#define N_MATCHES 4
/*
return value:
0: The config file can not be parsed correctly.
@@ -476,9 +480,15 @@ static int skip_comment_blank_line(char *oneline)
uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_deps)
{
char oneline[MAX_LINE_SIZE], *path_filename;
- regmatch_t match[N_MATCHES] = {0};
+ regmatch_t match[N_MATCHES];
char dir[MAX_LINE_SIZE] = {'\0'};
uint32_t dir_len;
+ int index;
+
+ for (index = 0; index < N_MATCHES; index++) {
+ match[index].rm_so = -1;
+ match[index].rm_eo = -1;
+ }
compile_reg_expr(REG_EXTENDED | REG_NEWLINE,
blank_or_comment_regex, &blank_or_comment_expr);
@@ -527,13 +537,17 @@ uint8_t process_config(FILE *config, amd_cb_config *cb_config, uint8_t print_dep
/* If the optional level field is present,
extract the level char. */
- if (match[3].rm_so != 0) {
+ if (match[3].rm_so != -1) {
if (cb_config->recovery_ab == 0)
ch_lvl = oneline[match[3].rm_so + 1];
else
ch_lvl = oneline[match[3].rm_so + 2];
}
+ assert(ch_lvl == 'x' || ch_lvl == 'X' ||
+ ch_lvl == 'b' || ch_lvl == 'B' ||
+ ch_lvl == '1' || ch_lvl == '2');
+
if (find_register_fw_filename_psp_dir(
&(oneline[match[1].rm_so]),
path_filename, ch_lvl, cb_config) == 0) {