From: Daniel Golle Date: Mon, 23 Aug 2021 17:11:08 +0000 (+0100) Subject: trace: handle open() return value and make sure string is terminated X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=d716cb5ca3c27e7bff2ab6f793aa4b827fdd3290;p=project%2Fprocd.git trace: handle open() return value and make sure string is terminated Coverity CID: 1446154 Argument cannot be negative Signed-off-by: Daniel Golle --- diff --git a/trace/trace.c b/trace/trace.c index eec21f8..8d90b5e 100644 --- a/trace/trace.c +++ b/trace/trace.c @@ -184,7 +184,12 @@ static void report_seccomp_vialation(pid_t pid, unsigned syscall) char buf[200]; snprintf(buf, sizeof(buf), "/proc/%d/cmdline", pid); int f = open(buf, O_RDONLY); + if (f < 0) + return; + int r = read(f, buf, sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + if (r >= 0) buf[r] = 0; else