]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
common: event: check event_type_name() argument
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 28 Jan 2024 07:58:55 +0000 (08:58 +0100)
committerTom Rini <trini@konsulko.com>
Tue, 6 Feb 2024 21:31:06 +0000 (16:31 -0500)
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@canonical.com>
common/event.c

index dc61b9672f32763d2545efec0f22e87ec8a7178d..16c2ba6cc92112907cb97b97331bac2a8c8a9ac2 100644 (file)
@@ -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