summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHeinrich Schuchardt <xypron.glpk@gmx.de>2019-10-15 22:46:03 +0300
committerTom Rini <trini@konsulko.com>2019-10-31 14:22:53 +0300
commit02e8a8241bb5fff315f3e721992220428f288b6d (patch)
treef853f2c6876329ed66b2f2e7c1cd763ec82d60cb /lib
parent80e7e7c2aba5793a1e39592cd53de9e5aca96f0b (diff)
downloadu-boot-02e8a8241bb5fff315f3e721992220428f288b6d.tar.xz
lib: errno: check for unsupported error number
If errno_str() is called with an unsupported error number, do not return a random pointer but a reasonable text. Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/errno_str.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/errno_str.c b/lib/errno_str.c
index 0ba950e970..bb8f9fbeb3 100644
--- a/lib/errno_str.c
+++ b/lib/errno_str.c
@@ -136,6 +136,8 @@ static const char * const errno_message[] = {
ERRNO_MSG(EDQUOT, "Quota exceeded"),
ERRNO_MSG(ENOMEDIUM, "No medium found"),
ERRNO_MSG(EMEDIUMTYPE, "Wrong medium type"),
+ /* Message for unsupported error numbers */
+ ERRNO_MSG(0, "Unknown error"),
};
const char *errno_str(int errno)
@@ -143,5 +145,9 @@ const char *errno_str(int errno)
if (errno >= 0)
return errno_message[0];
- return errno_message[abs(errno)];
+ errno = -errno;
+ if (errno >= ARRAY_SIZE(errno_message))
+ errno = ARRAY_SIZE(errno_message) - 1;
+
+ return errno_message[errno];
}