options: fix logic flaw when parsing ipaddr/mask notation
authorJo-Philipp Wich <jow@openwrt.org>
Sat, 19 Jul 2014 12:42:47 +0000 (14:42 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Sat, 19 Jul 2014 12:42:51 +0000 (14:42 +0200)
Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
options.c

index 292f5fc322f7d93facb08f8c1a2458708c80bfa3..0a796a4fe2920d049779cb35b62c416d2e5de9e2 100644 (file)
--- a/options.c
+++ b/options.c
@@ -268,12 +268,15 @@ fw3_parse_address(void *ptr, const char *val, bool is_list)
                addr.family = FW3_FAMILY_V6;
                addr.address.v6 = v6;
 
-               if (m && !inet_pton(AF_INET6, m, &addr.mask.v6))
+               if (m)
                {
-                       bits = strtol(m, &e, 10);
+                       if (!inet_pton(AF_INET6, m, &v6))
+                       {
+                               bits = strtol(m, &e, 10);
 
-                       if ((*e != 0) || !fw3_bitlen2netmask(addr.family, bits, &v6))
-                               goto fail;
+                               if ((*e != 0) || !fw3_bitlen2netmask(addr.family, bits, &v6))
+                                       goto fail;
+                       }
 
                        addr.mask.v6 = v6;
                }
@@ -294,12 +297,15 @@ fw3_parse_address(void *ptr, const char *val, bool is_list)
                addr.family = FW3_FAMILY_V4;
                addr.address.v4 = v4;
 
-               if (m && !inet_pton(AF_INET, m, &addr.mask.v4))
+               if (m)
                {
-                       bits = strtol(m, &e, 10);
+                       if (!inet_pton(AF_INET, m, &v4))
+                       {
+                               bits = strtol(m, &e, 10);
 
-                       if ((*e != 0) || !fw3_bitlen2netmask(addr.family, bits, &v4))
-                               goto fail;
+                               if ((*e != 0) || !fw3_bitlen2netmask(addr.family, bits, &v4))
+                                       goto fail;
+                       }
 
                        addr.mask.v4 = v4;
                }