]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
dmesg: add boundary check to facility & level array usage
authorSami Kerola <kerolasa@iki.fi>
Sat, 19 Jan 2013 00:09:02 +0000 (00:09 +0000)
committerKarel Zak <kzak@redhat.com>
Fri, 25 Jan 2013 09:09:36 +0000 (10:09 +0100)
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 <kerolasa@iki.fi>
sys-utils/dmesg.c

index f95db408dc263e8d0e6a925081a512c3b52fefe9..ddab9b4acafd7c625a63ca6ddaa4c70c9cae012e 100644 (file)
@@ -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);