Skip to content

Commit b85ab32

Browse files
singalsulgirdwood
authored andcommitted
Tools: Testbench/Tplg_parser: Add check for bytes data size
This patch adds check for bytes data control size into sof-testbench4 for topology embedded control data. Also the missing error handling is added to the topology parser. Signed-off-by: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
1 parent fa1d49a commit b85ab32

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

tools/testbench/include/testbench/utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define TB_MAX_CMD_CHARS 256
2323
#define TB_MAX_CTL_NAME_CHARS 128
2424
#define TB_MAX_VOLUME_SIZE 120
25-
#define TB_MAX_DATA_SIZE 512
25+
#define TB_MAX_BYTES_DATA_SIZE 512
2626

2727
/* number of widgets types supported in testbench */
2828
#define TB_NUM_WIDGETS_SUPPORTED 16
@@ -43,7 +43,7 @@ struct tb_ctl {
4343
unsigned int type;
4444
unsigned int volume_table[TB_MAX_VOLUME_SIZE];
4545
unsigned int index;
46-
char data[TB_MAX_DATA_SIZE];
46+
char data[TB_MAX_BYTES_DATA_SIZE];
4747
char name[TB_MAX_CTL_NAME_CHARS];
4848
union {
4949
struct snd_soc_tplg_mixer_control mixer_ctl;

tools/testbench/topology_ipc4.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1353,6 +1353,11 @@ static int tb_kcontrol_cb_new(struct snd_soc_tplg_ctl_hdr *tplg_ctl,
13531353
ctl->bytes_ctl = *tplg_bytes;
13541354
ctl->index = index;
13551355
ctl->type = tplg_ctl->type;
1356+
if (tplg_bytes->priv.size > TB_MAX_BYTES_DATA_SIZE) {
1357+
fprintf(stderr, "Error: Too large bytes data size %d\n",
1358+
tplg_bytes->priv.size);
1359+
return -EINVAL;
1360+
}
13561361
memcpy(ctl->data, tplg_bytes->priv.data, tplg_bytes->priv.size);
13571362
ctl->comp_info = comp_info;
13581363
strncpy(ctl->name, tplg_ctl->name, TB_MAX_CTL_NAME_CHARS);

tools/tplg_parser/control.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,13 @@ int tplg_create_controls(struct tplg_context *ctx, int num_kcontrols,
141141
return -EINVAL;
142142
}
143143

144-
if (ctx->ctl_cb && object)
145-
ctx->ctl_cb(ctl_hdr, object, ctx->ctl_arg, index);
144+
if (ctx->ctl_cb && object) {
145+
ret = ctx->ctl_cb(ctl_hdr, object, ctx->ctl_arg, index);
146+
if (ret) {
147+
fprintf(stderr, "error: failed control callback\n");
148+
goto err;
149+
}
150+
}
146151
}
147152

148153
if (rctl && ctl_hdr) {

0 commit comments

Comments
 (0)