I reread the changes made to `shttpd' and I realized that there is an error in reading data from the client.

I corrected the mistake and I created 2 new patch to be applied to amended code (the code amended by the previous patch). To apply patches simple copy files into source directory, cd to it and type:

   patch -u < ./shttpd.c.patch
   patch -u < ./defs.h.patch

However I think the support is not complete and need some tests.

Thank's.

Christian.
--- ../../shttpd-1.42-wip/src/defs.h	2008-11-09 10:36:51.000000000 +0100
+++ ./defs.h	2008-11-20 14:19:17.000000000 +0100
@@ -184,7 +184,7 @@
 #define	FLAG_DONT_CLOSE		32
 #define	FLAG_ALWAYS_READY	64		/* File, dir, user_func	*/
 #define	FLAG_SUSPEND		128
-#define FLAG_100_CONTINUE       256             /* 100-continue multipart request */
+  //#define FLAG_100_CONTINUE       256             /* 100-continue multipart request */
 };
 
 struct worker {
--- ../../shttpd-1.42-wip/src/shttpd.c	2008-11-10 13:15:42.000000000 +0100
+++ ./shttpd.c	2008-11-20 14:22:12.000000000 +0100
@@ -679,15 +679,24 @@
 	      {
 		_shttpd_send_server_error(c, 501, "Bad method ");
 	      } 
-	    else 
+	    else /* check for Expect: 100-cntinue */ 
 	      {
 		if(c->ch.expect.v_vec.ptr != NULL && 
 		   strncmp(c->ch.expect.v_vec.ptr, "100-continue", 12) == 0)
 		  {
+		    /* We have `Expect: 100-continue\r\n' */
 		    int how_to_read;
+		    int rbyte = 0, tot = 0;
+
+		    DBG(("FOUND `Expect: 100-continue' with `%s' method.",
+			 _shttpd_known_http_methods[c->method]));
 
 		    if((how_to_read = c->ch.cl.v_int) == 0)
-		      _shttpd_send_server_error(c, 411, "Length Required");
+		      {
+			DBG(("\tMissing `Content-Lenght'");
+			    _shttpd_send_server_error(c, 411, "Length Required"));
+			return;
+		      }
 		    else
 		      {
 			io_clear(&c->loc.io);
@@ -701,45 +710,62 @@
 			_shttpd_stop_stream(&c->loc);
 			write_stream(&c->loc, &c->rem);
 			
-			/* "100 Continue" response was sent */
-
+			DBG(("Response `HTTP/1.1 100 Continue\\r\\n\\r\\n' was sent."));
 
+			/* "100 Continue" response was sent */
+			
+			/* Read data and pass it to CGI */
 			if(c->rem.io.size - c->rem.io.total <= how_to_read)
 			  {
 			    /* We need more space in the read buffer so we realloc it */
 			    unsigned int nsize;
 			    char *nbuf;
-	
+			    
+			    DBG(("\tRead buffer must be realloc'd."));
 			    nsize = 
 			      (c->rem.io.size - c->rem.io.total) + how_to_read;
 			    
 			    nbuf = realloc(c->rem.io.buf, nsize);
 
-			    if(nbuf == NULL)
-			       _shttpd_send_server_error(c, 500, "Internal Error"); 
+			    if(nbuf != NULL)
+			      {
+				c->rem.io.buf = nbuf;
+				c->rem.io.size = nsize;
+				DBG(("\tRead buffer reallocated succesfully."));
+			      }
+			    else
+			      {
+				/* Memory allocation failure */
+				DBG(("\tDynami memory allocation error."));
+				_shttpd_send_server_error(c, 500, "Internal Error"); 
+				/* STOP PROCESSING */
+				return;
+			      }
 			  }
 
 			/* Read remaining data from client */
-
-			do 
+			tot = 0;
+			rbyte = 0;
+			
+			DBG(("\tReading data:"));
+			while(tot < how_to_read)
 			  {
-			    int rbyte = 0, tot = 0;
-			    while(rbyte < how_to_read)
-			      {
-				rbyte = read(c->rem.chan.sock, 
-					     c->rem.io.buf + c->rem.io.total, 
-					     how_to_read);
-				if(rbyte <= 0)
-				  break; /* Lost data ? */
-				tot += rbyte;
-				printf("%s:%s:%d: READING 100-continue. Buff: [%s]\n",
-				       __FILE__, __FUNCTION__, __LINE__, 
-				       c->rem.io.buf + c->rem.io.total);
-			      }
+			    rbyte = read
+			      (c->rem.chan.sock, c->rem.io.buf + c->rem.io.total, how_to_read);
+
+			    if(rbyte <= 0)
+			      break; /* Lost data ? */
+			    
+			    tot += rbyte;
+
+			    DBG(("\t\t[%s]\n", c->rem.io.buf + c->rem.io.total + tot));
 			  }
-			while(0);
+			c->rem.io.total += tot;
+			DBG(("\tEnd reading."));
+			/* Now we have all data into c->io.buf */
 			
 		      } /* else */
+		    
 		  } /* 100-continue */
 		
 		if((_shttpd_run_cgi(c, path)) == -1) 
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
shttpd-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/shttpd-general

Reply via email to