From 02e8a8241bb5fff315f3e721992220428f288b6d Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Tue, 15 Oct 2019 21:46:03 +0200 Subject: 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 Reviewed-by: Simon Glass --- lib/errno_str.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/errno_str.c') diff --git a/lib/errno_str.c b/lib/errno_str.c index 0ba950e9703..bb8f9fbeb39 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]; } -- cgit v1.2.3 From eb5b63f3699fd8068f79cf8ffe5524f98ec00ba6 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 6 Oct 2019 13:22:21 +0200 Subject: lib: errno: sync error codes Macro ERRNO_MSG() ignores the error number but we should still use the same constants as in include/linux/errno.h. Signed-off-by: Heinrich Schuchardt --- lib/errno_str.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/errno_str.c') diff --git a/lib/errno_str.c b/lib/errno_str.c index bb8f9fbeb39..2e5f4a887d5 100644 --- a/lib/errno_str.c +++ b/lib/errno_str.c @@ -13,7 +13,7 @@ static const char * const errno_message[] = { ERRNO_MSG(0, "Success"), ERRNO_MSG(EPERM, "Operation not permitted"), - ERRNO_MSG(ENOEN, "No such file or directory"), + ERRNO_MSG(ENOENT, "No such file or directory"), ERRNO_MSG(ESRCH, "No such process"), ERRNO_MSG(EINTR, "Interrupted system call"), ERRNO_MSG(EIO, "I/O error"), @@ -26,7 +26,7 @@ static const char * const errno_message[] = { ERRNO_MSG(ENOMEM, "Out of memory"), ERRNO_MSG(EACCES, "Permission denied"), ERRNO_MSG(EFAULT, "Bad address"), - ERRNO_MSG(ENOTBL, "Block device required"), + ERRNO_MSG(ENOTBLK, "Block device required"), ERRNO_MSG(EBUSY, "Device or resource busy"), ERRNO_MSG(EEXIST, "File exists"), ERRNO_MSG(EXDEV, "Cross-device link"), -- cgit v1.2.3