List Info

Thread: fcgi-0011: Fix to fixup_padding




fcgi-0011: Fix to fixup_padding
user name
2006-01-07 22:52:36
Hi,

This is a patch against the latest svn revision, fixing the
fixup_padding. This is the original implementation (was
named
fixup_params function). Although works simpler, the alo's
version was
not quite correct by leaving paddingLength field of the last
FCGI record
to be blank (0x00) while this field must be filled with the
number of
bytes of the pad. If this is not filled, then the server
would take the
pad as the start of the next record, while it is an invalid
record
(starting with 0x00), hence, the server would drop the
connection.

This patch traverses the buffer and find all the records
inside and fill
the last record's paddingLength with the pad size (if
applicable).
_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
fcgi-0011: Fix to fixup_padding
user name
2006-01-08 09:10:09
Hi Mohammad,

 > +    byte += 2;
 > +    if (*byte == (char) 0xFF)
 > +      *byte = crafted_id [1];
 > +    byte ++;
 > +    if (*byte == (char) 0xFF)
 > +      *byte = crafted_id [0];
 > +    byte ++;

   I haven't applied this chunk. Now it sets the ID number
on-the-fly,
   so it doesn't need to do it any longer.

 > +    length = (*byte << 8);
 > +    byte ++;
 > +    length |= *byte;
 > +    byte ++;
 > +    length += *byte;
 >
 > +    last_pad = byte;
 > +    byte ++;
 > +    byte += (length + 1);
 > +  }
 > +
 > +  if ((buf->len % 8) != 0)
 > +  {
 > +    pad = 8 - (buf->len % 8);
 > +    cherokee_buffer_ensure_size (buf, buf->len +
pad);
 > +
 > +    *last_pad = pad;
 > +    cherokee_buffer_add (buf, padding, pad);
 > +  }
 > +
 > +}

   It would be wonderful to be able to localize the last
packet rather
   than parsing all the buffer.. I will take a look at it.

   Thanks Mohammad!

-- 
Greetings, alo.
http://www.alobbs.com
_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
fcgi-0011: Fix to fixup_padding
user name
2006-01-10 10:53:36
Hi Mohammad,

 >   It would be wonderful to be able to localize the
last packet rather
 >   than parsing all the buffer.. I will take a look at
it.

   I have committed this change, and it seems to be
working..

     http://www.0x5
0.org/bugs/changeset/128

   so, we don't need to parse the full buffer any longer


-- 
Greetings, alo.
_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
fcgi-0011: Fix to fixup_padding
user name
2006-01-10 11:09:01
Pada hari Selasa, tanggal 10/01/2006 pukul 11:53 +0100,
Alvaro Lopez
Ortega menulis:
>    I have committed this change, and it seems to be
working..
> 
>      http://www.0x5
0.org/bugs/changeset/128
> 
>    so, we don't need to parse the full buffer any
longer 

Sweet, I'll try it later.


_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
fcgi-0011: Fix to fixup_padding
user name
2006-01-12 21:53:06
Pada hari Selasa, tanggal 10/01/2006 pukul 11:53 +0100,
Alvaro Lopez
Ortega menulis:
> Hi Mohammad,
> 
>  >   It would be wonderful to be able to localize
the last packet rather
>  >   than parsing all the buffer.. I will take a
look at it.
> 
>    I have committed this change, and it seems to be
working..
> 
>      http://www.0x5
0.org/bugs/changeset/128
> 
>    so, we don't need to parse the full buffer any
longer 
> 

I found sometimes the write_buffer is changed somewhere so
the
last_header is no longer valid. So even the pad is appended
but the pad
length is not filled in paddingLength. With this patch now
it will work
for "ab -c 1 -n 100". 

Using -c more than 1 or -n more than 100 is still failing,
with another
cause of problem which is being investigated now.
_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
fcgi-0011: Fix to fixup_padding
user name
2006-01-14 16:31:16
Mohammad DAMT wrote:

 >> >   It would be wonderful to be able to
localize the last packet
 >> >   rather than parsing all the buffer.. I will
take a look at it.
 >>
 >>   I have committed this change, and it seems to be
working..
 >>
 >>     http://www.0x5
0.org/bugs/changeset/128
 >>
 >>   so, we don't need to parse the full buffer any
longer 
 >>
 >
 > I found sometimes the write_buffer is changed
somewhere so the
 > last_header is no longer valid. So even the pad is
appended but the
 > pad length is not filled in paddingLength. With this
patch now it
 > will work for "ab -c 1 -n 100".
 >
 > Using -c more than 1 or -n more than 100 is still
failing, with
 > another cause of problem which is being investigated
now.

   Mohammad, I have been working on this for a while, and
you were
   right, something weird was happening with the buffer.

   I'm about to commit something similar to the following
patch, but
   without the print_header() function (it was just for
debugging
   purposes, there is no point in keeping it there).

   The patch also simplifies the add_env_pair_with_id*() a
little bit,
   and fixes the incorrect pointer you detected: it prints
headers like
   this one keeping the FastCGI connection open:

=====
header->version         = 1
header->type            = 4
header->requestIdB1     = 0
header->requestIdB0     = 1
header->contentLengthB1 = 0
header->contentLengthB0 = 22
header->paddingLength   = 5
=====



Index: cherokee/handler_fastcgi.c
============================================================
=======
--- cherokee/handler_fastcgi.c	(revision 132)
+++ cherokee/handler_fastcgi.c	(working copy)
 -151,82
+151,51 
  }


-#if 0
-
  static void
-fixup_padding (cherokee_buffer_t *buf, cuint_t id)
+print_header (FCGI_Header *header)
  {
-	char *byte, *end, *last_pad;
-	char  padding [8] = {0, 0, 0, 0, 0, 0, 0, 0};
-	int   length;
-	int   crafted_id [2];
-	int   pad;
-
-	if (buf->len == 0)
-		return;
-
-	if ((buf->len % 8) == 0)
-		return;
-
-	byte = (char*) buf->buf;
-	end  = buf->buf + buf->len;
-
-	crafted_id [0] = (cuchar_t) id;
-	crafted_id [1] = (cuchar_t) (id >> 8) & 0xff;
-
-	while (byte < end) {
-		byte += 4;
-
-		length = (*byte << 8);
-		byte ++;
-		length |= *byte;
-		byte ++;
-		length += *byte;
-
-		last_pad = byte;
-		byte ++;
-		byte += (length + 1);
-	}
-
-	pad = 8 - (buf->len % 8);
-	cherokee_buffer_ensure_size (buf, buf->len + pad);
-
-	*last_pad = pad;
-	cherokee_buffer_add (buf, padding, pad);
+	printf ("header->version         = %dn",
header->version);
+	printf ("header->type            = %dn",
header->type);
+	printf ("header->requestIdB1     = %dn",
header->requestIdB1);
+	printf ("header->requestIdB0     = %dn",
header->requestIdB0);
+	printf ("header->contentLengthB1 = %dn",
header->contentLengthB1);
+	printf ("header->contentLengthB0 = %dn",
header->contentLengthB0);
+	printf ("header->paddingLength   = %dn",
header->paddingLength);
+	printf ("n");
  }

-#endif

  static void
-fixup_padding (cherokee_buffer_t *buf, cuint_t id,
FCGI_Header *last_header)
+fixup_padding (cherokee_buffer_t *buf, cuint_t id, cuint_t
last_header_offset)
  {
-	cuint_t                  rest;
-	cuint_t                  pad;
-	char                     padding[8] = {0, 0, 0, 0, 0, 0,
0, 0};
+	cuint_t      rest;
+	cuint_t      pad;
+	char         padding[8] = {0, 0, 0, 0, 0, 0, 0, 0};
+	FCGI_Header *last_header;

  	if (buf->len <= 0)
  		return;

-	rest    = buf->len % 8;
-	pad     = 8 - rest;
+	last_header = (FCGI_Header *) (buf->buf +
last_header_offset);
+	rest        = buf->len % 8;
+	pad         = 8 - rest;

  	if (rest == 0)
  		return;

  	last_header->paddingLength = pad;

+	print_header (last_header);
+
  	cherokee_buffer_ensure_size (buf, buf->len + pad);
  	cherokee_buffer_add (buf, padding, pad);
  }


-
-
  static void
