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@xxxxxxxxx> --- lib/libfile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/libfile.c b/lib/libfile.c index 39c85b2fc..8f2aed230 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) { -- 2.17.1 _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox