apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rpl...@apache.org
Subject svn commit: r987541 - in /apr/apr/branches/1.3.x: ./ network_io/unix/ test/
Date Fri, 20 Aug 2010 15:17:06 GMT
Author: rpluem
Date: Fri Aug 20 15:17:05 2010
New Revision: 987541

URL: http://svn.apache.org/viewvc?rev=987541&view=rev
Log:
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

Modified:
    apr/apr/branches/1.3.x/   (props changed)
    apr/apr/branches/1.3.x/network_io/unix/sockets.c
    apr/apr/branches/1.3.x/test/NWGNUaprtest   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUglobalmutexchild   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUmod_test   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUproc_child   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUreadchild   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUsockchild   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUtestatmc   (props changed)
    apr/apr/branches/1.3.x/test/NWGNUtryread   (props changed)
    apr/apr/branches/1.3.x/test/testsock.c

Propchange: apr/apr/branches/1.3.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,2 +1,2 @@
 /apr/apr/branches/1.4.x:783970
-/apr/apr/trunk:712674,733052,742752,747990,748361,748371,748565,748902,748988,749810,760443,782838,783398,783958,788588,793193,794485,795267,799497,800627,809854,829490,831641,835607,905040,908427,910419
+/apr/apr/trunk:712674,733052,742752,747990,748361,748371,748565,748902,748988,749810,760443,782838,783398,783958,788588,793193,794485,795267,799497,800627,809854,829490,831641,835607,905040,908427,910419,983618

Modified: apr/apr/branches/1.3.x/network_io/unix/sockets.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/network_io/unix/sockets.c?rev=987541&r1=987540&r2=987541&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/network_io/unix/sockets.c (original)
+++ apr/apr/branches/1.3.x/network_io/unix/sockets.c Fri Aug 20 15:17:05 2010
@@ -343,10 +343,13 @@ apr_status_t apr_socket_connect(apr_sock
         /* 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) {

Propchange: apr/apr/branches/1.3.x/test/NWGNUaprtest
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnuaprtest:783970
-/apr/apr/trunk/test/NWGNUaprtest:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUaprtest:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnuaprtest:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUglobalmutexchild
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnuglobalmutexchild:783970
-/apr/apr/trunk/test/NWGNUglobalmutexchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUglobalmutexchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnuglobalmutexchild:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUmod_test
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnumod_test:783970
-/apr/apr/trunk/test/NWGNUmod_test:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUmod_test:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnumod_test:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUproc_child
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnuproc_child:783970
-/apr/apr/trunk/test/NWGNUproc_child:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUproc_child:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnuproc_child:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUreadchild
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnureadchild:783970
-/apr/apr/trunk/test/NWGNUreadchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUreadchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnureadchild:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUsockchild
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnusockchild:783970
-/apr/apr/trunk/test/NWGNUsockchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUsockchild:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnusockchild:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUtestatmc
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnutestatmc:783970
-/apr/apr/trunk/test/NWGNUtestatmc:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUtestatmc:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnutestatmc:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Propchange: apr/apr/branches/1.3.x/test/NWGNUtryread
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Aug 20 15:17:05 2010
@@ -1,3 +1,3 @@
 /apr/apr/branches/1.4.x/test/nwgnutryread:783970
-/apr/apr/trunk/test/NWGNUtryread:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419
+/apr/apr/trunk/test/NWGNUtryread:793193,794485,795267,799497,800627,809854,829490,831641,908427,910419,983618
 /apr/apr/trunk/test/nwgnutryread:712674,733052,742752,747990,748361,748371,748565,748988,749810,782838,783398,783958,788588

Modified: apr/apr/branches/1.3.x/test/testsock.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/1.3.x/test/testsock.c?rev=987541&r1=987540&r2=987541&view=diff
==============================================================================
--- apr/apr/branches/1.3.x/test/testsock.c (original)
+++ apr/apr/branches/1.3.x/test/testsock.c Fri Aug 20 15:17:05 2010
@@ -267,8 +267,11 @@ static void test_get_addr(abts_case *tc,
     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,
@@ -276,7 +279,7 @@ static void test_get_addr(abts_case *tc,
                        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",
@@ -302,7 +305,7 @@ static void test_get_addr(abts_case *tc,
     }
 
     APR_ASSERT_SUCCESS(tc, "accept connection",
-                       apr_socket_accept(&sd, ld, p));
+                       apr_socket_accept(&sd, ld, subp));
     
     {
         /* wait for writability */
@@ -322,18 +325,38 @@ static void test_get_addr(abts_case *tc,
 
     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)



Mime
View raw message