提交 2a0cbf3b 编写于 作者: H Heinrich Schuchardt 提交者: Tom Rini

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: NHeinrich Schuchardt <xypron.glpk@gmx.de>
Reviewed-by: NSimon Glass <sjg@chromium.org>
上级 92015767
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册