]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_string: Avoid potential array out of bounds access
authorPhil Sutter <phil@nwl.cc>
Mon, 10 Sep 2018 21:35:16 +0000 (23:35 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 13 Sep 2018 08:48:11 +0000 (10:48 +0200)
The pattern index variable 'sindex' is bounds checked before
incrementing it, which means in the next loop iteration it might already
match the bounds check condition but is used anyway.

Fix this by incrementing the index before performing the bounds check.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
extensions/libxt_string.c

index fb15980e4a73fc490c904a97e4c5804f847f6088..d298c6a7081e7ade72233edaee7d762ecb101a54 100644 (file)
@@ -159,9 +159,8 @@ parse_hex_string(const char *s, struct xt_string_info *info)
                        info->pattern[sindex] = s[i];
                        i++;
                }
-               if (sindex > XT_STRING_MAX_PATTERN_SIZE)
+               if (++sindex > XT_STRING_MAX_PATTERN_SIZE)
                        xtables_error(PARAMETER_PROBLEM, "STRING too long \"%s\"", s);
-               sindex++;
        }
        info->patlen = sindex;
 }