]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute_lwtunnel: fix array boundary check
authorAndrea Claudi <aclaudi@redhat.com>
Mon, 29 May 2023 21:42:16 +0000 (23:42 +0200)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 30 May 2023 19:25:47 +0000 (12:25 -0700)
seg6_mode_types is made up of 5 elements, so ARRAY_SIZE(seg6_mode_types)
evaluates to 5. Thus, when mode = 5, this function returns
seg6_mode_types[5], resulting in an out-of-bound access.

Fix this bailing out when mode is equal to or greater than 5.

Fixes: cf87da417bb4 ("iproute: add support for seg6 l2encap mode")
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
ip/iproute_lwtunnel.c

index 96de3b207ef47c73d25bf1999f93bc75823fdd31..949859723dcb91ec7b910c93782242cd2c48a7e9 100644 (file)
@@ -140,7 +140,7 @@ static const char *seg6_mode_types[] = {
 
 static const char *format_seg6mode_type(int mode)
 {
-       if (mode < 0 || mode > ARRAY_SIZE(seg6_mode_types))
+       if (mode < 0 || mode >= ARRAY_SIZE(seg6_mode_types))
                return "<unknown>";
 
        return seg6_mode_types[mode];