Skip to content

Commit e68bb29

Browse files
committed
tools: testbench: bound control name and value copies in tb_parse_amixer
tb_parse_amixer() copies the control name and value parsed from a control-script line into two fixed 128-byte stack buffers (control_name, control_params) via memcpy. The copy length is derived from the quote delimiter pointers with no upper bound: - control_name: len = end_str - name_str - find_len, taken from the cset name="..." quotes and never capped to TB_MAX_CTL_NAME_CHARS - control_params: same unchecked length for the value after the closing quote A script line whose name or value exceeds the buffer overflows the stack. The sibling tb_parse_sofctl() parses the same shape safely with strndup(). Reject over-length fields before each memcpy. Signed-off-by: jmestwa-coder <jmestwa@gmail.com>
1 parent 45a3167 commit e68bb29

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

tools/testbench/utils.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,10 +368,18 @@ static int tb_parse_amixer(struct testbench_prm *tp, char *line)
368368
}
369369

370370
len = end_str - name_str - find_len;
371+
if (len < 0 || len >= TB_MAX_CTL_NAME_CHARS) {
372+
fprintf(stderr, "error: control name too long in script line: %s\n", line);
373+
return -EINVAL;
374+
}
371375
memcpy(control_name, name_str + find_len, len);
372376

373377
line_end = line + strlen(line);
374378
len = line_end - end_str - find_end_len;
379+
if (len < 0 || len >= TB_MAX_CTL_NAME_CHARS) {
380+
fprintf(stderr, "error: control value too long in script line: %s\n", line);
381+
return -EINVAL;
382+
}
375383
memcpy(control_params, &end_str[find_end_len], len);
376384

377385
printf("Info: Setting control name '%s' to value (%s)\n", control_name, control_params);

0 commit comments

Comments
 (0)