mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
mod_proxy: Don't limit the size of the connectable Unix Domain Socket paths.
Since connect() to UDS path is used at several places, introduce ap_proxy_connect_uds() in proxy_util. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1602989 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -2550,13 +2550,16 @@ static apr_status_t send_http_connect(proxy_conn_rec *backend,
|
||||
|
||||
|
||||
#if APR_HAVE_SYS_UN_H
|
||||
/* lifted from mod_proxy_fdpass.c; tweaked addrlen in connect() call */
|
||||
static apr_status_t socket_connect_un(apr_socket_t *sock,
|
||||
struct sockaddr_un *sa)
|
||||
/* TODO: In APR 2.x: Extend apr_sockaddr_t to possibly be a path !!! */
|
||||
PROXY_DECLARE(apr_status_t) ap_proxy_connect_uds(apr_socket_t *sock,
|
||||
const char *uds_path,
|
||||
apr_pool_t *p)
|
||||
{
|
||||
apr_status_t rv;
|
||||
apr_os_sock_t rawsock;
|
||||
apr_interval_time_t t;
|
||||
struct sockaddr_un *sa;
|
||||
apr_socklen_t addrlen, pathlen;
|
||||
|
||||
rv = apr_os_sock_get(&rawsock, sock);
|
||||
if (rv != APR_SUCCESS) {
|
||||
@@ -2568,29 +2571,30 @@ static apr_status_t socket_connect_un(apr_socket_t *sock,
|
||||
return rv;
|
||||
}
|
||||
|
||||
pathlen = strlen(uds_path);
|
||||
/* copy the UDS path (including NUL) to the sockaddr_un */
|
||||
addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path) + pathlen;
|
||||
sa = (struct sockaddr_un *)apr_palloc(p, addrlen + 1);
|
||||
memcpy(sa->sun_path, uds_path, pathlen + 1);
|
||||
sa->sun_family = AF_UNIX;
|
||||
|
||||
do {
|
||||
const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, sun_path)
|
||||
+ strlen(sa->sun_path) + 1;
|
||||
rv = connect(rawsock, (struct sockaddr*)sa, addrlen);
|
||||
} while (rv == -1 && errno == EINTR);
|
||||
} while (rv == -1 && (rv = errno) == EINTR);
|
||||
|
||||
if ((rv == -1) && (errno == EINPROGRESS || errno == EALREADY)
|
||||
&& (t > 0)) {
|
||||
if (rv && rv != EISCONN) {
|
||||
if ((rv == EINPROGRESS || rv == EALREADY) && (t > 0)) {
|
||||
#if APR_MAJOR_VERSION < 2
|
||||
rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
|
||||
rv = apr_wait_for_io_or_timeout(NULL, sock, 0);
|
||||
#else
|
||||
rv = apr_socket_wait(sock, APR_WAIT_WRITE);
|
||||
rv = apr_socket_wait(sock, APR_WAIT_WRITE);
|
||||
#endif
|
||||
|
||||
}
|
||||
if (rv != APR_SUCCESS) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
if (rv == -1 && errno != EISCONN) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
return APR_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
@@ -2623,8 +2627,6 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
|
||||
#if APR_HAVE_SYS_UN_H
|
||||
if (conn->uds_path)
|
||||
{
|
||||
struct sockaddr_un sa;
|
||||
|
||||
rv = apr_socket_create(&newsock, AF_UNIX, SOCK_STREAM, 0,
|
||||
conn->scpool);
|
||||
if (rv != APR_SUCCESS) {
|
||||
@@ -2638,10 +2640,7 @@ PROXY_DECLARE(int) ap_proxy_connect_backend(const char *proxy_function,
|
||||
}
|
||||
conn->connection = NULL;
|
||||
|
||||
sa.sun_family = AF_UNIX;
|
||||
apr_cpystrn(sa.sun_path, conn->uds_path, sizeof(sa.sun_path));
|
||||
|
||||
rv = socket_connect_un(newsock, &sa);
|
||||
rv = ap_proxy_connect_uds(newsock, conn->uds_path, conn->scpool);
|
||||
if (rv != APR_SUCCESS) {
|
||||
apr_socket_close(newsock);
|
||||
ap_log_error(APLOG_MARK, APLOG_ERR, rv, s, APLOGNO(02454)
|
||||
|
Reference in New Issue
Block a user