-add_env_pair_with_id_and_header_ref (cherokee_buffer_t
*buf, cuint_t id,
-				     char *key, int key_len,
-				     char *val, int val_len,
-				     FCGI_Header **req_ref)
+add_env_pair_with_id (cherokee_buffer_t *buf, cuint_t id,
+		      char *key, int key_len,
+		      char *val, int val_len)
  {
  	FCGI_BeginRequestRecord  request;
  	int                      len;
 -237,10
+206,7 

  	fcgi_build_header (&request.header, FCGI_PARAMS, id,
len, 0);

-	if (req_ref != NULL)
-		*req_ref = (FCGI_Header *) buf->buf + buf->len;
-
-	cherokee_buffer_ensure_size (buf, buf->len + key_len +
val_len + sizeof(FCGI_Header));
+	cherokee_buffer_ensure_size (buf, buf->len +
sizeof(FCGI_Header) + key_len + val_len);
  	cherokee_buffer_add (buf, (void *)&request.header,
sizeof(FCGI_Header));

  	if (key_len <= 127) {
 -267,15
+233,6 


  static void
-add_env_pair_with_id (cherokee_buffer_t *buf, cuint_t id,
-		      char *key, int key_len,
-		      char *val, int val_len)
-{
-	add_env_pair_with_id_and_header_ref (buf, id, key,
key_len, val, val_len, NULL);
-}
-
-
-static void
  add_env_pair_2_params (void *params[2],
  		       char *key, int key_len,
  		       char *val, int val_len)
 -291,7
+248,7 


  static void
-add_more_env (cherokee_handler_fastcgi_t *fcgi,
cherokee_buffer_t *buf, FCGI_Header **last_header)
+add_more_env (cherokee_handler_fastcgi_t *fcgi,
cherokee_buffer_t *buf, cuint_t *last_header_offset)
  {
  	cherokee_connection_t   *conn;
  	cherokee_buffer_t        buffer = CHEROKEE_BUF_INIT;
 -349,11
+306,16 
  			      FCGI_PATH_TRANSLATED_VAR, sizeof
(FCGI_PATH_TRANSLATED_VAR) - 1,
  			      buffer.buf, buffer.len);

-	add_env_pair_with_id_and_header_ref (buf, fcgi->id,
-					     FCGI_SCRIPT_NAME_VAR, sizeof
(FCGI_SCRIPT_NAME_VAR) - 1,
-					     conn->request.buf, conn->request.len,
-					     last_header);

+	/* The last package has a special treatment, we need
+	 * to now where the header begins to set the right padding
+	 */
+	*last_header_offset = buf->len;
+
+	add_env_pair_with_id (buf, fcgi->id,
+			      FCGI_SCRIPT_NAME_VAR, sizeof
(FCGI_SCRIPT_NAME_VAR) - 1,
+			      conn->request.buf, conn->request.len);
+
  	cherokee_buffer_mrproper (&buffer);
  }

 -364,10
+326,10 
  	ret_t                    ret;
  	FCGI_BeginRequestRecord  request;
  	void                    *params[2];
+	cuint_t                  last_header_offset;
  	cherokee_buffer_t        tmp         = CHEROKEE_BUF_INIT;
  	cherokee_buffer_t        write_tmp   = CHEROKEE_BUF_INIT;
  	cherokee_connection_t   *conn        = HANDLER_CONN
(fcgi);;
-	FCGI_Header             *last_header = NULL;

  	cherokee_connection_parse_args (conn);

 -388,8
+350,8 
  	ret = cherokee_cgi_build_basic_env (conn,
(cherokee_cgi_set_env_pair_t) add_env_pair_2_params,
&tmp, params);
  	if (unlikely (ret != ret_ok)) return ret;

-	add_more_env (fcgi, &write_tmp, &last_header);
-	fixup_padding (&write_tmp, fcgi->id, last_header);
+	add_more_env (fcgi, &write_tmp,
&last_header_offset);
+	fixup_padding (&write_tmp, fcgi->id,
last_header_offset);
  	
  	cherokee_buffer_add_buffer (&fcgi->write_buffer,
&write_tmp);



-- 
Greetings, alo.
http://www.alobbs.com
_______________________________________________
Cherokee mailing list
Cherokeelists.alobbs.com
http://www.alobbs.com/cgi-bin/mailman/listinfo/cherokee
[1-6]

about | contact  Other archives ( Real Estate discussion Medical topics )