From 9f1106d8a5e1321cc0de8ba48c99f9fb6a27c07a Mon Sep 17 00:00:00 2001 From: Mohana Datta Yelugoti Date: Wed, 22 Jul 2020 12:05:29 +0000 Subject: [PATCH] testbench: add null pointer check for function argument tb_pipeline_params() function takes an argument called ipc_pipe, which is a pointer and is derefernced in the function to access a member of structure that pointer is pointing to. If this pointer is NULL, this leads to Segmentation fault. A null pointer check is added before the argument is dereferenced. Signed-off-by: Mohana Datta Yelugoti --- tools/testbench/common_test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/testbench/common_test.c b/tools/testbench/common_test.c index 6726d7a7c..ff668afe2 100644 --- a/tools/testbench/common_test.c +++ b/tools/testbench/common_test.c @@ -99,9 +99,16 @@ int tb_pipeline_params(struct ipc *ipc, struct sof_ipc_pipe_new *ipc_pipe, struct sof_ipc_pcm_params params; char message[DEBUG_MSG_LEN]; int fs_period; - int period = ipc_pipe->period; + int period; int ret = 0; + if (!ipc_pipe) { + fprintf(stderr, "error: ipc_pipe NULL\n"); + return -EINVAL; + } + + period = ipc_pipe->period; + /* Compute period from sample rates */ fs_period = (int)(0.9999 + tp->fs_in * period / 1e6); sprintf(message, "period sample count %d\n", fs_period);