trace: handle open() return value and make sure string is terminated
authorDaniel Golle <daniel@makrotopia.org>
Mon, 23 Aug 2021 17:11:08 +0000 (18:11 +0100)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 24 Aug 2021 17:32:01 +0000 (18:32 +0100)
Coverity CID: 1446154 Argument cannot be negative

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
trace/trace.c

index eec21f8b744e22cc6d3891df202faa6daaf87906..8d90b5ee7fa5e03c99e02e917edb82e15e7f94d0 100644 (file)
@@ -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