perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Mitchell <da...@fdgroup.co.uk>
Subject Re: new multipart_buffer patch for libapreq
Date Wed, 05 Jul 2000 12:03:15 GMT
joe@sunstarsys.com wrote

> The patch I posted yesterday has a problem 
> dealing with client disconnects - your server will hang if 
> the upload is interrupted )!
> 
> This new patch should be ok. 

Your patch uses memmem(), which isn't available on some OSes (eg Solaris).
Also, the linux manpage warns against using memmem() because it was broken
in some earlier versions of libc.

I've rolled my own version, and it seems to work okay (famous last words).
Here's a patch for your patch. (I'm not promising this is the greatest
re-implementation of memmem() the world has ever seen.)

Regards,
Dave M.



*** libapreq-0.31/c/multipart_buffer.c.FCS	Wed Jul  5 11:17:07 2000
--- libapreq-0.31/c/multipart_buffer.c	Wed Jul  5 11:22:26 2000
***************
*** 71,76 ****
--- 71,97 ----
  
  #define DEBUG 0 /* 0 = off, 1 = noisy */
  
+ 
+ /* return pointer to first occurance of s in buf */
+ 
+ void *my_memmem(const void *buf, size_t buf_len, const void *s, size_t s_len)
+ {
+ 	void *p, *q;
+ 	size_t n;
+ 	unsigned int c;
+ 
+ 	if (s_len > buf_len || s_len == 0 || buf_len == 0) return NULL;
+ 	p = (void *) buf;
+ 	c = *((unsigned char *) s);
+ 	for (n = buf_len - s_len + 1; n > 0; n--, p++) {
+ 		q = memchr(p,c,n);
+ 		if (!q) return NULL;
+ 		n -= (q-p);
+ 		p = q;
+ 		if (memcmp(p,s,s_len) == 0) return p;
+ 	}
+ 	return NULL;
+ }
  static char *my_join(pool *p, char *one, int lenone, char *two, int lentwo)
  {
      char *res;
***************
*** 200,206 ****
  
      /* Find the boundary in the buffer (it may not be there). */
  
!     if (mem = memmem(self->buffer + self->buffer_off, self->buffer_len,
  		     self->boundary, self->boundary_length) )
      {
   	 start = mem - ( self->buffer + self->buffer_off );
--- 221,227 ----
  
      /* Find the boundary in the buffer (it may not be there). */
  
!     if (mem = my_memmem(self->buffer + self->buffer_off, self->buffer_len,
  		     self->boundary, self->boundary_length) )
      {
   	 start = mem - ( self->buffer + self->buffer_off );
***************
*** 294,300 ****
  
  	multipart_buffer_fill(self, bytes);
  
! 	if (mem = memmem(self->buffer + self->buffer_off, self->buffer_len, 
  			  CRLF_CRLF, 4)) 
  	{
  	    /* have final header 'fragment' in the buffer */
--- 315,321 ----
  
  	multipart_buffer_fill(self, bytes);
  
! 	if (mem = my_memmem(self->buffer + self->buffer_off, self->buffer_len, 
  			  CRLF_CRLF, 4)) 
  	{
  	    /* have final header 'fragment' in the buffer */
***************
*** 416,418 ****
--- 437,440 ----
  
      return self;
  }
+ 




Mime
View raw message