diff --git a/src/cgroups/cgroup_utils.c b/src/cgroups/cgroup_utils.c index 078f864..c21e7bc 100644 --- a/src/cgroups/cgroup_utils.c +++ b/src/cgroups/cgroup_utils.c @@ -521,23 +521,28 @@ static char *copy_to_eol(char *p) return sret; } -static void batch_realloc(char **mem, size_t oldlen, size_t newlen) +char *batch_realloc(char *mem, size_t oldlen, size_t newlen) { int newbatches = (newlen / BATCH_SIZE) + 1; int oldbatches = (oldlen / BATCH_SIZE) + 1; - if (!*mem || newbatches > oldbatches) { - *mem = must_realloc(*mem, newbatches * BATCH_SIZE); + if (!mem || newbatches > oldbatches) { + char *tmp; + tmp = must_realloc(mem, newbatches * BATCH_SIZE); + return tmp; } + return mem; } -void append_line(char **dest, size_t oldlen, char *new, size_t newlen) +char *append_line(char *dest, size_t oldlen, char *new, size_t newlen) { + char *tmp; size_t full = oldlen + newlen; - batch_realloc(dest, oldlen, full + 1); + tmp = batch_realloc(dest, oldlen, full + 1); - memcpy(*dest + oldlen, new, newlen + 1); + memcpy(tmp + oldlen, new, newlen + 1); + return tmp; } static inline void drop_trailing_newlines(char *s) @@ -561,7 +566,7 @@ char *read_file(const char *fnam) if (!f) return NULL; while ((linelen = getline(&line, &len, f)) != -1) { - append_line(&buf, fulllen, line, linelen); + buf = append_line(buf, fulllen, line, linelen); fulllen += linelen; } return buf; @@ -691,7 +696,7 @@ char *readat_file(int dirfd, const char *path) move_fd(fd); while ((linelen = getline(&line, &len, f)) != -1) { - append_line(&buf, fulllen, line, linelen); + buf = append_line(buf, fulllen, line, linelen); fulllen += linelen; } diff --git a/src/cgroups/cgroup_utils.h b/src/cgroups/cgroup_utils.h index d1f5639..a40bdf5 100644 --- a/src/cgroups/cgroup_utils.h +++ b/src/cgroups/cgroup_utils.h @@ -79,7 +79,7 @@ extern size_t strlcat(char *d, const char *s, size_t n); #endif extern FILE *fopen_cloexec(const char *path, const char *mode); -extern void append_line(char **dest, size_t oldlen, char *new, size_t newlen); +extern char *append_line(char *dest, size_t oldlen, char *new, size_t newlen); extern char *read_file(const char *fnam); extern char *readat_file(int fd, const char *path); extern char *read_file_strip_newline(const char *fnam); diff --git a/src/proc_fuse.c b/src/proc_fuse.c index 6b503d6..334f6ea 100644 --- a/src/proc_fuse.c +++ b/src/proc_fuse.c @@ -1403,6 +1403,9 @@ __lxcfs_fuse_ops int proc_read(const char *path, char *buf, size_t size, { struct file_info *f = INTTYPE_TO_PTR(fi->fh); + if (!f->buf) + return -EINVAL; + switch (f->type) { case LXC_TYPE_PROC_MEMINFO: if (liblxcfs_functional())