From 681135cda96f23351bf0d81aa4d871f9209387b5 Mon Sep 17 00:00:00 2001 From: Jyri Sarha Date: Mon, 19 Jun 2023 00:16:16 +0300 Subject: [PATCH] Audio: SRC: Add safeguard against missing, wrong size or type init data In some error situations the configuration init_data may be NULL, and in such a situations we should fail gracefully and not crash. Also adds check that the IPC message is of correct type and for IPC3 only that it is of correct type. Signed-off-by: Jyri Sarha --- src/audio/src/src.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/audio/src/src.c b/src/audio/src/src.c index 31c943d2b..94c0e0aef 100644 --- a/src/audio/src/src.c +++ b/src/audio/src/src.c @@ -920,6 +920,18 @@ static int src_init(struct processing_module *mod) struct comp_data *cd = NULL; comp_dbg(dev, "src_init()"); +#if CONFIG_IPC_MAJOR_3 + if (dev->ipc_config.type != SOF_COMP_SRC) { + comp_err(dev, "src_init(): Wrong IPC config type %u", + dev->ipc_config.type); + return -EINVAL; + } +#endif + if (!cfg->init_data || cfg->size != sizeof(cd->ipc_config)) { + comp_err(dev, "src_init(): Missing or bad size (%u) init data", + cfg->size); + return -EINVAL; + } /* validate init data - either SRC sink or source rate must be set */ if (src_rate_check(cfg->init_data) < 0) {