From f39cad003e197ec0de07131bf9c99aefc4c2a783 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 22 Nov 2021 09:47:22 +0100 Subject: libfile: null-terminate read_file of wchar_t buffer read_file always nul-terminates the buffer, which is useful when slurping ASCII text into a variable. This doesn't work as well for UCS-2, because we need two aligned nuls there. Fix this. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20211122084732.2597109-21-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- lib/libfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/libfile.c b/lib/libfile.c index 40b1d8bb27..6b373f05ca 100644 --- a/lib/libfile.c +++ b/lib/libfile.c @@ -213,7 +213,8 @@ again: goto again; } - buf = calloc(read_size + 1, 1); + /* ensure wchar_t nul termination */ + buf = calloc(ALIGN(read_size, 2) + 2, 1); if (!buf) { ret = -ENOMEM; errno = ENOMEM; -- cgit v1.2.3