procps-ng/Possible-segfault-in-file2strvec-introduced-by-lates.patch
2019-12-25 17:13:31 +08:00

14 lines
598 B
Diff

diff --git a/proc/readproc.c b/proc/readproc.c
index 0f00231..b5fbbaa 100644
--- a/proc/readproc.c
+++ b/proc/readproc.c
@@ -714,7 +714,7 @@ static char** file2strvec(const char* directory, const char* what) {
#undef ARG_LEN
if (end_of_file &&
((n > 0 && buf[n-1] != '\0') || /* last read char not null */
- (n <= 0 && rbuf[tot-1] != '\0'))) /* last read char not null */
+ (n <= 0 && rbuf && rbuf[tot-1] != '\0'))) /* last read char not null */
buf[n++] = '\0'; /* so append null-terminator */
if (n <= 0) break; /* unneeded (end_of_file = 1) but avoid realloc */