summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Ylavic <ylavic@apache.org>2020-11-22 23:31:31 +0100
committerYann Ylavic <ylavic@apache.org>2020-11-22 23:31:31 +0100
commit40fa956c583b84e0b6fbca4a7c495eb5d3c9b2f7 (patch)
tree378d082571ca0fa653f008a6f63441da87741c81
parentmod_example_hooks: fix global "trace" string lifetime. (diff)
downloadapache2-40fa956c583b84e0b6fbca4a7c495eb5d3c9b2f7.tar.xz
apache2-40fa956c583b84e0b6fbca4a7c495eb5d3c9b2f7.zip
core: fix c->client_ip for unix socket connections.
Catch apr_socket_addr_get() error in core_create_conn() to avoid uninitialized conn_rec->client_ip. This can happen for mod_proxy connections using unix sockets, which are not handled by apr_socket_addr_get() until APR's r1883728 (trunk only for now). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1883729 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--server/core.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/server/core.c b/server/core.c
index e030f9eae3..e2855540a5 100644
--- a/server/core.c
+++ b/server/core.c
@@ -5437,7 +5437,6 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *s,
c->slaves = apr_array_make(c->pool, 20, sizeof(conn_slave_rec *));
c->requests = apr_array_make(c->pool, 20, sizeof(request_rec *));
-
if ((rv = apr_socket_addr_get(&c->local_addr, APR_LOCAL, csd))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00137)
@@ -5445,8 +5444,17 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *s,
apr_socket_close(csd);
return NULL;
}
+ if (apr_sockaddr_ip_get(&c->local_ip, c->local_addr)) {
+#if APR_HAVE_SOCKADDR_UN
+ if (c->local_addr->family == APR_UNIX) {
+ c->local_ip = apr_pstrndup(c->pool, c->local_addr->ipaddr_ptr,
+ c->local_addr->ipaddr_len);
+ }
+ else
+#endif
+ c->local_ip = apr_pstrdup(c->pool, "unknown");
+ }
- apr_sockaddr_ip_get(&c->local_ip, c->local_addr);
if ((rv = apr_socket_addr_get(&c->client_addr, APR_REMOTE, csd))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_INFO, rv, s, APLOGNO(00138)
@@ -5454,8 +5462,17 @@ static conn_rec *core_create_conn(apr_pool_t *ptrans, server_rec *s,
apr_socket_close(csd);
return NULL;
}
+ if (apr_sockaddr_ip_get(&c->client_ip, c->client_addr)) {
+#if APR_HAVE_SOCKADDR_UN
+ if (c->client_addr->family == APR_UNIX) {
+ c->client_ip = apr_pstrndup(c->pool, c->client_addr->ipaddr_ptr,
+ c->client_addr->ipaddr_len);
+ }
+ else
+#endif
+ c->client_ip = apr_pstrdup(c->pool, "unknown");
+ }
- apr_sockaddr_ip_get(&c->client_ip, c->client_addr);
c->base_server = s;
c->id = id;