[PATCH 1/1] common: event: check event_type_name() argument

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Sun Jan 28 08:58:55 CET 2024


In event_type_name() we should avoid possible buffer overruns by checking
the type argument.

Addresses-Coverity-ID: 478862 Out-of-bounds access
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 common/event.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/event.c b/common/event.c
index dc61b9672f3..16c2ba6cc92 100644
--- a/common/event.c
+++ b/common/event.c
@@ -56,7 +56,10 @@ _Static_assert(ARRAY_SIZE(type_name) == EVT_COUNT, "event type_name size");
 const char *event_type_name(enum event_t type)
 {
 #if CONFIG_IS_ENABLED(EVENT_DEBUG)
-	return type_name[type];
+	if (type < ARRAY_SIZE(type_name))
+		return type_name[type];
+	else
+		return "(unknown)";
 #else
 	return "(unknown)";
 #endif
-- 
2.43.0



More information about the U-Boot mailing list