From e4171c89f89828ab2fe5d42a9aa4b4ece3ed695c Mon Sep 17 00:00:00 2001 From: Ranjani Sridharan Date: Mon, 1 Oct 2018 11:12:08 -0700 Subject: [PATCH] eqctl: do not process invalid input file name Fixes seg faults when input file does not exist. Signed-off-by: Ranjani Sridharan --- eqctl/eqctl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eqctl/eqctl.c b/eqctl/eqctl.c index 320b8de..843a047 100644 --- a/eqctl/eqctl.c +++ b/eqctl/eqctl.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #define SOF_CTRL_CMD_BINARY 3 /* TODO: From uapi ipc */ @@ -64,7 +65,13 @@ static int read_setup(unsigned int *data, char setup[], size_t smax) int n_max = smax / sizeof(unsigned int); int separator; + /* open input file */ fh = fopen(setup, "r"); + if (!fh) { + fprintf(stderr, "error: %s\n", strerror(errno)); + return -errno; + } + while (fscanf(fh, "%u", &data[n]) != EOF && n < n_max) { if (n > 0) fprintf(stdout, ",");