mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] libfile: null-terminate buffer as expected
@ 2019-09-16 18:38 Ahmad Fatoum
  2019-09-16 18:48 ` Ahmad Fatoum
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Fatoum @ 2019-09-16 18:38 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

strim calls strlen on buf internally which is undefined because buf
is not null-terminated. Fix this.

Accessing buf+size is safe, because read_file_2 always allocates a
1 byte bigger buffer than the required (non-null-terminated) size.

This leading to errors can be observed by increasing the alignment of
the buffer allocated in read_file_2. This would lead to

	ERROR: Cannot init param from global: ... : Invalid argument

messages whenever nvvar_load is executed.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 lib/libfile.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lib/libfile.c b/lib/libfile.c
index 172602377fc0..92f8fc2608e5 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -136,6 +136,8 @@ char *read_file_line(const char *fmt, ...)
 	if (!buf)
 		goto out;
 
+	buf[size] = '\0';
+
 	line = strim(buf);
 
 	line = xstrdup(line);
-- 
2.23.0


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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-17  7:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16 18:38 [PATCH] libfile: null-terminate buffer as expected Ahmad Fatoum
2019-09-16 18:48 ` Ahmad Fatoum
2019-09-17  7:49   ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox