httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tom Tromey <tro...@creche.cygnus.com>
Subject CGI-related core
Date Wed, 25 Sep 1996 21:46:46 GMT
I'm still using Apache 1.1.1.

This CGI script causes Apache to dump core:

================================================================
#! /bin/sh

# CGI script that returns status 204 and no data.

echo "Status: 204 No Content"

exit 0
================================================================


The problem occurs in the send_error_response function in
http_protocol.c.  The problem is that the function index_of_response
can return -1, but the function response_code_string isn't prepared to
handle that case.

I fixed this by having send_error_response check for the -1 return,
and switch to a "500" error code in this case.  I don't know if this
is the best solution or not.  However, it did eliminate the core dump.

Patch appended.

I've noticed there are a number of defined status codes missing from
the tables in http_protocol.c.  From the HTTP/1.0 spec: 201, 202, 204,
301, 503.  Is there any reason why?  It makes sense for a CGI script
to return some of these codes, and this is something I'd like to check
in my test suite.  If there is no reason, I'll happily generate a
patch.

Last, I've noticed a minor inconsistency in send_error_response.  Most
of the function uses the "status" variable.  But the switch statement
towards the end switches on r->status.  Is there a reason for this
discrepancy (and if so, could someone please add a comment explaining
the reason?).  My patch assumes that this is just an oversight, and
changes r->status to just status.

All the above problems seem to exist in the current snapshot.  I
haven't tried it, though.

Tom
-- 
tromey@cygnus.com                 Member, League for Programming Freedom

Index: http_protocol.c
===================================================================
RCS file: /rel/cvsfiles/devo/apache/src/http_protocol.c,v
retrieving revision 1.4
diff -c -5 -r1.4 http_protocol.c
*** http_protocol.c	1996/09/23 17:20:21	1.4
--- http_protocol.c	1996/09/25 21:40:13
***************
*** 847,856 ****
--- 847,862 ----
      char *custom_response;
      int status = r->status;
      int idx = index_of_response (status);
      char *location = table_get (r->headers_out, "Location");
  
+     /* If status code not found, use code 500.  */
+     if (idx == -1) {
+         status = SERVER_ERROR;
+         idx = index_of_response (SERVER_ERROR);
+     }
+ 
      if (!r->assbackwards) {
  	int i;
  	table *err_hdrs_arr = r->err_headers_out;
  	table_entry *err_hdrs = (table_entry *)err_hdrs_arr->elts;
    
***************
*** 889,899 ****
  	BUFF *fd = c->client;
  	
          bvputs(fd,"<HEAD><TITLE>", title, "</TITLE></HEAD>\n<BODY><H1>",
title,
  	       "</H1>\n", NULL);
  	
!         switch (r->status) {
  	case REDIRECT:
  	    bvputs(fd, "The document has moved <A HREF=\"",
  		    escape_html(r->pool, location), "\">here</A>.<P>\n", NULL);
  	    break;
  	case AUTH_REQUIRED:
--- 895,905 ----
  	BUFF *fd = c->client;
  	
          bvputs(fd,"<HEAD><TITLE>", title, "</TITLE></HEAD>\n<BODY><H1>",
title,
  	       "</H1>\n", NULL);
  	
!         switch (status) {
  	case REDIRECT:
  	    bvputs(fd, "The document has moved <A HREF=\"",
  		    escape_html(r->pool, location), "\">here</A>.<P>\n", NULL);
  	    break;
  	case AUTH_REQUIRED:

Mime
View raw message