From b131b271a0d89b1ff04fd721530f424d0a15f0b2 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sun, 17 Dec 2006 17:30:01 +0000 Subject: start_stop_daemon: fix bug where any program name was "matching" processes for which readlink(/proc/N/exe) fails --- libbb/read.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libbb') diff --git a/libbb/read.c b/libbb/read.c index b3648b4d7..50e0354ad 100644 --- a/libbb/read.c +++ b/libbb/read.c @@ -118,16 +118,19 @@ void *xmalloc_open_read_close(const char *filename, size_t *sizep) char *buf; size_t size = sizep ? *sizep : INT_MAX; int fd = xopen(filename, O_RDONLY); - off_t len = xlseek(fd, 0, SEEK_END); + /* /proc/N/stat files report len 0 here */ + /* In order to make such files readable, we add small const */ + off_t len = xlseek(fd, 0, SEEK_END) + 256; xlseek(fd, 0, SEEK_SET); if (len > size) bb_error_msg_and_die("file '%s' is too big", filename); size = len; - buf = xmalloc(size+1); + buf = xmalloc(size + 1); size = read_close(fd, buf, size); if ((ssize_t)size < 0) bb_perror_msg_and_die("'%s'", filename); + xrealloc(buf, size + 1); buf[size] = '\0'; if (sizep) *sizep = size; return buf; -- cgit v1.2.3