aboutsummaryrefslogtreecommitdiff
path: root/common/log.c
diff options
context:
space:
mode:
authorSimon Glass2018-06-12 00:04:55 -0600
committerTom Rini2018-06-18 14:43:14 -0400
commitc2e4e7e6316a1683be56618a5918732477742fbc (patch)
treea448e550dc9b28dd0a8aac68ab274f345d955a58 /common/log.c
parentb4c3fb087b06ec56cc325e2e73f8f497be89d129 (diff)
log: Fix incorect range check in log_get_cat_name()
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@chromium.org>
Diffstat (limited to 'common/log.c')
-rw-r--r--common/log.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/common/log.c b/common/log.c
index 3b5588ebe7a..59869cd29da 100644
--- a/common/log.c
+++ b/common/log.c
@@ -38,12 +38,16 @@ static const char *log_level_name[LOGL_COUNT] = {
const char *log_get_cat_name(enum log_category_t cat)
{
- if (cat > LOGC_COUNT)
- return "invalid";
+ const char *name;
+
+ if (cat < 0 || cat >= LOGC_COUNT)
+ return "<invalid>";
if (cat >= LOGC_NONE)
return log_cat_name[cat - LOGC_NONE];
- return uclass_get_name((enum uclass_id)cat);
+ name = uclass_get_name((enum uclass_id)cat);
+
+ return name ? name : "<missing>";
}
enum log_category_t log_get_cat_by_name(const char *name)