Do not accept strings like 0.0.0.0.0 as IP masks.
authorMichael Poole <mdpoole@troilus.org>
Thu, 20 Mar 2008 23:58:27 +0000 (23:58 +0000)
committerMichael Poole <mdpoole@troilus.org>
Thu, 20 Mar 2008 23:58:27 +0000 (23:58 +0000)
(Reported by the Quakenet crew: paulr, splidge, and company.)

git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/branches/u2_10_12_branch@1872 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/ircd_string.c
ircd/test/ircd_in_addr_t.c

index 37007c7241d637ae305476798dd926143008e4b4..8f1e198db526824cc422e6c7e3262b7dfc052da5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2008-03-20  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/ircd_string.c (ircd_aton_ip4): Reject strings with more
+       than 3 dots in them.
+
+       * ircd/test/ircd_in_addr_t.c (test_addrs): Update the expected
+       parsing for a bare IPv4 address to a IPv4-mapped address.
+       (test_masks): Add a test for the ircd_string.c change.
+
 2008-03-20  Kevin L. Mitchell  <klmitch@mit.edu>
 
        * include/client.h: IsLocOp() now checks to see if its MyUser() as
 2008-03-20  Kevin L. Mitchell  <klmitch@mit.edu>
 
        * include/client.h: IsLocOp() now checks to see if its MyUser() as
index 1ed082d6f34d6073d5d5d59041b4d8d65c7ad99a..b5b32cfc01dacc068e56e674910c6043322d6c4e 100644 (file)
@@ -481,9 +481,11 @@ ircd_aton_ip4(const char *input, unsigned int *output, unsigned char *pbits)
       *pbits = bits;
     return pos;
   case '.':
       *pbits = bits;
     return pos;
   case '.':
+    if (++dots > 3)
+      return 0;
     if (input[++pos] == '.')
       return 0;
     if (input[++pos] == '.')
       return 0;
-    ip |= part << (24 - 8 * dots++);
+    ip |= part << (32 - 8 * dots);
     part = 0;
     if (input[pos] == '*') {
       while (input[++pos] == '*' || input[pos] == '.') ;
     part = 0;
     if (input[pos] == '*') {
       while (input[++pos] == '*' || input[pos] == '.') ;
index 1a65aec59eaa20a8f1dca570e8c513d6a1cc608f..7eaf56ee5e78f309cd595570118b9e32c4d7e518 100644 (file)
@@ -29,7 +29,7 @@ static struct address_test test_addrs[] = {
       {{ 0, 0, 0, 0, 0, 0, 0, 1 }},
       "AAAAAA", "_AAB", 1, 0, 1 },
     { "127.0.0.1", "127.0.0.1",
       {{ 0, 0, 0, 0, 0, 0, 0, 1 }},
       "AAAAAA", "_AAB", 1, 0, 1 },
     { "127.0.0.1", "127.0.0.1",
-      {{ 0, 0, 0, 0, 0, 0, 0x7f00, 1 }},
+      {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 1 }},
       "B]AAAB", "B]AAAB", 1, 1, 1 },
     { "::ffff:127.0.0.3", "127.0.0.3",
       {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 3 }},
       "B]AAAB", "B]AAAB", 1, 1, 1 },
     { "::ffff:127.0.0.3", "127.0.0.3",
       {{ 0, 0, 0, 0, 0, 0xffff, 0x7f00, 3 }},
@@ -123,6 +123,7 @@ static struct ipmask_test test_masks[] = {
     { "a:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
     { "a:*:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
     { "a:/16", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
     { "a:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
     { "a:*:*", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
     { "a:/16", {{ 0xa, 0, 0, 0, 0, 0, 0, 0 }}, 1, 1, 16 },
+    { "0.0.0.0.0/1", {{ 0, 0, 0, 0, 0, 0, 0, 0 }}, 0, 0, 0 },
     { 0 }
 };
 
     { 0 }
 };