Skip to content

Commit

Permalink
* network_io/unix/sockaddr.c (apr_sockaddr_zone_set): Fail
Browse files Browse the repository at this point in the history
  for an address which is not link-local.

* include/apr_network_io.h: Document the above.

* test/testsock.c (test_zone): Test for that.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@1816628 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Nov 29, 2017
1 parent 30cab59 commit 624111a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/apr_network_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ APR_DECLARE(apr_status_t) apr_sockaddr_info_copy(apr_sockaddr_t **dst,
/* Set the zone of an IPv6 link-local address object.
* @param sa Socket address object
* @param zone_id Zone ID (textual "eth0" or numeric "3").
* @return Returns APR_EBADIP for non-IPv6 socket or an IPv6 address
* which isn't link-local.
*/
APR_DECLARE(apr_status_t) apr_sockaddr_zone_set(apr_sockaddr_t *sa,
const char *zone_id);
Expand Down
3 changes: 2 additions & 1 deletion network_io/unix/sockaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,8 @@ APR_DECLARE(apr_status_t) apr_sockaddr_zone_set(apr_sockaddr_t *sa,
#else
unsigned int idx;

if (sa->family != APR_INET6) {
if (sa->family != APR_INET6
|| !IN6_IS_ADDR_LINKLOCAL((struct in6_addr *)sa->ipaddr_ptr)) {
return APR_EBADIP;
}

Expand Down
7 changes: 6 additions & 1 deletion test/testsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ static void test_zone(abts_case *tc, void *data)
const char *name = NULL;
apr_uint32_t id = 0;

/* RFC 5737 address */
rv = apr_sockaddr_info_get(&sa, "127.0.0.1", APR_INET, 8080, 0, p);
APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);

Expand All @@ -669,6 +668,12 @@ static void test_zone(abts_case *tc, void *data)
apr_sockaddr_zone_set(sa, "1"));
ABTS_INT_EQUAL(tc, APR_EBADIP,
apr_sockaddr_zone_get(sa, &name, &id, p));

rv = apr_sockaddr_info_get(&sa, "::1", APR_INET6, 8080, 0, p);
APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);

/* Fail for an address which isn't link-local */
ABTS_INT_EQUAL(tc, APR_EBADIP, apr_sockaddr_zone_set(sa, "1"));

rv = apr_sockaddr_info_get(&sa, TEST_ZONE_ADDR, APR_INET6, 8080, 0, p);
APR_ASSERT_SUCCESS(tc, "Problem generating sockaddr", rv);
Expand Down

0 comments on commit 624111a

Please sign in to comment.