summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrpluem <rpluem@13f79535-47bb-0310-9956-ffa450edef68>2010-08-20 15:16:46 +0000
committerrpluem <rpluem@13f79535-47bb-0310-9956-ffa450edef68>2010-08-20 15:16:46 +0000
commit11e2b71b02c27a7465bf184df0f352576f6cac34 (patch)
tree1643c8cef3b146789cb3e8ea3e38ab3d8c97b52d
parent89f0b7009ab81f979febd7b3881cbd67b225d35f (diff)
downloadlibapr-11e2b71b02c27a7465bf184df0f352576f6cac34.tar.gz
Merge r983618 from trunk:
* network_io/unix/sockets.c (apr_socket_connect): Copy the remote address by value rather than by reference. This ensures that the sockaddr object returned by apr_socket_addr_get is allocated from the same pool as the socket object itself, as apr_socket_accept does; avoiding any potential lifetime mismatches. * test/testsock.c (test_get_addr): Enhance test case to cover this. PR: 49713 Submitted by: jorton Reviewed by: rpluem git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.4.x@987540 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--network_io/unix/sockets.c9
-rw-r--r--test/testsock.c35
2 files changed, 35 insertions, 9 deletions
diff --git a/network_io/unix/sockets.c b/network_io/unix/sockets.c
index bb5e220f9..93f2632b8 100644
--- a/network_io/unix/sockets.c
+++ b/network_io/unix/sockets.c
@@ -343,10 +343,13 @@ apr_status_t apr_socket_connect(apr_socket_t *sock, apr_sockaddr_t *sa)
/* A real remote address was passed in. If the unspecified
* address was used, the actual remote addr will have to be
* determined using getpeername() if required. */
- /* ### this should probably be a structure copy + fixup as per
- * _accept()'s handling of local_addr */
- sock->remote_addr = sa;
sock->remote_addr_unknown = 0;
+
+ /* Copy the address structure details in. */
+ sock->remote_addr->sa = sa->sa;
+ sock->remote_addr->salen = sa->salen;
+ /* Adjust ipaddr_ptr et al. */
+ apr_sockaddr_vars_set(sock->remote_addr, sa->family, sa->port);
}
if (sock->local_addr->port == 0) {
diff --git a/test/testsock.c b/test/testsock.c
index b1115fd46..a15dbf8d4 100644
--- a/test/testsock.c
+++ b/test/testsock.c
@@ -328,8 +328,11 @@ static void test_get_addr(abts_case *tc, void *data)
apr_status_t rv;
apr_socket_t *ld, *sd, *cd;
apr_sockaddr_t *sa, *ca;
+ apr_pool_t *subp;
char *a, *b;
+ APR_ASSERT_SUCCESS(tc, "create subpool", apr_pool_create(&subp, p));
+
ld = setup_socket(tc);
APR_ASSERT_SUCCESS(tc,
@@ -337,7 +340,7 @@ static void test_get_addr(abts_case *tc, void *data)
apr_socket_addr_get(&sa, APR_LOCAL, ld));
rv = apr_socket_create(&cd, sa->family, SOCK_STREAM,
- APR_PROTO_TCP, p);
+ APR_PROTO_TCP, subp);
APR_ASSERT_SUCCESS(tc, "create client socket", rv);
APR_ASSERT_SUCCESS(tc, "enable non-block mode",
@@ -363,7 +366,7 @@ static void test_get_addr(abts_case *tc, void *data)
}
APR_ASSERT_SUCCESS(tc, "accept connection",
- apr_socket_accept(&sd, ld, p));
+ apr_socket_accept(&sd, ld, subp));
{
/* wait for writability */
@@ -383,18 +386,38 @@ static void test_get_addr(abts_case *tc, void *data)
APR_ASSERT_SUCCESS(tc, "get local address of server socket",
apr_socket_addr_get(&sa, APR_LOCAL, sd));
-
APR_ASSERT_SUCCESS(tc, "get remote address of client socket",
apr_socket_addr_get(&ca, APR_REMOTE, cd));
-
- a = apr_psprintf(p, "%pI", sa);
- b = apr_psprintf(p, "%pI", ca);
+ /* Test that the pool of the returned sockaddr objects exactly
+ * match the socket. */
+ ABTS_PTR_EQUAL(tc, subp, sa->pool);
+ ABTS_PTR_EQUAL(tc, subp, ca->pool);
+
+ /* Check equivalence. */
+ a = apr_psprintf(p, "%pI fam=%d", sa, sa->family);
+ b = apr_psprintf(p, "%pI fam=%d", ca, ca->family);
ABTS_STR_EQUAL(tc, a, b);
+
+ /* Check pool of returned sockaddr, as above. */
+ APR_ASSERT_SUCCESS(tc, "get local address of client socket",
+ apr_socket_addr_get(&sa, APR_LOCAL, cd));
+ APR_ASSERT_SUCCESS(tc, "get remote address of server socket",
+ apr_socket_addr_get(&ca, APR_REMOTE, sd));
+
+ /* Check equivalence. */
+ a = apr_psprintf(p, "%pI fam=%d", sa, sa->family);
+ b = apr_psprintf(p, "%pI fam=%d", ca, ca->family);
+ ABTS_STR_EQUAL(tc, a, b);
+
+ ABTS_PTR_EQUAL(tc, subp, sa->pool);
+ ABTS_PTR_EQUAL(tc, subp, ca->pool);
apr_socket_close(cd);
apr_socket_close(sd);
apr_socket_close(ld);
+
+ apr_pool_destroy(subp);
}
abts_suite *testsock(abts_suite *suite)