]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
string: fix wrong pattern length calculation
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 2 Mar 2009 10:46:55 +0000 (11:46 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 2 Mar 2009 10:46:55 +0000 (11:46 +0100)
This fixes a problem introduced in 37b4bde745698bf140d74e59a2561f34deeb8726
that leads to the wrong calculation of the pattern length in the
string match.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
extensions/libxt_string.c

index 5ea529e4bc5beb3a63c9e8b0f02abb904f0ff7d0..ba4b720a81899a8cab62446f8ae458227e7bd027 100644 (file)
@@ -64,9 +64,10 @@ static void string_init(struct xt_entry_match *m)
 static void
 parse_string(const char *s, struct xt_string_info *info)
 {      
+       /* xt_string does not need \0 at the end of the pattern */
        if (strlen(s) <= XT_STRING_MAX_PATTERN_SIZE) {
                strncpy(info->pattern, s, XT_STRING_MAX_PATTERN_SIZE);
-               info->patlen = strlen(s);
+               info->patlen = strnlen(s, XT_STRING_MAX_PATTERN_SIZE);
                return;
        }
        xtables_error(PARAMETER_PROBLEM, "STRING too long \"%s\"", s);
@@ -75,7 +76,8 @@ parse_string(const char *s, struct xt_string_info *info)
 static void
 parse_algo(const char *s, struct xt_string_info *info)
 {
-       if (strlen(s) <= XT_STRING_MAX_ALGO_NAME_SIZE) {
+       /* xt_string needs \0 for algo name */
+       if (strlen(s) < XT_STRING_MAX_ALGO_NAME_SIZE) {
                strncpy(info->algo, s, XT_STRING_MAX_ALGO_NAME_SIZE);
                return;
        }
@@ -208,8 +210,6 @@ string_parse(int c, char **argv, int invert, unsigned int *flags,
                        else
                                stringinfo->u.v1.flags |= XT_STRING_FLAG_INVERT;
                }
-               stringinfo->patlen = strnlen((char *)&stringinfo->pattern,
-                       sizeof(stringinfo->patlen));
                *flags |= STRING;
                break;