]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxt_policy: use bounded strtoui
authorJan Engelhardt <jengelh@medozas.de>
Sat, 21 Feb 2009 03:00:21 +0000 (04:00 +0100)
committerJan Engelhardt <jengelh@medozas.de>
Sat, 21 Feb 2009 03:01:48 +0000 (04:01 +0100)
reqid and SPI can only have a value in the range 0..UINT32_MAX, not
the entire range of the "long" type. Also throw an error if the
incoming string does not look like a pure number.

"Replaces" commit 6db2ded2f22a7e78743c86af523b8430876582e9.

Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
extensions/libip6t_policy.c
extensions/libipt_policy.c

index 0016da29cfc23f2f554fd5db5bd6b8042e57a267..5106c28e84fc15384fad11481949ab6938e092a9 100644 (file)
@@ -156,7 +156,7 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
        struct ip6t_policy_info *info = (void *)(*match)->data;
        struct ip6t_policy_elem *e = &info->pol[info->len];
        struct in6_addr *addr = NULL, mask;
-       unsigned int naddr = 0;
+       unsigned int naddr = 0, num;
        int mode;
 
        xtables_check_inverse(optarg, &invert, &optind, 0);
@@ -197,7 +197,9 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
 
                e->match.reqid = 1;
                e->invert.reqid = invert;
-               e->reqid = strtoul(argv[optind-1], NULL, 10);
+               if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
+                       xtables_param_act(XTF_BAD_VALUE, "policy", "--reqid", optarg);
+               e->reqid = num;
                break;
        case '5':
                if (e->match.spi)
@@ -206,7 +208,9 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
 
                e->match.spi = 1;
                e->invert.spi = invert;
-               e->spi = strtoul(argv[optind-1], NULL, 0x10);
+               if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
+                       xtables_param_act(XTF_BAD_VALUE, "policy", "--spi", optarg);
+               e->spi = num;
                break;
        case '6':
                if (e->match.saddr)
index 1271fbadde5e9f44c2fcc19e35767826fad98451..ae7282a3948dbd7996c8e4ced677b87b93cb7ee7 100644 (file)
@@ -124,7 +124,7 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
        struct ipt_policy_info *info = (void *)(*match)->data;
        struct ipt_policy_elem *e = &info->pol[info->len];
        struct in_addr *addr = NULL, mask;
-       unsigned int naddr = 0;
+       unsigned int naddr = 0, num;
        int mode;
 
        xtables_check_inverse(optarg, &invert, &optind, 0);
@@ -165,7 +165,9 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
 
                e->match.reqid = 1;
                e->invert.reqid = invert;
-               e->reqid = strtoul(argv[optind-1], NULL, 10);
+               if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
+                       xtables_param_act(XTF_BAD_VALUE, "policy", "--spi", optarg);
+               e->reqid = num;
                break;
        case '5':
                if (e->match.spi)
@@ -174,7 +176,9 @@ static int policy_parse(int c, char **argv, int invert, unsigned int *flags,
 
                e->match.spi = 1;
                e->invert.spi = invert;
-               e->spi = strtoul(argv[optind-1], NULL, 0x10);
+               if (!xtables_strtoui(optarg, NULL, &num, 0, UINT32_MAX))
+                       xtables_param_act(XTF_BAD_VALUE, "policy", "--spi", optarg);
+               e->spi = num;
                break;
        case '6':
                if (e->match.saddr)