Browse Source

[cygwin] fix mod_proxy and mod_fastcgi ioctl use

cygwin does not support ioctl on sockets, returning EOPTNOTSUPP
(would be better if cygwin used Windows ioctlsocket() instead)

Windows uses signed (socklen_t), so add some casts to quiet warnings

Windows path handling is convoluted, so disable one tests in mod_fastcgi
since trailing spaces are removed from URL for _WIN32 and __CYGWIN__ in
response.c
personal/stbuehler/mod-csrf-old
Glenn Strauss 5 years ago
parent
commit
8dcbd61a45
  1. 2
      src/http-header-glue.c
  2. 11
      src/mod_fastcgi.c
  3. 8
      src/mod_proxy.c
  4. 2
      src/mod_scgi.c
  5. 4
      tests/mod-fastcgi.t

2
src/http-header-glue.c

@ -143,7 +143,7 @@ int http_response_redirect_to_directory(server *srv, connection *con) {
our_addr_len = sizeof(our_addr);
if (-1 == getsockname(con->fd, (struct sockaddr *)&our_addr, &our_addr_len)
|| our_addr_len > sizeof(our_addr)) {
|| our_addr_len > (socklen_t)sizeof(our_addr)) {
con->http_status = 500;
log_error_write(srv, __FILE__, __LINE__, "ss",

11
src/mod_fastcgi.c

@ -2009,7 +2009,7 @@ static int fcgi_create_env(server *srv, handler_ctx *hctx, int request_id) {
our_addr_len = sizeof(our_addr);
if (-1 == getsockname(con->fd, (struct sockaddr *)&our_addr, &our_addr_len)
|| our_addr_len > sizeof(our_addr)) {
|| our_addr_len > (socklen_t)sizeof(our_addr)) {
s = inet_ntop_cache_get_ip(srv, &(srv_sock->addr));
} else {
s = inet_ntop_cache_get_ip(srv, &(our_addr));
@ -2496,7 +2496,7 @@ static int fastcgi_get_packet(server *srv, handler_ctx *hctx, fastcgi_response_p
static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
int fin = 0;
int toread, ret;
ssize_t r;
ssize_t r = 0;
plugin_data *p = hctx->plugin_data;
connection *con = hctx->remote_conn;
@ -2507,6 +2507,7 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
/*
* check how much we have to read
*/
#if !defined(_WIN32) && !defined(__CYGWIN__)
if (ioctl(hctx->fd, FIONREAD, &toread)) {
if (errno == EAGAIN) {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
@ -2517,6 +2518,9 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
fcgi_fd);
return -1;
}
#else
toread = 4096;
#endif
if (toread > 0) {
char *mem;
@ -2547,7 +2551,8 @@ static int fcgi_demux_response(server *srv, handler_ctx *hctx) {
fcgi_fd, strerror(errno));
return -1;
}
} else {
}
if (0 == r) {
log_error_write(srv, __FILE__, __LINE__, "ssdsb",
"unexpected end-of-file (perhaps the fastcgi process died):",
"pid:", proc->pid,

8
src/mod_proxy.c

@ -628,6 +628,7 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
int proxy_fd = hctx->fd;
/* check how much we have to read */
#if !defined(_WIN32) && !defined(__CYGWIN__)
if (ioctl(hctx->fd, FIONREAD, &b)) {
if (errno == EAGAIN) {
fdevent_event_add(srv->ev, &(hctx->fde_ndx), hctx->fd, FDEVENT_IN);
@ -638,6 +639,9 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
proxy_fd);
return -1;
}
#else
b = 4096;
#endif
if (p->conf.debug) {
@ -675,6 +679,10 @@ static int proxy_demux_response(server *srv, handler_ctx *hctx) {
return -1;
}
#if defined(_WIN32) || defined(__CYGWIN__)
if (0 == r) return 1; /* fin */
#endif
/* this should be catched by the b > 0 above */
force_assert(r);

2
src/mod_scgi.c

@ -1618,7 +1618,7 @@ static int scgi_create_env(server *srv, handler_ctx *hctx) {
our_addr_len = sizeof(our_addr);
if (-1 == getsockname(con->fd, (struct sockaddr *)&our_addr, &our_addr_len)
|| our_addr_len > sizeof(our_addr)) {
|| our_addr_len > (socklen_t)sizeof(our_addr)) {
s = inet_ntop_cache_get_ip(srv, &(srv_sock->addr));
} else {
s = inet_ntop_cache_get_ip(srv, &(our_addr));

4
tests/mod-fastcgi.t

@ -129,12 +129,16 @@ EOF
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
ok($tf->handle_http($t) == 0, 'PATHINFO');
if ($^O ne "cygwin") {
$t->{REQUEST} = ( <<EOF
GET /cgi.php%20%20%20 HTTP/1.0
EOF
);
$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
ok($tf->handle_http($t) == 0, 'No source retrieval');
} else {
ok(1, 'No source retrieval; skipped on cygwin; see response.c');
}
$t->{REQUEST} = ( <<EOF
GET /www/abc/def HTTP/1.0

Loading…
Cancel
Save