From: Jeff Trawick Date: Thu, 1 Feb 2001 17:21:49 +0000 (+0000) Subject: handle a TCP connection reset between the time we accept the connection X-Git-Tag: APACHE_2_0_BETA_CANDIDATE_1~23 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=288e2cc490719b95f3c5e96469c8e0d78e27f4a8;p=apache handle a TCP connection reset between the time we accept the connection and when apr_get_sockaddr() does getsockname() or getpeername() this change will be rolled into the other MPMs later git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87947 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/connection.c b/server/connection.c index 5c9f50bf01..6287fa2177 100644 --- a/server/connection.c +++ b/server/connection.c @@ -67,6 +67,7 @@ #include "mpm_status.h" #include "http_config.h" #include "http_vhost.h" +#include "http_log.h" #include "util_filter.h" #ifdef HAVE_NETINET_IN_H @@ -270,6 +271,7 @@ conn_rec *ap_new_connection(apr_pool_t *p, server_rec *server, apr_socket_t *inout, long id) { conn_rec *conn = (conn_rec *) apr_pcalloc(p, sizeof(conn_rec)); + apr_status_t rv; /* Got a connection structure, so initialize what fields we can * (the rest are zeroed out by pcalloc). @@ -279,9 +281,21 @@ conn_rec *ap_new_connection(apr_pool_t *p, server_rec *server, conn->notes = apr_make_table(p, 5); conn->pool = p; - apr_get_sockaddr(&conn->local_addr, APR_LOCAL, inout); + if ((rv = apr_get_sockaddr(&conn->local_addr, APR_LOCAL, inout)) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_INFO, rv, server, + "apr_get_sockaddr(APR_LOCAL)"); + apr_close_socket(inout); + return NULL; + } apr_get_ipaddr(&conn->local_ip, conn->local_addr); - apr_get_sockaddr(&conn->remote_addr, APR_REMOTE, inout); + if ((rv = apr_get_sockaddr(&conn->remote_addr, APR_REMOTE, inout)) + != APR_SUCCESS) { + ap_log_error(APLOG_MARK, APLOG_INFO, rv, server, + "apr_get_sockaddr(APR_REMOTE)"); + apr_close_socket(inout); + return NULL; + } apr_get_ipaddr(&conn->remote_ip, conn->remote_addr); conn->base_server = server; conn->client_socket = inout; diff --git a/server/mpm/prefork/prefork.c b/server/mpm/prefork/prefork.c index 098d67d8a1..7db36c0b28 100644 --- a/server/mpm/prefork/prefork.c +++ b/server/mpm/prefork/prefork.c @@ -1048,9 +1048,10 @@ static void child_main(int child_num_arg) current_conn = ap_new_connection(ptrans, ap_server_conf, csd, my_child_num); - - ap_process_connection(current_conn); - ap_lingering_close(current_conn); + if (current_conn) { + ap_process_connection(current_conn); + ap_lingering_close(current_conn); + } } clean_child_exit(0); }