From cb3de87ff027f8ef83edff0777b433a7e3fe7ebe 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 size and of correct type. Signed-off-by: Jyri Sarha --- src/audio/src/src.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/audio/src/src.c b/src/audio/src/src.c index 193a17746219..c4565a7559df 100644 --- a/src/audio/src/src.c +++ b/src/audio/src/src.c @@ -987,6 +987,12 @@ static int src_init(struct processing_module *mod) comp_dbg(dev, "src_init()"); + if (dev->ipc_config.type != SOF_COMP_SRC || !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) { comp_err(dev, "src_init(): SRC sink and source rate are not set");