From: Sami Kerola Date: Sat, 19 Jan 2013 00:09:02 +0000 (+0000) Subject: dmesg: add boundary check to facility & level array usage X-Git-Tag: v2.23-rc1~318 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae6288da84ff6e6c70d4a9719b8935995022f65e;p=thirdparty%2Futil-linux.git dmesg: add boundary check to facility & level array usage The dmesg should not crash while --decode'ing message facilities and levels to readable string even if the values are out of bounds. Signed-off-by: Sami Kerola --- diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c index f95db408dc..ddab9b4aca 100644 --- a/sys-utils/dmesg.c +++ b/sys-utils/dmesg.c @@ -803,7 +803,9 @@ static void print_record(struct dmesg_control *ctl, /* * facility : priority : */ - if (ctl->decode && rec->level >= 0 && rec->facility >= 0) + if (ctl->decode && + -1 < rec->level && rec->level < (int) ARRAY_SIZE(level_names) && + -1 < rec->facility && rec->facility < (int) ARRAY_SIZE(facility_names)) printf("%-6s:%-6s: ", facility_names[rec->facility].name, level_names[rec->level].name);