dgaudet 98/03/24 18:57:29
Modified: src CHANGES src/main buff.c http_main.c http_protocol.c src/modules/proxy proxy_connect.c Log: Protect against various FD_SETSIZE restrictions. Note that I couldn't really test this well -- because libc5 linux systems just don't let you muck with FD_SETSIZE easily. Folks on BSD systems should be able to -DFD_SETSIZE=16 or 20 and produce lots of interesting failures. Clean up make_sock error messages a bit. Revision Changes Path 1.730 +2 -0 apache-1.3/src/CHANGES Index: CHANGES =================================================================== RCS file: /export/home/cvs/apache-1.3/src/CHANGES,v retrieving revision 1.729 retrieving revision 1.730 diff -u -r1.729 -r1.730 --- CHANGES 1998/03/23 07:42:10 1.729 +++ CHANGES 1998/03/25 02:57:19 1.730 @@ -1,5 +1,7 @@ Changes with Apache 1.3b6 + *) Protect against FD_SETSIZE mismatches. [Dean Gaudet] + *) Make the shared object compilation command more portable by avoiding the direct combination of `-c' & `-o' which is not honored by some compilers like UnixWare's cc. [Ralf S. Engelschall] 1.66 +1 -0 apache-1.3/src/main/buff.c Index: buff.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/buff.c,v retrieving revision 1.65 retrieving revision 1.66 diff -u -r1.65 -r1.66 --- buff.c 1998/02/23 00:05:37 1.65 +++ buff.c 1998/03/25 02:57:22 1.66 @@ -529,6 +529,7 @@ #endif +/* note we assume the caller has ensured that fb->fd_in <= FD_SETSIZE */ API_EXPORT(void) bhalfduplex(BUFF *fb) { int rv; 1.310 +54 -19 apache-1.3/src/main/http_main.c Index: http_main.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_main.c,v retrieving revision 1.309 retrieving revision 1.310 diff -u -r1.309 -r1.310 --- http_main.c 1998/03/21 02:06:05 1.309 +++ http_main.c 1998/03/25 02:57:23 1.310 @@ -2567,12 +2567,19 @@ { int s; int one = 1; + char addr[512]; + + if (server->sin_addr.s_addr != htonl(INADDR_ANY)) + ap_snprintf(addr, sizeof(addr), "address %s port %d", + inet_ntoa(server->sin_addr), ntohs(server->sin_port)); + else + ap_snprintf(addr, sizeof(addr), "port %d", ntohs(server->sin_port)); /* note that because we're about to slack we don't use psocket */ block_alarms(); if ((s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { aplog_error(APLOG_MARK, APLOG_CRIT, server_conf, - "socket: Failed to get a socket, exiting child"); + "make_sock: failed to get a socket for %s", addr); unblock_alarms(); exit(1); } @@ -2595,7 +2602,6 @@ s = ap_slack(s, AP_SLACK_HIGH); note_cleanups_for_socket(p, s); /* arrange to close on exec or restart */ - unblock_alarms(); #endif #ifndef MPE @@ -2603,8 +2609,10 @@ #ifndef _OSD_POSIX if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &one, sizeof(int)) < 0) { aplog_error(APLOG_MARK, APLOG_CRIT, server_conf, - "setsockopt: (SO_REUSEADDR)"); - exit(1); + "make_sock: for %s, setsockopt: (SO_REUSEADDR)", addr); + close(s); + unblock_alarms(); + return -1; } #endif /*_OSD_POSIX*/ one = 1; @@ -2612,8 +2620,10 @@ /* BeOS does not support SO_KEEPALIVE */ if (setsockopt(s, SOL_SOCKET, SO_KEEPALIVE, (char *) &one, sizeof(int)) < 0) { aplog_error(APLOG_MARK, APLOG_CRIT, server_conf, - "setsockopt: (SO_KEEPALIVE)"); - exit(1); + "make_sock: for %s, setsockopt: (SO_KEEPALIVE)", addr); + close(s); + unblock_alarms(); + return -1; } #endif #endif @@ -2645,7 +2655,8 @@ if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, (char *) &server_conf->send_buffer_size, sizeof(int)) < 0) { aplog_error(APLOG_MARK, APLOG_WARNING, server_conf, - "setsockopt: (SO_SNDBUF): Failed to set SendBufferSize, using default"); + "make_sock: failed to set SendBufferSize for %s, " + "using default", addr); /* not a fatal error */ } } @@ -2657,17 +2668,14 @@ GETPRIVMODE(); #endif if (bind(s, (struct sockaddr *) server, sizeof(struct sockaddr_in)) == -1) { - perror("bind"); + aplog_error(APLOG_MARK, APLOG_CRIT, server_conf, + "make_sock: could not bind to %s", addr); #ifdef MPE if (ntohs(server->sin_port) < 1024) GETUSERMODE(); #endif - if (server->sin_addr.s_addr != htonl(INADDR_ANY)) - fprintf(stderr, "httpd: could not bind to address %s port %d\n", - inet_ntoa(server->sin_addr), ntohs(server->sin_port)); - else - fprintf(stderr, "httpd: could not bind to port %d\n", - ntohs(server->sin_port)); + close(s); + unblock_alarms(); exit(1); } #ifdef MPE @@ -2677,20 +2685,29 @@ if (listen(s, listenbacklog) == -1) { aplog_error(APLOG_MARK, APLOG_ERR, server_conf, - "listen: unable to listen for connections"); + "make_sock: unable to listen for connections on %s", addr); close(s); -#ifdef WORKAROUND_SOLARIS_BUG unblock_alarms(); -#endif - return -1; + exit(1); } #ifdef WORKAROUND_SOLARIS_BUG s = ap_slack(s, AP_SLACK_HIGH); note_cleanups_for_socket(p, s); /* arrange to close on exec or restart */ - unblock_alarms(); #endif + unblock_alarms(); + + /* protect various fd_sets */ + if (s >= FD_SETSIZE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + "make_sock: problem listening on %s, filedescriptor (%u) " + "larger than FD_SETSIZE (%u) " + "found, you probably need to rebuild Apache with a " + "larger FD_SETSIZE", addr, s, FD_SETSIZE); + close(s); + return -1; + } return s; } @@ -3273,6 +3290,15 @@ note_cleanups_for_fd(ptrans, csd); + /* protect various fd_sets */ + if (csd >= FD_SETSIZE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + "[csd] filedescriptor (%u) larger than FD_SETSIZE (%u) " + "found, you probably need to rebuild Apache with a " + "larger FD_SETSIZE", csd, FD_SETSIZE); + continue; + } + /* * We now have a connection, so set it up with the appropriate * socket options, file descriptors, and read/write buffers. @@ -3309,6 +3335,15 @@ dupped_csd = csd; /* Oh well... */ } note_cleanups_for_fd(ptrans, dupped_csd); + + /* protect various fd_sets */ + if (dupped_csd >= FD_SETSIZE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + "[dupped_csd] filedescriptor (%u) larger than FD_SETSIZE (%u) " + "found, you probably need to rebuild Apache with a " + "larger FD_SETSIZE", dupped_csd, FD_SETSIZE); + continue; + } #endif bpushfd(conn_io, csd, dupped_csd); 1.202 +7 -0 apache-1.3/src/main/http_protocol.c Index: http_protocol.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/main/http_protocol.c,v retrieving revision 1.201 retrieving revision 1.202 diff -u -r1.201 -r1.202 --- http_protocol.c 1998/03/24 23:20:26 1.201 +++ http_protocol.c 1998/03/25 02:57:26 1.202 @@ -1663,6 +1663,13 @@ bsetflag(fb, B_RD, 0); bnonblock(fb, B_RD); fd = bfileno(fb, B_RD); + if (fd >= FD_SETSIZE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + "send body: filedescriptor (%u) larger than FD_SETSIZE (%u) " + "found, you probably need to rebuild Apache with a " + "larger FD_SETSIZE", fd, FD_SETSIZE); + return 0; + } soft_timeout("send body", r); 1.23 +10 -0 apache-1.3/src/modules/proxy/proxy_connect.c Index: proxy_connect.c =================================================================== RCS file: /export/home/cvs/apache-1.3/src/modules/proxy/proxy_connect.c,v retrieving revision 1.22 retrieving revision 1.23 diff -u -r1.22 -r1.23 --- proxy_connect.c 1998/03/04 02:28:22 1.22 +++ proxy_connect.c 1998/03/25 02:57:28 1.23 @@ -161,6 +161,16 @@ return SERVER_ERROR; } + if (sock >= FD_SETSIZE) { + aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_WARNING, NULL, + "proxy_connect_handler: filedescriptor (%u) " + "larger than FD_SETSIZE (%u) " + "found, you probably need to rebuild Apache with a " + "larger FD_SETSIZE", sock, FD_SETSIZE); + pclosesocket(r->pool, sock); + return SERVER_ERROR; + } + j = 0; while (server_hp.h_addr_list[j] != NULL) { memcpy(&server.sin_addr, server_hp.h_addr_list[j],