From: Christian Brauner Date: Fri, 19 Feb 2021 13:32:36 +0000 (+0100) Subject: file_utils: allow fd_to_buf() to fail for real X-Git-Tag: lxc-5.0.0~276^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8b145a8778f28ed1c0079c008625ce907f77bbbf;p=thirdparty%2Flxc.git file_utils: allow fd_to_buf() to fail for real Signed-off-by: Christian Brauner --- 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; }