summaryrefslogtreecommitdiffhomepage
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/read.c7
1 files changed, 5 insertions, 2 deletions
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;