]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iplink_can: Prevent overstepping array bounds
authorPhil Sutter <phil@nwl.cc>
Mon, 21 Aug 2017 09:27:00 +0000 (11:27 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 22 Aug 2017 00:17:00 +0000 (17:17 -0700)
can_state_names array contains at most CAN_STATE_MAX fields, so allowing
an index to it to be equal to that number is wrong. While here, also
make sure the array is indeed that big so nothing bad happens if
CAN_STATE_MAX ever increases.

Signed-off-by: Phil Sutter <phil@nwl.cc>
ip/iplink_can.c

index 5df56b2bbbb3be7a0a637dc134e596134b8dc4c9..2954010fefa22cd04eb2d90f79e98356a2c55a0d 100644 (file)
@@ -251,7 +251,7 @@ static int can_parse_opt(struct link_util *lu, int argc, char **argv,
        return 0;
 }
 
-static const char *can_state_names[] = {
+static const char *can_state_names[CAN_STATE_MAX] = {
        [CAN_STATE_ERROR_ACTIVE] = "ERROR-ACTIVE",
        [CAN_STATE_ERROR_WARNING] = "ERROR-WARNING",
        [CAN_STATE_ERROR_PASSIVE] = "ERROR-PASSIVE",
@@ -275,7 +275,7 @@ static void can_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
        if (tb[IFLA_CAN_STATE]) {
                uint32_t state = rta_getattr_u32(tb[IFLA_CAN_STATE]);
 
-               fprintf(f, "state %s ", state <= CAN_STATE_MAX ?
+               fprintf(f, "state %s ", state < CAN_STATE_MAX ?
                        can_state_names[state] : "UNKNOWN");
        }