From 8b145a8778f28ed1c0079c008625ce907f77bbbf Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Fri, 19 Feb 2021 14:32:36 +0100 Subject: [PATCH] file_utils: allow fd_to_buf() to fail for real Signed-off-by: Christian Brauner --- src/lxc/file_utils.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lxc/file_utils.c b/src/lxc/file_utils.c index 625654005..6f668988a 100644 --- a/src/lxc/file_utils.c +++ b/src/lxc/file_utils.c @@ -455,12 +455,15 @@ int fd_to_buf(int fd, char **buf, size_t *length) bytes_read = lxc_read_nointr(fd, chunk, sizeof(chunk)); if (bytes_read < 0) - return 0; + return -errno; if (!bytes_read) break; - copy = must_realloc(old, (*length + bytes_read) * sizeof(*old)); + copy = realloc(old, (*length + bytes_read) * sizeof(*old)); + if (!copy) + return ret_errno(ENOMEM); + memcpy(copy + *length, chunk, bytes_read); *length += bytes_read; } -- 2.47.2