]> granicus.if.org Git - procps-ng/commitdiff
library: avoid SEGV if file2str should read zero bytes
authorJim Warner <james.warner@comcast.net>
Sat, 30 Mar 2013 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Sun, 7 Apr 2013 07:35:49 +0000 (17:35 +1000)
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 <james.warner@comcast.net>
Signed-off-by: Craig Small <csmall@enc.com.au>
proc/readproc.c

index d4210a73d996723ce1f6bbd2bc02655d093947f0..71a634b4df636bb9af9847696739d2d9041ac640 100644 (file)
@@ -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