You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by jo...@apache.org on 2017/10/25 13:18:20 UTC

svn commit: r1813286 - in /apr/apr/trunk: network_io/unix/sockaddr.c test/testipsub.c

Author: jorton
Date: Wed Oct 25 13:18:20 2017
New Revision: 1813286

URL: http://svn.apache.org/viewvc?rev=1813286&view=rev
Log:
* network_io/unix/sockaddr.c (apr_parse_addr_port): Fix regression in
  scope id parsing introduced in r1683521.

* test/testipsub.c (test_parse_addr_port): New function.

Submitted by: rjung, jorton

Modified:
    apr/apr/trunk/network_io/unix/sockaddr.c
    apr/apr/trunk/test/testipsub.c

Modified: apr/apr/trunk/network_io/unix/sockaddr.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/network_io/unix/sockaddr.c?rev=1813286&r1=1813285&r2=1813286&view=diff
==============================================================================
--- apr/apr/trunk/network_io/unix/sockaddr.c (original)
+++ apr/apr/trunk/network_io/unix/sockaddr.c Wed Oct 25 13:18:20 2017
@@ -277,7 +277,7 @@ APR_DECLARE(apr_status_t) apr_parse_addr
                 return APR_EINVAL;
             }
             addrlen = scope_delim - str - 1;
-            *scope_id = apr_pstrmemdup(p, scope_delim, end_bracket - scope_delim - 1);
+            *scope_id = apr_pstrmemdup(p, scope_delim + 1, end_bracket - scope_delim - 1);
         }
         else {
             addrlen = addrlen - 2; /* minus 2 for '[' and ']' */

Modified: apr/apr/trunk/test/testipsub.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/test/testipsub.c?rev=1813286&r1=1813285&r2=1813286&view=diff
==============================================================================
--- apr/apr/trunk/test/testipsub.c (original)
+++ apr/apr/trunk/test/testipsub.c Wed Oct 25 13:18:20 2017
@@ -165,6 +165,52 @@ static void test_badip_str(abts_case *tc
                       "The specified IP address is invalid.");
 }
 
+static void test_parse_addr_port(abts_case *tc, void *data)
+{
+    const struct {
+        const char *input;
+        apr_status_t rv;
+        const char *addr, *scope_id;
+        apr_port_t port;
+    } *test, testcases[] = {
+        { "localhost:80", APR_SUCCESS, "localhost", NULL, 80 }
+        ,{ "www.example.com:8080", APR_SUCCESS, "www.example.com", NULL, 8080 }
+        ,{ "w:1", APR_SUCCESS, "w", NULL, 1 }
+        ,{ "127.0.0.1:80", APR_SUCCESS, "127.0.0.1", NULL, 80 }
+        ,{ "[::]:80", APR_SUCCESS, "::", NULL, 80 }
+        ,{ "localhost:999999", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "localhost:0", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "[::]z:80", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "[:::80", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "[zzzz]:80", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "[::%]:80", APR_EINVAL, NULL, NULL, 0 }
+        ,{ "[::%eth0]:80", APR_SUCCESS, "::", "eth0", 80 }
+/*        ,{ "127.0.0.1:80x", APR_EINVAL, NULL, NULL, 0 }  <- should fail, doesn't  */
+/*        ,{ "127.0.0.1x:80", APR_EINVAL, NULL, NULL, 0 }  <- maybe should fail?, doesn't  */
+/*        ,{ "localhost:-1", APR_EINVAL, NULL, NULL, 0 }   <- should fail, doesn't */
+    };
+    unsigned i;
+        
+    for (i = 0; i < (sizeof testcases / sizeof testcases[0]); i++) {
+        char *addr, *scope_id;
+        apr_port_t port;
+        apr_status_t rv;
+
+        test = &testcases[i];
+        
+        rv = apr_parse_addr_port(&addr, &scope_id, &port, test->input, p);
+        ABTS_INT_EQUAL(tc, test->rv, rv);
+
+        if (test->rv != APR_SUCCESS) continue;
+
+        APR_ASSERT_SUCCESS(tc, "parse address", test->rv);
+
+        ABTS_STR_EQUAL(tc, test->addr, addr);
+        ABTS_STR_EQUAL(tc, test->scope_id, scope_id);
+        ABTS_INT_EQUAL(tc, test->port, port);
+    }
+}
+
 abts_suite *testipsub(abts_suite *suite)
 {
     suite = ADD_SUITE(suite)
@@ -174,6 +220,7 @@ abts_suite *testipsub(abts_suite *suite)
     abts_run_test(suite, test_interesting_subnets, NULL);
     abts_run_test(suite, test_badmask_str, NULL);
     abts_run_test(suite, test_badip_str, NULL);
+    abts_run_test(suite, test_parse_addr_port, NULL);
     return suite;
 }