]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
further fixes of string_to_number fixes
authorHarald Welte <laforge@gnumonks.org>
Mon, 23 Jul 2001 02:14:22 +0000 (02:14 +0000)
committerHarald Welte <laforge@gnumonks.org>
Mon, 23 Jul 2001 02:14:22 +0000 (02:14 +0000)
23 files changed:
extensions/libip6t_LOG.c
extensions/libip6t_icmpv6.c
extensions/libip6t_limit.c
extensions/libip6t_multiport.c
extensions/libip6t_tcp.c
extensions/libip6t_udp.c
extensions/libipt_FTOS.c
extensions/libipt_LOG.c
extensions/libipt_NETMAP.c
extensions/libipt_TCPMSS.c
extensions/libipt_TOS.c
extensions/libipt_icmp.c
extensions/libipt_length.c
extensions/libipt_limit.c
extensions/libipt_mport.c
extensions/libipt_multiport.c
extensions/libipt_nth.c
extensions/libipt_psd.c
extensions/libipt_tcp.c
extensions/libipt_tcpmss.c
extensions/libipt_time.c
extensions/libipt_tos.c
extensions/libipt_udp.c

index c147d1ca9041fa19d1289d6aa733d45b3bf6b255..6800315095138f4e7f687d074ee58f5a04fc9751 100644 (file)
@@ -66,10 +66,9 @@ static struct ip6t_log_names ip6t_log_names[]
 static u_int8_t
 parse_level(const char *level)
 {
-       int lev;
+       unsigned int lev;
 
-       lev = string_to_number(level, 0, 7);
-       if (lev == -1) {
+       if (string_to_number(level, 0, 7, lev) == -1) {
                unsigned int i = 0;
 
                for (i = 0;
index 41ae5ca3edadcdff6c0fd175a7454c537857d1fd..1b801d2d2d3bd008b19e20db483e8b7bf1a458d6 100644 (file)
@@ -118,7 +118,7 @@ parse_icmpv6(const char *icmpv6type, u_int8_t *type, u_int8_t code[])
        } else {
                char *slash;
                char buffer[strlen(icmpv6type) + 1];
-               int number;
+               unsigned int number;
 
                strcpy(buffer, icmpv6type);
                slash = strchr(buffer, '/');
@@ -126,14 +126,12 @@ parse_icmpv6(const char *icmpv6type, u_int8_t *type, u_int8_t code[])
                if (slash)
                        *slash = '\0';
 
-               number = string_to_number(buffer, 0, 255);
-               if (number == -1)
+               if (string_to_number(buffer, 0, 255, &number) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Invalid ICMPv6 type `%s'\n", buffer);
                *type = number;
                if (slash) {
-                       number = string_to_number(slash+1, 0, 255);
-                       if (number == -1)
+                       if (string_to_number(slash+1, 0, 255, &number) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "Invalid ICMPv6 code `%s'\n",
                                           slash+1);
index 3b0318bac28c3b82b3a6c188d0b157d090ccdec9..e794675c72783b7115524199c7ccd25593911acb 100644 (file)
@@ -98,7 +98,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
       struct ip6t_entry_match **match)
 {
        struct ip6t_rateinfo *r = (struct ip6t_rateinfo *)(*match)->data;
-       int num;
+       unsigned int num;
 
        switch(c) {
        case '%':
@@ -115,8 +115,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                        exit_error(PARAMETER_PROBLEM,
                                   "Unexpected `!' after --limit-burst");
 
-               num = string_to_number(optarg, 0, 10000);
-               if (num <= 0)
+               if (string_to_number(optarg, 0, 10000, &num) <= 0)
                        exit_error(PARAMETER_PROBLEM,
                                   "bad --limit-burst `%s'", optarg);
                r->burst = num;
index 0fcefde1bf044583e7abebc7e49fb7647f9316da..d58bbb974badefe6d45411ecdf50f3cde02ba776 100644 (file)
@@ -47,8 +47,9 @@ service_to_port(const char *name, const char *proto)
 static u_int16_t
 parse_port(const char *port, const char *proto)
 {
-       int portnum;
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       unsigned int portnum;
+
+       if ((string_to_number(port, 0, 65535, &portnum)) != -1 ||
            (portnum = service_to_port(port, proto)) != -1)
                return (u_int16_t)portnum;
 
index 718ec8ce02716062e4cfaeea8bc3e3f1ca1440c7..dd515f0eab69cc3132b1af31d9979a5e0d17bdc6 100644 (file)
@@ -52,9 +52,9 @@ service_to_port(const char *name)
 static u_int16_t
 parse_tcp_port(const char *port)
 {
-       int portnum;
+       unsigned int portnum;
 
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       if (string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port)) != -1)
                return (u_int16_t)portnum;
 
@@ -141,10 +141,9 @@ parse_tcp_flags(struct ip6t_tcp *tcpinfo,
 static void
 parse_tcp_option(const char *option, u_int8_t *result)
 {
-       int ret;
+       unsigned int ret;
 
-       ret = string_to_number(option, 1, 255);
-       if (ret == -1)
+       if (string_to_number(option, 1, 266, &ret) == -1)
                exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
 
        *result = (u_int8_t)ret;
index 7fe16dd732fbdf1bc6efe279b34fc6eb370fcbfc..ac0361674dfd8eb4fa1b09e4c3b953f1d6ab07c0 100644 (file)
@@ -44,9 +44,9 @@ service_to_port(const char *name)
 static u_int16_t
 parse_udp_port(const char *port)
 {
-       int portnum;
+       unsigned int portnum;
 
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       if (string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port)) != -1)
                return (u_int16_t)portnum;
 
index 93120385f59d6dc7d9f805d6a3101cd4c099a979..48f88ec50e55141b4ee21f67fa863696df2fa830 100644 (file)
@@ -43,7 +43,9 @@ static struct option opts[] = {
 static void
 parse_ftos(const unsigned char *s, struct ipt_FTOS_info *finfo)
 {
-       int ftos = string_to_number(s, 0, 255);
+       unsigned int ftos;
+       
+       string_to_number(s, 0, 255, &ftos);
        finfo->ftos = (u_int8_t )ftos;
        return;
 }
index 024c68d2d065cd1271fd7331fbe5d10210ed7d99..9f41853f0b9c5bbe4dd97f50bd5e392f4f230ed8 100644 (file)
@@ -66,10 +66,9 @@ static struct ipt_log_names ipt_log_names[]
 static u_int8_t
 parse_level(const char *level)
 {
-       int lev;
+       unsigned int lev;
 
-       lev = string_to_number(level, 0, 7);
-       if (lev == -1) {
+       if (string_to_number(level, 0, 7, &lev) == -1) {
                unsigned int i = 0;
 
                for (i = 0;
index 4cd7abc1097a520471b4dbda5fd7e7cb6e255304..7d5ad04fb25cb27a10162c0c3ef1dd5c97b84a80 100644 (file)
@@ -74,7 +74,7 @@ parse_to(char *arg, struct ip_nat_range *range)
        char *slash;
        struct in_addr *ip;
        u_int32_t netmask;
-       int bits;
+       unsigned int bits;
 
        range->flags |= IP_NAT_RANGE_MAP_IPS;
        slash = strchr(arg, '/');
@@ -95,7 +95,7 @@ parse_to(char *arg, struct ip_nat_range *range)
                        netmask = ip->s_addr;
                }
                else {
-                       if ((bits = string_to_number(slash+1, 0, 32)) == -1)
+                       if (string_to_number(slash+1, 0, 32, &bits) == -1)
                                exit_error(PARAMETER_PROBLEM, "Bad netmask `%s'\n",
                                           slash+1);
                        netmask = bits2netmask(bits);
index 03ce1bdbc482e3450c0df0f7607bd5e030a4bd53..d14f0c08533fbfc8fdf060fcdd491cf2f2f31fb8 100644 (file)
@@ -50,13 +50,13 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                = (struct ipt_tcpmss_info *)(*target)->data;
 
        switch (c) {
-               int mssval;
+               unsigned int mssval;
 
        case '1':
                if (*flags)
                        exit_error(PARAMETER_PROBLEM,
                                   "TCPMSS target: Only one option may be specified");
-               if ((mssval = string_to_number(optarg, 0, 65535 - 40)) == -1)
+               if (string_to_number(optarg, 0, 65535 - 40, &mssval) == -1)
                        exit_error(PARAMETER_PROBLEM, "Bad TCPMSS value `%s'", optarg);
                
                mssinfo->mss = mssval;
index 0c91cb5450f472a67c05c9ccba5244335928f54a..9feba06063c6f54fc9de2d3947e3949b13e366bb 100644 (file)
@@ -60,10 +60,9 @@ init(struct ipt_entry_target *t, unsigned int *nfcache)
 static void
 parse_tos(const unsigned char *s, struct ipt_tos_target_info *info)
 {
-       unsigned int i;
-       int tos = string_to_number(s, 0, 255);
+       unsigned int i, tos;
 
-       if (tos != -1) {
+       if (string_to_number(s, 0, 255,tos) != -1) {
                if (tos == IPTOS_LOWDELAY
                    || tos == IPTOS_THROUGHPUT
                    || tos == IPTOS_RELIABILITY
index 63905181d211c966e2839e3cb6d7dac5f5aead9a..a8b6bd13f87fb3184df601df485ae06152b9ee2c 100644 (file)
@@ -133,7 +133,7 @@ parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[])
        } else {
                char *slash;
                char buffer[strlen(icmptype) + 1];
-               int number;
+               unsigned int number;
 
                strcpy(buffer, icmptype);
                slash = strchr(buffer, '/');
@@ -141,14 +141,12 @@ parse_icmp(const char *icmptype, u_int8_t *type, u_int8_t code[])
                if (slash)
                        *slash = '\0';
 
-               number = string_to_number(buffer, 0, 255);
-               if (number == -1)
+               if (string_to_number(buffer, 0, 255, &number) == -1)
                        exit_error(PARAMETER_PROBLEM,
                                   "Invalid ICMP type `%s'\n", buffer);
                *type = number;
                if (slash) {
-                       number = string_to_number(slash+1, 0, 255);
-                       if (number == -1)
+                       if (string_to_number(slash+1, 0, 255, &number) == -1)
                                exit_error(PARAMETER_PROBLEM,
                                           "Invalid ICMP code `%s'\n",
                                           slash+1);
index 7ea5084d121147ddf434f6127fcd3b8e191282c6..ee2af94356634dd56cc12aecfa8e372512579fd0 100644 (file)
@@ -35,11 +35,9 @@ init(struct ipt_entry_match *m, unsigned int *nfcache)
 static u_int16_t
 parse_length(const char *s)
 {
-       int len;
+       unsigned int len;
        
-       len = string_to_number(s, 0, 0xFFFF);
-       
-       if (len == -1)
+       if (string_to_number(s, 0, 0xFFFF, &len) == -1)
                exit_error(PARAMETER_PROBLEM, "length invalid: `%s'\n", s);
        else
                return (u_int16_t )len;
index 58c2ebd0e608d38f56a915a5a02728d4a8aaaa19..23924a7f3242d4a32bf92d6f8c9ba39d0f210507 100644 (file)
@@ -98,7 +98,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
       struct ipt_entry_match **match)
 {
        struct ipt_rateinfo *r = (struct ipt_rateinfo *)(*match)->data;
-       int num;
+       unsigned int num;
 
        switch(c) {
        case '%':
@@ -115,8 +115,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                        exit_error(PARAMETER_PROBLEM,
                                   "Unexpected `!' after --limit-burst");
 
-               num = string_to_number(optarg, 0, 10000);
-               if (num <= 0)
+               if (string_to_number(optarg, 0, 10000, &num) <= 0)
                        exit_error(PARAMETER_PROBLEM,
                                   "bad --limit-burst `%s'", optarg);
                r->burst = num;
index 38474cde1fb12bb7f045b83a2b8e0e1b7b2488d7..f2dfd1e1a72a26f31c46b03aa8db38f915ba8551 100644 (file)
@@ -47,8 +47,9 @@ service_to_port(const char *name, const char *proto)
 static u_int16_t
 parse_port(const char *port, const char *proto)
 {
-       int portnum;
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       unsigned int portnum;
+
+       if (portnum = string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port, proto)) != -1)
                return (u_int16_t)portnum;
 
index bac4621fdbe674bbd7dcb636dcfd472caa1e8b72..6eb5bdf0e429efb9dcfaf21eb6d6f1e584b1452e 100644 (file)
@@ -47,8 +47,9 @@ service_to_port(const char *name, const char *proto)
 static u_int16_t
 parse_port(const char *port, const char *proto)
 {
-       int portnum;
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       unsigned int portnum;
+
+       if (string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port, proto)) != -1)
                return (u_int16_t)portnum;
 
index 5fdd36257c4683aefb05056bdfa307de44c3c9d0..efeb71bf9f7fa91c89bde0f8609cd880626f3ee7 100644 (file)
@@ -59,7 +59,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
       struct ipt_entry_match **match)
 {
        struct ipt_nth_info *nthinfo = (struct ipt_nth_info *)(*match)->data;
-       int num;
+       unsigned int num;
 
        switch (c) {
        case '1':
@@ -79,8 +79,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
 
                /* Remember, this function will interpret a leading 0 to be 
                   Octal, a leading 0x to be hexdecimal... */
-                num = string_to_number(optarg, 2, 100);
-                if (num < 2)
+                if (string_to_number(optarg, 2, 100, &num) == -1 || num < 2)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --every `%s', must be between 2 and 100", optarg);
 
@@ -110,8 +109,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                if (*flags & IPT_NTH_OPT_START)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --start twice");
-               num = string_to_number(optarg, 0, nthinfo->every);
-                if (num < 0)
+               if (string_to_number(optarg, 0, nthinfo->every, &num) == -1)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --start `%s', must between 0 and %u", optarg, nthinfo->every);
                *flags |= IPT_NTH_OPT_START;
index f6885025257f3c8c0d9f73c56f2d522b94cd1c11..d5bb87e8f07eee9959821663abea8ab0f5e19cca 100644 (file)
@@ -81,7 +81,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
       struct ipt_entry_match **match)
 {
        struct ipt_psd_info *psdinfo = (struct ipt_psd_info *)(*match)->data;
-       int num;
+       unsigned int num;
 
        switch (c) {
        /* PSD-weight-threshold */
@@ -90,8 +90,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --psd-weight-threshold "
                                   "twice");
-                num = string_to_number(optarg, 0, 10000);
-                if (num <= 0)
+                if (string_to_number(optarg, 0, 10000, &num) == -1)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --psd-weight-threshold `%s'", optarg);
                psdinfo->weight_threshold = num;
@@ -103,8 +102,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                if (*flags & IPT_PSD_OPT_DTRESH)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --psd-delay-threshold twice");
-                num = string_to_number(optarg, 0, 10000);
-                if (num <= 0)
+                if (string_to_number(optarg, 0, 10000, &num) == -1)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --psd-delay-threshold `%s'", optarg);
                psdinfo->delay_threshold = num;
@@ -116,8 +114,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                if (*flags & IPT_PSD_OPT_LPWEIGHT)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --psd-lo-ports-weight twice");
-                num = string_to_number(optarg, 0, 10000);
-                if (num <= 0)
+                if (string_to_number(optarg, 0, 10000, &num) == -1)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --psd-lo-ports-weight `%s'", optarg);
                psdinfo->lo_ports_weight = num;
@@ -129,8 +126,7 @@ parse(int c, char **argv, int invert, unsigned int *flags,
                if (*flags & IPT_PSD_OPT_HPWEIGHT)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --psd-hi-ports-weight twice");
-                num = string_to_number(optarg, 0, 10000);
-                if (num <= 0)
+                if (string_to_number(optarg, 0, 10000, &num) == -1)
                         exit_error(PARAMETER_PROBLEM,
                                    "bad --psd-hi-ports-weight `%s'", optarg);
                psdinfo->hi_ports_weight = num;
index fb99bec76b2e4694dd2e03e4790020515b11e3c1..1b0a37a3ea7870db1c159791cdf9e02586ecc8b1 100644 (file)
@@ -52,9 +52,9 @@ service_to_port(const char *name)
 static u_int16_t
 parse_tcp_port(const char *port)
 {
-       int portnum;
+       unsigned int portnum;
 
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       if (string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port)) != -1)
                return (u_int16_t)portnum;
 
@@ -141,10 +141,9 @@ parse_tcp_flags(struct ipt_tcp *tcpinfo,
 static void
 parse_tcp_option(const char *option, u_int8_t *result)
 {
-       int ret;
+       unsigned int ret;
 
-       ret = string_to_number(option, 1, 255);
-       if (ret == -1)
+       if (string_to_number(option, 1, 255, &ret) == -1)
                exit_error(PARAMETER_PROBLEM, "Bad TCP option `%s'", option);
 
        *result = (u_int8_t)ret;
index 79e8d76c1f54811fd890e03ab0a2ba4fcc81d29a..6cf4211f4879141066d58c7ccdd4cd395c180675 100644 (file)
@@ -34,9 +34,9 @@ init(struct ipt_entry_match *m, unsigned int *nfcache)
 static u_int16_t
 parse_tcp_mssvalue(const char *mssvalue)
 {
-       int mssvaluenum;
+       unsigned int mssvaluenum;
 
-       if ((mssvaluenum = string_to_number(mssvalue, 0, 65535)) != -1)
+       if (string_to_number(mssvalue, 0, 65535, &mssvaluenum) != -1)
                return (u_int16_t)mssvaluenum;
 
        exit_error(PARAMETER_PROBLEM,
index 1d7690caea740d44b12844629eb9222df9477f08..10b37885ff487acb59e80d5000a581895e476436 100644 (file)
@@ -76,7 +76,7 @@ split_time(char **part1, char **part2, const char *str_2_parse)
 }
 
 static void
-parse_time_string(int *hour, int *minute, const char *time)
+parse_time_string(unsigned int *hour, unsigned int *minute, const char *time)
 {
        char *hours;
        char *minutes;
@@ -94,8 +94,10 @@ parse_time_string(int *hour, int *minute, const char *time)
                        hours[0] = ' ';
                if (minutes[0] == '0')
                        minutes[0] = ' ';
-               *hour   = string_to_number(hours, 0, 23);
-               *minute = string_to_number(minutes, 0, 59);
+
+               /* FIXME: error checking */
+               string_to_number(hours, 0, 23, hour);
+               string_to_number(minutes, 0, 59, minute);
        }
        if ((*hour != (-1)) && (*minute != (-1))) {
                free(hours);
index ec83e18d0338804510a12fd28b1fe4259ec99e91..f1d3b2a65740ed3ea7c359ab055f16aa72ce7a3a 100644 (file)
@@ -57,9 +57,9 @@ static void
 parse_tos(const unsigned char *s, struct ipt_tos_info *info)
 {
        unsigned int i;
-       int tos = string_to_number(s, 0, 255);
+       unsigned int tos;
 
-       if (tos != -1) {
+       if (string_to_number(s, 0, 255, &tos) != -1) {
                if (tos == IPTOS_LOWDELAY
                    || tos == IPTOS_THROUGHPUT
                    || tos == IPTOS_RELIABILITY
index 06c61c515d19e40688d54bd11bb12c3c1645cd79..9b18d18beeefe988cb2645fad6c74928ad6a5521 100644 (file)
@@ -44,9 +44,9 @@ service_to_port(const char *name)
 static u_int16_t
 parse_udp_port(const char *port)
 {
-       int portnum;
+       unsigned int portnum;
 
-       if ((portnum = string_to_number(port, 0, 65535)) != -1 ||
+       if (string_to_number(port, 0, 65535, &portnum) != -1 ||
            (portnum = service_to_port(port)) != -1)
                return (u_int16_t)portnum;