From: Mark Wielaard Date: Sat, 25 May 2019 14:25:19 +0000 (+0200) Subject: vgdb: Fix read check in report_pid. X-Git-Tag: VALGRIND_3_16_0~282 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7f48f91b046751def38326f8a8547bb8c98d4f2;p=thirdparty%2Fvalgrind.git vgdb: Fix read check in report_pid. 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. --- diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 075c737fd1..e678eac2db 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -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] = ' ';