Fix base64toip() bugs (PR#1197043).
authorMichael Poole <mdpoole@troilus.org>
Sun, 8 May 2005 00:56:05 +0000 (00:56 +0000)
committerMichael Poole <mdpoole@troilus.org>
Sun, 8 May 2005 00:56:05 +0000 (00:56 +0000)
git-svn-id: file:///home/klmitch/undernet-ircu/undernet-ircu-svn/ircu2/trunk@1398 c9e4aea6-c8fd-4c43-8297-357d70d61c8c

ChangeLog
ircd/numnicks.c
ircd/test/ircd_in_addr_t.c

index 0b0384fcf9b782098882b0b5369623cee6e96a85..9e3fe6660d7dc4f49ba9c1b89e90b1bceb2f0c71 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2005-05-07  Michael Poole <mdpoole@troilus.org>
+
+       * ircd/numnicks.c (base64toip): Fix bugs in parsing IPv6
+       addresses.
+       * ircd/test/ircd_in_addr_t.c (test_addrs): Add new entry.
+       (test_address): Test base64toip() as well.
+
 2005-05-05  Michael Poole <mdpoole@troilus.org>
 
        * ircd/s_user.c (umode_str): Only clear the operator flag when not
index 9dd051dea3cacf8a00b871c314f9a2dba4c36d49..66e432135d23db284df65b3e1c1b0a03518bd2c8 100644 (file)
@@ -513,7 +513,7 @@ void base64toip(const char* input, struct irc_in_addr* addr)
     do {
       if (*input == '_') {
         unsigned int left;
-        for (left = (25 - strlen(input)) / 3; left; left--)
+        for (left = (25 - strlen(input)) / 3 - pos; left; left--)
           addr->in6_16[pos++] = 0;
         input++;
       } else {
@@ -521,7 +521,6 @@ void base64toip(const char* input, struct irc_in_addr* addr)
         accum = (accum << NUMNICKLOG) | convert2n[(unsigned char)*input++];
         accum = (accum << NUMNICKLOG) | convert2n[(unsigned char)*input++];
         addr->in6_16[pos++] = ntohs(accum);
-        input += 3;
       }
     } while (pos < 8);
   }
index 4694d67e995fcd5f22cf93d7a102dc670349cecd..2797057c10b85e9ac90f396ceaf1c08d68eace12 100644 (file)
@@ -43,6 +43,9 @@ static struct address_test test_addrs[] = {
     { "8352:0344:0:0:0:0:2001:1204", "8352:344::2001:1204",
       {{ 0x8352, 0x344, 0, 0, 0, 0, 0x2001, 0x1204 }},
       "AAAAAA", "INSANE_CABBIE", 1, 0, 0 },
+    { "1:2:3:4:5:6:7:8", "1:2:3:4:5:6:7:8",
+      {{ 1, 2, 3, 4, 5, 6, 7, 8 }},
+      "AAAAAA", "AABAACAADAAEAAFAAGAAHAAI", 1, 0, 0 },
     { 0 },
 };
 
@@ -80,6 +83,15 @@ test_address(struct address_test *addr)
     assert(!!val == addr->is_ipv4);
     val = irc_in_addr_is_loopback(&parsed);
     assert(!!val == addr->is_loopback);
+    /* Check base64-to-IP conversion. */
+    if (addr->is_ipv4) {
+        base64toip(addr->base64_v4, &parsed);
+        assert(!memcmp(parsed.in6_16+6, addr->expected.in6_16+6, 4));
+    } else {
+        base64toip(addr->base64_v6, &parsed);
+        assert(!memcmp(&parsed, &addr->expected, sizeof(parsed)));
+    }
+    /* Tests completed. */
     printf("Passed: %s (%s/%s)\n", addr->text, base64_v4, base64_v6);
 }