httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christophe JAILLET <christophe.jail...@wanadoo.fr>
Subject Re: Issue with connect() call made in mod_proxy_fdpass?
Date Sat, 31 May 2014 06:34:49 GMT
Hi,

I share your feeling.

See line 2572 of proxy_util.c, where the length is computed as follow:

         const socklen_t addrlen = APR_OFFSETOF(struct sockaddr_un, 
sun_path)
                                   + strlen(sa->sun_path) + 1;
         rv = connect(rawsock, (struct sockaddr*)sa, addrlen);


Apart that, the 2 'socket_connect_un' functions (in mod_proxy_fdpass.c 
<https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/proxy/mod_proxy_fdpass.c>

and in proxy_util.c) are the same.

CJ



Le 31/05/2014 05:54, Graham Dumpleton a écrit :
> In mod_proxy_fdpass there is a function socket_connect_un():
>
> https://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/proxy/mod_proxy_fdpass.c
>
> which contains the code:
>
>         rv = connect(rawsock, (struct sockaddr*)sa,
>      sizeof(*sa) + strlen(sa->sun_path));
>
> Can some explain to me why it is using:
>
> sizeof(*sa) + strlen(sa->sun_path)
>
> rather than just:
>
> sizeof(*sa)
>
> It just doesn't seem right.
>
> One does find on the Internet examples which use:
>
> #define SERV_PATH "./serv.path" struct sockaddr_un serv_addr; int 
> servlen; bzero((char *) &serv_addr, sizeof(serv_addr)); 
> serv_addr.sun_family = AF_UNIX; strcpy(serv_addr.sun_path, SERV_PATH); 
> servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family); 
> connect(sockfd, (struct sockaddr *) &serv_addr, servlen);
>
> That is, the sockaddr_un structure length is calculated as:
>
> servlen = strlen(serv_addr.sun_path) + sizeof(serv_addr.sun_family)
>
> It almost looked like someone started with something similar, but 
> rather than replace the whole thing with:
>
> sizeof(*sa)
>
> replaced just the part:
>
> sizeof(serv_addr.sun_family)
>
> and then wrongly still added the length of the sun_path member of the 
> struct to that.
>
> Any comments? Is there something else funny going on with 
> mod_proxy_fdpass that requires it be done this way?
>
> Graham
>
>
>



Mime
View raw message