Skip to content

Commit

Permalink
Merge r1920061, r1920070 from trunk:
Browse files Browse the repository at this point in the history
Replicate r983618 in Win32 code.

* network_io/win32/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): Fix test to portably switch
  the socket to non-blocking mode using apr_socket_timeout_set().
  Also make the test SKIP for the case where the connect() completes
  synchronously.

See: https://lists.apache.org/thread/9m0n8s3zxq0wznnq9nyxswoqdhx7167b

Submitted by: ivan, jorton
Reviewed by: jorton


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.8.x@1920119 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
notroj committed Aug 21, 2024
1 parent 15cc371 commit 9d20a45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion network_io/win32/sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,10 @@ APR_DECLARE(apr_status_t) apr_socket_connect(apr_socket_t *sock,
sock->remote_addr_unknown = 0;

/* Copy the address structure details in. */
sock->remote_addr = sa;
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->sa.sin.sin_port == 0) {
Expand Down
12 changes: 6 additions & 6 deletions test/testsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,17 @@ static void test_get_addr(abts_case *tc, void *data)
APR_ASSERT_SUCCESS(tc, "create client socket", rv);

APR_ASSERT_SUCCESS(tc, "enable non-block mode",
apr_socket_opt_set(cd, APR_SO_NONBLOCK, 1));
apr_socket_timeout_set(cd, 0));

/* It is valid for a connect() on a socket with NONBLOCK set to
* succeed (if the connection can be established synchronously),
* but if it does, this test cannot proceed. */
/* It is valid for a connect() on a non-blocking socket to succeed
* (if the connection can be established synchronously), but if it
* does, this test cannot proceed. */
rv = apr_socket_connect(cd, sa);
if (rv == APR_SUCCESS) {
apr_socket_close(ld);
apr_socket_close(cd);
ABTS_NOT_IMPL(tc, "Cannot test if connect completes "
"synchronously");
ABTS_SKIP(tc, data, "Cannot test if connect() completes "
"synchronously");
return;
}

Expand Down

0 comments on commit 9d20a45

Please sign in to comment.