From 526bc5dfa924177e68be0123bd67e3370955f924 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 30 Mar 2013 00:00:00 -0500 Subject: [PATCH] library: avoid SEGV if file2str should read zero bytes When utility buffers were introduced for file2str read requests, a subtle change was inadvertently introduced such that a read of zero no longer returns a -1 value. This commit ensures that zero bytes read returns a -1. And although the solution differs from a merge request submitted by sergey.senozhatsky@gmail.com, a thank you is offered for revealing this potential abend problem. References(s): commit a45dace4b82c9cdcda7020ca5665153b1e81275f http://gitorious.org/procps/procps/merge_requests/11 Signed-off-by: Jim Warner Signed-off-by: Craig Small --- proc/readproc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/proc/readproc.c b/proc/readproc.c index d4210a73..71a634b4 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -555,6 +555,7 @@ static int file2str(const char *directory, const char *what, struct utlbuf_s *ub }; ub->buf[tot_read] = '\0'; close(fd); + if (unlikely(tot_read < 1)) return -1; return tot_read; #undef readMAX #undef buffMIN -- 2.40.0