diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2021-11-22 09:47:22 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2021-12-13 23:19:38 +0100 |
commit | f39cad003e197ec0de07131bf9c99aefc4c2a783 (patch) | |
tree | 37ca7ecc088243cb3bdc772e39c4597f58ec3e86 | |
parent | 532fba0ef7bfb5ee844f10e771255d80cebcc2dc (diff) | |
download | barebox-f39cad003e197ec0de07131bf9c99aefc4c2a783.tar.gz barebox-f39cad003e197ec0de07131bf9c99aefc4c2a783.tar.xz |
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 <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20211122084732.2597109-21-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | lib/libfile.c | 3 |
1 files changed, 2 insertions, 1 deletions
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; |