diff options
author | Heinrich Schuchardt <xypron.glpk@gmx.de> | 2020-10-23 13:00:01 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-10-27 17:04:15 -0400 |
commit | 2a0cbf3bca372dcbc79048d475c817d4e462069e (patch) | |
tree | 4f12560f10151c4fe5b7bb2a58e2b04bee035f45 /common/log.c | |
parent | 920157678b863bc34b655212a4bc0d29f84b4a80 (diff) | |
download | u-boot-2a0cbf3bca372dcbc79048d475c817d4e462069e.zip u-boot-2a0cbf3bca372dcbc79048d475c817d4e462069e.tar.gz u-boot-2a0cbf3bca372dcbc79048d475c817d4e462069e.tar.bz2 |
log: correct and check array size of log categories
The log command has led to NULL dereferences if an unknown category name
name was used due to missing entries in the list of category names.
Add compile time checks for the array sizes of log_cat_name and
log_lvl_name to avoid future mishaps.
Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/log.c')
-rw-r--r-- | common/log.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/common/log.c b/common/log.c index d830883..9f98e9a 100644 --- a/common/log.c +++ b/common/log.c @@ -13,7 +13,7 @@ DECLARE_GLOBAL_DATA_PTR; -static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { +static const char *log_cat_name[] = { "none", "arch", "board", @@ -28,7 +28,10 @@ static const char *log_cat_name[LOGC_COUNT - LOGC_NONE] = { "acpi", }; -static const char *log_level_name[LOGL_COUNT] = { +_Static_assert(ARRAY_SIZE(log_cat_name) == LOGC_COUNT - LOGC_NONE, + "log_cat_name size"); + +static const char *log_level_name[] = { "EMERG", "ALERT", "CRIT", @@ -41,6 +44,9 @@ static const char *log_level_name[LOGL_COUNT] = { "IO", }; +_Static_assert(ARRAY_SIZE(log_level_name) == LOGL_COUNT, "log_level_name size"); + +/* All error responses MUST begin with '<' */ const char *log_get_cat_name(enum log_category_t cat) { const char *name; |