[U-Boot] [PATCH 1/8] log: Fix incorect range check in log_get_cat_name()

Simon Glass sjg at chromium.org
Sat Jun 9 18:22:27 UTC 2018


This allows access to an element after the end of the array. Fix it.

Reported-by: Coverity (CID: 173279)
Signed-off-by: Simon Glass <sjg at chromium.org>
---

 common/log.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/common/log.c b/common/log.c
index 3b5588ebe7..4e488eca5b 100644
--- a/common/log.c
+++ b/common/log.c
@@ -38,7 +38,7 @@ static const char *log_level_name[LOGL_COUNT] = {
 
 const char *log_get_cat_name(enum log_category_t cat)
 {
-	if (cat > LOGC_COUNT)
+	if (cat >= LOGC_COUNT)
 		return "invalid";
 	if (cat >= LOGC_NONE)
 		return log_cat_name[cat - LOGC_NONE];
-- 
2.18.0.rc1.242.g61856ae69a-goog



More information about the U-Boot mailing list