summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2018-10-15 10:00:21 -0700
committerSascha Hauer <s.hauer@pengutronix.de>2018-10-16 09:04:08 +0200
commit1e0d7e417acd745e5ddd9fb3b8dbb8691945f62f (patch)
tree11b9d55152eeb246c9f26bdf911581a8d11d1064
parente1818e02408d9e412a2092c2419f323d6b8c7413 (diff)
downloadbarebox-1e0d7e417acd745e5ddd9fb3b8dbb8691945f62f.tar.gz
barebox-1e0d7e417acd745e5ddd9fb3b8dbb8691945f62f.tar.xz
libfile: Error out if out of memory in read_file_2()
All other error cases in read_file_2() are handled gracefully, so there shouldn't be any reason not do so for the case of trying to allocate too much memory. This error path can be easily triggered with: barebox_update file-bigger-than-availible-ram.img Currently this would result in a crash which is not really desirable from user experience. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--lib/libfile.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libfile.c b/lib/libfile.c
index 39c85b2fc0..8f2aed2309 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -185,7 +185,11 @@ again:
goto again;
}
- buf = xzalloc(read_size + 1);
+ buf = calloc(read_size + 1, 1);
+ if (!buf) {
+ ret = -ENOMEM;
+ goto err_out;
+ }
fd = open(filename, O_RDONLY);
if (fd < 0) {