]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
test/addr: Add unit tests for the fixes in 30721
authorteor <teor@torproject.org>
Thu, 13 Jun 2019 11:22:27 +0000 (21:22 +1000)
committerNick Mathewson <nickm@torproject.org>
Wed, 26 Jun 2019 13:55:37 +0000 (09:55 -0400)
src/test/test_addr.c

index 05d8bf6c7b8099c986c0c2cf66fc87407b8edd7c..a961a4685475c47546ebe0647b46340ed7822ff4 100644 (file)
@@ -788,6 +788,10 @@ test_addr_parse(void *arg)
   r= tor_addr_parse(&addr, "11:22:33:44:55:66:77:88:1.2.3.4");
   tt_int_op(r,OP_EQ, -1);
 
+  /* IPv6 address with port and no brackets */
+  r= tor_addr_parse(&addr, "11:22::33:44:12345");
+  tt_int_op(r, OP_EQ, -1);
+
   /* Correct call. */
   r= tor_addr_port_parse(LOG_DEBUG,
                          "192.0.2.1:1234",
@@ -834,6 +838,18 @@ test_addr_parse(void *arg)
   tt_int_op(r, OP_EQ, 0);
   tt_int_op(port,OP_EQ,400);
 
+  /* Allow IPv6 without square brackets, when there is no port */
+  r= tor_addr_port_parse(LOG_DEBUG,
+                         "::1",
+                         &addr, &port, -1);
+  tt_int_op(r, OP_EQ, -1);
+
+  r= tor_addr_port_parse(LOG_DEBUG,
+                         "::1",
+                         &addr, &port, 600);
+  tt_int_op(r, OP_EQ, 0);
+  tt_int_op(port,OP_EQ,600);
+
   /* Bad port. */
   r= tor_addr_port_parse(LOG_DEBUG,
                          "192.0.2.2:66666",
@@ -854,12 +870,29 @@ test_addr_parse(void *arg)
                          &addr, &port, 200);
   tt_int_op(r, OP_EQ, -1);
 
-  /* Bad IP address */
+  /* Bad IPv4 address */
   r= tor_addr_port_parse(LOG_DEBUG,
                          "192.0.2:1234",
                          &addr, &port, -1);
   tt_int_op(r, OP_EQ, -1);
 
+  /* Bad IPv4 address and port: brackets */
+  r= tor_addr_port_parse(LOG_DEBUG,
+                         "[192.0.2.3]:12345",
+                         &addr, &port, -1);
+  tt_int_op(r, OP_EQ, -1);
+
+  /* Bad IPv6 addresses and ports: no brackets */
+  r= tor_addr_port_parse(LOG_DEBUG,
+                         "::1:12345",
+                         &addr, &port, -1);
+  tt_int_op(r, OP_EQ, -1);
+
+  r= tor_addr_port_parse(LOG_DEBUG,
+                         "11:22::33:44:12345",
+                         &addr, &port, -1);
+  tt_int_op(r, OP_EQ, -1);
+
   /* Make sure that the default port has lower priority than the real
      one */
   r= tor_addr_port_parse(LOG_DEBUG,