log: correct and check array size of log categories
PATCH 1/1 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.
--- common/log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
common/log.c +7 -2
@@ -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,8 @@ static const char *log_level_name[LOGL_COUNT] = { "IO", }; +_Static_assert (ARRAY_SIZE (log_level_name) ==LOGL_COUNT ,"log_level_name size" ); +const char *log_get_cat_name (enum log_category_t cat) {const char *name;
--
2.28.0
PATCH 1/1 log: correct and check array size of log categories
Quoted 4 lines · Heinrich Schuchardt
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.
Quoted 8 lines
Add compile time checks for the array sizes of
log_cat_nameandlog_lvl_nameto avoid future mishaps.Signed-off-by Heinrich Schuchardt <[email protected]>--- common/log.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
PATCH 1/1 log: correct and check array size of log categories
In reply to Heinrich SchuchardtQuoted 8 lines · Heinrich Schuchardt
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_nameandlog_lvl_nameto avoid future mishaps.Signed-off-by Heinrich Schuchardt <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20201028/cba38ada/attachment.sig>