mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Subject: [PATCH] common: misc: support strerror(err) for all err <= MAX_ERRNO
Date: Mon, 21 Sep 2020 09:11:35 +0200	[thread overview]
Message-ID: <20200921071135.561256-1-ahmad@a3f.at> (raw)

We have a _LAST_ERRNO of 3 decimal digits. strerror(_LAST_ERRNO) is ok,
but it's still possible that some code passes a non-error code int,
which will overflow the static buffer. Play it safe and bump up the
buffer size to at least 11 characters. This is enough to represent
all integers, with only 7 characters more static storage.

This way strerror(some_int_passed_by_mistake) will not invoke UB.

Signed-off-by: Ahmad Fatoum <ahmad@a3f.at>
---
Detected by ASAN on sandbox a while ago. The place which passed the
non-errno int needs probably fixing as well, but I need to find it again
first..
---
 common/misc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/common/misc.c b/common/misc.c
index 1c7f93760804..1a1cc071b4d1 100644
--- a/common/misc.c
+++ b/common/misc.c
@@ -22,6 +22,7 @@
 #include <led.h>
 #include <of.h>
 #include <restart.h>
+#include <linux/stringify.h>
 
 int errno;
 EXPORT_SYMBOL(errno);
@@ -29,7 +30,7 @@ EXPORT_SYMBOL(errno);
 
 const char *strerror(int errnum)
 {
-	static char errno_string[10];
+	static char errno_string[sizeof("error -2147483648")];
 
 #ifdef CONFIG_ERRNO_MESSAGES
 	char *str;
-- 
2.28.0


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

             reply	other threads:[~2020-09-21  7:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-21  7:11 Ahmad Fatoum [this message]
2020-09-28  8:28 ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200921071135.561256-1-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox