You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Tony Finch <do...@dotat.at> on 2000/07/30 03:52:47 UTC

Bugs in 1.3's make_sock?

I'm trying to add support for FreeBSD's accept filters to Apache 1.3
and I think I have found a collection of bugs in make_sock(). There
are a number of situations in which it can fail and return -1 (e.g. a
cock-up in new code added by me), but this return value isn't checked
in any useful sort of way so the server ends up trying to call
accept() on descriptor -1. From looking at the CVS logs it seems that
the server used to just bomb out if this happened, but some of these
exits were turned into returns by Dean in revs 1.189 and 1.310. I
think this is wrong and that the included patch should be applied.

Tony.
-- 
en oeccget g mtcaa    f.a.n.finch
v spdlkishrhtewe y    dot@dotat.at
eatp o v eiti i d.    fanf@covalent.net


? http_main.c.diff
Index: http_main.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
retrieving revision 1.507
diff -u -r1.507 http_main.c
--- http_main.c	2000/07/29 23:56:19	1.507
+++ http_main.c	2000/07/30 01:51:19
@@ -3306,7 +3306,7 @@
 	close(s);
 #endif
 	ap_unblock_alarms();
-	return -1;
+	exit(1);
     }
 #endif /*_OSD_POSIX*/
     one = 1;
@@ -3321,7 +3321,7 @@
 #endif
 
 	ap_unblock_alarms();
-	return -1;
+	exit(1);
     }
 #endif
 
@@ -3418,7 +3418,7 @@
 #else
 	close(s);
 #endif
-	return -1;
+	exit(1);
     }
 #endif
 
@@ -3505,16 +3505,14 @@
     for (;;) {
 	fd = find_listener(lr);
 	if (fd < 0) {
-        fd = make_sock(p, &lr->local_addr);
+	    fd = make_sock(p, &lr->local_addr);
 	}
 	else {
 	    ap_note_cleanups_for_socket(p, fd);
-	}
-	if (fd >= 0) {
-	    FD_SET(fd, &listenfds);
-	    if (fd > listenmaxfd)
-		listenmaxfd = fd;
 	}
+	FD_SET(fd, &listenfds);
+	if (fd > listenmaxfd)
+	    listenmaxfd = fd;
 	lr->fd = fd;
 	if (lr->next == NULL)
 	    break;

Re: Bugs in 1.3's make_sock?

Posted by dean gaudet <dg...@arctic.org>.
+1

-dean

On Sun, 30 Jul 2000, Tony Finch wrote:

> 
> I'm trying to add support for FreeBSD's accept filters to Apache 1.3
> and I think I have found a collection of bugs in make_sock(). There
> are a number of situations in which it can fail and return -1 (e.g. a
> cock-up in new code added by me), but this return value isn't checked
> in any useful sort of way so the server ends up trying to call
> accept() on descriptor -1. From looking at the CVS logs it seems that
> the server used to just bomb out if this happened, but some of these
> exits were turned into returns by Dean in revs 1.189 and 1.310. I
> think this is wrong and that the included patch should be applied.
> 
> Tony.
> -- 
> en oeccget g mtcaa    f.a.n.finch
> v spdlkishrhtewe y    dot@dotat.at
> eatp o v eiti i d.    fanf@covalent.net
> 
> 
> ? http_main.c.diff
> Index: http_main.c
> ===================================================================
> RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
> retrieving revision 1.507
> diff -u -r1.507 http_main.c
> --- http_main.c	2000/07/29 23:56:19	1.507
> +++ http_main.c	2000/07/30 01:51:19
> @@ -3306,7 +3306,7 @@
>  	close(s);
>  #endif
>  	ap_unblock_alarms();
> -	return -1;
> +	exit(1);
>      }
>  #endif /*_OSD_POSIX*/
>      one = 1;
> @@ -3321,7 +3321,7 @@
>  #endif
>  
>  	ap_unblock_alarms();
> -	return -1;
> +	exit(1);
>      }
>  #endif
>  
> @@ -3418,7 +3418,7 @@
>  #else
>  	close(s);
>  #endif
> -	return -1;
> +	exit(1);
>      }
>  #endif
>  
> @@ -3505,16 +3505,14 @@
>      for (;;) {
>  	fd = find_listener(lr);
>  	if (fd < 0) {
> -        fd = make_sock(p, &lr->local_addr);
> +	    fd = make_sock(p, &lr->local_addr);
>  	}
>  	else {
>  	    ap_note_cleanups_for_socket(p, fd);
> -	}
> -	if (fd >= 0) {
> -	    FD_SET(fd, &listenfds);
> -	    if (fd > listenmaxfd)
> -		listenmaxfd = fd;
>  	}
> +	FD_SET(fd, &listenfds);
> +	if (fd > listenmaxfd)
> +	    listenmaxfd = fd;
>  	lr->fd = fd;
>  	if (lr->next == NULL)
>  	    break;
>