httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roy T. Fielding" <field...@kiwi.ICS.UCI.EDU>
Subject Re: bread() patch
Date Wed, 20 Nov 1996 08:02:51 GMT
Okay, here is my suggested patch for get_client_block.  Note that I also
fixed a separate problem: it was assuming that bread would always read
an entire chunk of data, which may not be true in practice.

While testing this, I also discovered that CONTENT_LENGTH is not being
passed to the CGI script if the incoming data is chunked.  How is the
script supposed to know how much data to read if we remove the chunk sizes
but do not create CONTENT_LENGTH?  They can't look for EOF.  We may have
to rethink this notion of protecting stupid CGI scripts by doing the
chunking transparently.  Either that or use a temporary file.

.....Roy

Index: http_protocol.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_protocol.c,v
retrieving revision 1.75
diff -c -r1.75 http_protocol.c
*** http_protocol.c	1996/11/14 07:35:49	1.75
--- http_protocol.c	1996/11/20 07:41:17
***************
*** 1080,1086 ****
   * 3. Finally, call get_client_block in a loop. Pass it a buffer and its
   *    size. It will put data into the buffer (not neccessarily the full
   *    buffer, in the case of chunked inputs), and return the length of
!  *    the input block. When it is done reading, it will return 0.
   *
   */
  
--- 1080,1087 ----
   * 3. Finally, call get_client_block in a loop. Pass it a buffer and its
   *    size. It will put data into the buffer (not neccessarily the full
   *    buffer, in the case of chunked inputs), and return the length of
!  *    the input block. When it is done reading, it will return 0,
!  *    or -1 if there was an error.
   *
   */
  
***************
*** 1160,1165 ****
--- 1161,1168 ----
  	if (len_to_read > bufsiz)
  	    len_to_read = bufsiz;
  	len_read = bread(r->connection->client, buffer, len_to_read);
+ 	if (len_read <= 0)
+             return len_read;
  	r->remaining -= len_read;
  	return len_read;
      }
***************
*** 1167,1187 ****
      /* Handle chunked reading */
      if (len_to_read == 0) {
  	len_to_read = rd_chunk_size(r->connection->client);
  	if (len_to_read == 0) {
  	    /* Read any footers - the module may not notice them,
  	     * but they're there, and so we read them */
  	    get_mime_headers(r);
  	    return 0;
  	}
      }
!     if (len_to_read > bufsiz) {
! 	r->remaining = len_to_read - bufsiz;
! 	len_to_read = bufsiz;
!     }
!     else
! 	r->remaining = 0;
      
      len_read = bread(r->connection->client, buffer, len_to_read);
      if (r->remaining == 0) {
  	/* Read the newline at the end of the chunk
  	 * (and any other garbage that might be present) */
--- 1170,1193 ----
      /* Handle chunked reading */
      if (len_to_read == 0) {
  	len_to_read = rd_chunk_size(r->connection->client);
+ 	if (len_to_read < 0)
+ 	    return -1;
  	if (len_to_read == 0) {
  	    /* Read any footers - the module may not notice them,
  	     * but they're there, and so we read them */
  	    get_mime_headers(r);
  	    return 0;
  	}
+ 	r->remaining = len_to_read;
      }
! 
!     len_to_read = (r->remaining > bufsiz) ? bufsiz : r->remaining;
      
      len_read = bread(r->connection->client, buffer, len_to_read);
+     if (len_read <= 0)
+         return len_read;
+     r->remaining -= len_read;
+ 
      if (r->remaining == 0) {
  	/* Read the newline at the end of the chunk
  	 * (and any other garbage that might be present) */

Mime
View raw message