summaryrefslogtreecommitdiffstats
path: root/common/misc.c
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2020-09-21 09:11:35 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2020-09-28 10:28:11 +0200
commitf3c05f20dcb09159141c8843d909a26997cc5f03 (patch)
treed92917ab060840c6473bc1050b323afdb604c952 /common/misc.c
parentfac4a8649e61236b57fc81150e6e3e5db9f8b5e2 (diff)
downloadbarebox-f3c05f20dcb09159141c8843d909a26997cc5f03.tar.gz
barebox-f3c05f20dcb09159141c8843d909a26997cc5f03.tar.xz
common: misc: support strerror(err) for all err <= MAX_ERRNO
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/misc.c')
-rw-r--r--common/misc.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/common/misc.c b/common/misc.c
index 1c7f937608..1a1cc071b4 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;