[PATCH 20/30] libfile: null-terminate read_file of wchar_t buffer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
 lib/libfile.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/libfile.c b/lib/libfile.c
index 40b1d8bb2717..6b373f05ca72 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;
-- 
2.30.2


_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux