Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id C1A93200D27 for ; Wed, 25 Oct 2017 15:18:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id BFC62160BDA; Wed, 25 Oct 2017 13:18:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1010F1609E5 for ; Wed, 25 Oct 2017 15:18:21 +0200 (CEST) Received: (qmail 97570 invoked by uid 500); 25 Oct 2017 13:18:21 -0000 Mailing-List: contact commits-help@apr.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: Reply-To: dev@apr.apache.org List-Id: Delivered-To: mailing list commits@apr.apache.org Received: (qmail 97561 invoked by uid 99); 25 Oct 2017 13:18:21 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 25 Oct 2017 13:18:21 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 37D743A030D for ; Wed, 25 Oct 2017 13:18:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1813286 - in /apr/apr/trunk: network_io/unix/sockaddr.c test/testipsub.c Date: Wed, 25 Oct 2017 13:18:20 -0000 To: commits@apr.apache.org From: jorton@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171025131820.37D743A030D@svn01-us-west.apache.org> archived-at: Wed, 25 Oct 2017 13:18:22 -0000 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; }