]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
vgdb: Fix read check in report_pid.
authorMark Wielaard <mark@klomp.org>
Sat, 25 May 2019 14:25:19 +0000 (16:25 +0200)
committerMark Wielaard <mark@klomp.org>
Sat, 25 May 2019 14:25:19 +0000 (16:25 +0200)
When read fails it will return -1. In which case we might assign
cmdline[sz] = 0 and print a garbage cmdline. Fix the test to check
the return value is > 0.

coregrind/vgdb.c

index 075c737fd12c3f1838b7b267e9d36d34ecffe91a..e678eac2dbfe7e3954397ff8905f849b0c9261cd 100644 (file)
@@ -1090,7 +1090,7 @@ void report_pid(int pid, Bool on_stdout)
    } else {
       char cmdline[100];
       ssize_t sz;
-      while ((sz = read(fd, cmdline, sizeof cmdline - 1)) != 0) {
+      while ((sz = read(fd, cmdline, sizeof cmdline - 1)) > 0) {
          for (i = 0; i < sz; i++)
             if (cmdline[i] == 0)
                cmdline[i] = ' ';