From: Andrea Claudi Date: Mon, 29 May 2023 21:42:16 +0000 (+0200) Subject: iproute_lwtunnel: fix array boundary check X-Git-Tag: v6.4.0~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1cf50a1f2723764eb53fad7c5ff8754835806df0;p=thirdparty%2Fiproute2.git iproute_lwtunnel: fix array boundary check 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 Signed-off-by: Stephen Hemminger --- diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c index 96de3b207..949859723 100644 --- a/ip/iproute_lwtunnel.c +++ b/ip/iproute_lwtunnel.c @@ -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 ""; return seg6_mode_types[mode];