From: Daniel Golle Date: Sat, 30 Mar 2024 13:07:29 +0000 (+0000) Subject: utils: get_cmdline_val: add missing error check X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=1e411a58f52ea49e5cb4ef4a067ecdab8befd55c;p=project%2Fprocd.git utils: get_cmdline_val: add missing error check Add check to prevent read() in case open() has failed. Coverity CID: 1595922: Error handling issues (NEGATIVE_RETURNS) Fixes: 6f52ef3 ("get_cmdline_val: search for entire name, not just suffix") Signed-off-by: Daniel Golle --- diff --git a/utils/utils.c b/utils/utils.c index e5b1297..aa37c86 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -167,7 +167,12 @@ char *get_cmdline_val_offset(const char *name, char *out, int len, int offset) { char line[CMDLINE_SIZE + 1], *c, *sptr; int i, fd = open("/proc/cmdline", O_RDONLY); - ssize_t r = read(fd, line, sizeof(line) - 1); + ssize_t r; + + if (fd < 0) + return NULL; + + r = read(fd, line, sizeof(line) - 1); close(fd); if (r <= 0)