diff options
author | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2017-10-25 13:26:42 +0000 |
---|---|---|
committer | jorton <jorton@13f79535-47bb-0310-9956-ffa450edef68> | 2017-10-25 13:26:42 +0000 |
commit | 27490b0d47c92b2e62a73cb15f6792d87afdfcd7 (patch) | |
tree | b558f01c8cd3b77660f3051589de867194d17450 | |
parent | 1c3e186170d3bb4aef391e486f88788b9643f0a4 (diff) | |
download | libapr-27490b0d47c92b2e62a73cb15f6792d87afdfcd7.tar.gz |
Merge r1813286 from trunk:
* 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
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.6.x@1813288 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | network_io/unix/sockaddr.c | 2 | ||||
-rw-r--r-- | test/testipsub.c | 47 |
3 files changed, 50 insertions, 2 deletions
@@ -1,7 +1,8 @@ -*- coding: utf-8 -*- Changes for APR 1.6.4 - + *) Fix apr_parse_addr_port() regression in scope_id parsing introduced + in 1.6.3. [Rainer Jung] Changes for APR 1.6.3 diff --git a/network_io/unix/sockaddr.c b/network_io/unix/sockaddr.c index 8cfc0d7a4..a375f72ec 100644 --- a/network_io/unix/sockaddr.c +++ b/network_io/unix/sockaddr.c @@ -277,7 +277,7 @@ APR_DECLARE(apr_status_t) apr_parse_addr_port(char **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 ']' */ diff --git a/test/testipsub.c b/test/testipsub.c index 342b5ca37..6b1b92625 100644 --- a/test/testipsub.c +++ b/test/testipsub.c @@ -165,6 +165,52 @@ static void test_badip_str(abts_case *tc, void *data) "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; } |