From nobody  Fri Jan 10 21:48:30 1997
Received: (from nobody@localhost)
          by freefall.freebsd.org (8.8.4/8.8.4) id VAA00517;
          Fri, 10 Jan 1997 21:48:30 -0800 (PST)
Message-Id: <199701110548.VAA00517@freefall.freebsd.org>
Date: Fri, 10 Jan 1997 21:48:30 -0800 (PST)
From: hyama@acm.org
To: freebsd-gnats-submit@freebsd.org
Subject: Fetch cannot find the correct boundary between HTTP header and body.
X-Send-Pr-Version: www-1.0

>Number:         2443
>Category:       bin
>Synopsis:       Fetch cannot find the correct boundary between HTTP header and body.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Jan 10 21:50:01 PST 1997
>Closed-Date:    Sun Apr 26 09:43:29 PDT 1998
>Last-Modified:  Sun Apr 26 09:43:39 PDT 1998
>Originator:     Hideki Yamamoto
>Release:        FreeBSD 2.1.5
>Organization:
Oki Electric Industy Co., Ltd.
>Environment:
FreeBSD imagen.pumpkin.kansai.oki.co.jp 2.1.5-RELEASE FreeBSD 2.1.5-RELEASE #2: Thu Jan  9 00:54:59 JST 1997     root@imagen.pumpkin.kansai.oki.co.jp:/usr/src/sys/compile/psm  i386

>Description:

fetch in FreeBSD-2.2-Beta (2.1.5 also) has a problem that it cannot fetch
the following example correctly, because `filter' function in fetch handles
the second `\r\n` as a boundary between the HTTP header and the body.

I hope you will understand the problem and do something for 2.2-RELEASE.
The following patch is an example to finds the first 
separator( `\r\n' or `\n\n' or `\r\r' ).

Thank you for your efforts for FreeBSD.
>How-To-Repeat:
Type the following command:
	% fetch http://www.sun.com/index.html
You can find the fetched `index.html' incomplete.

>Fix:
*** main.c.orig	Thu Jan  9 01:33:22 1997
--- main.c	Sat Jan 11 13:08:02 1997
***************
*** 644,649 ****
--- 644,667 ----
      return pmatch[1].rm_so ? pmatch[1].rm_so : -1;
  }
  
+ unsigned char *
+ min3(unsigned char *x, unsigned char *y, unsigned char *z)
+ {
+   if( (x)<=(y) ){
+     if ((x)<=(z)){
+       return (x); 
+     }else{
+       return (z);
+     }
+   }else{
+     if ((y)<=(z)){
+       return (y);
+     }else{
+       return (z);
+     }
+   } 
+ }
+ 
  void
  filter (unsigned char *p, int len)
  {
***************
*** 682,703 ****
  	    }
  	} else {
  	    unsigned char *t;
  	    /* document begins with a success line. try to get size */
  	    i = match ("content-length:[ \t]*([0-9]+)", s);
  	    if (i > 0)
  		size = atoi (s+i);
  	    /* assume that the file to get begins after an empty line */
! 	    i = match ("(\n\n|\r\n\r\n)", s);
! 	    if (i > 0) {
! 		if (s[i] == '\r')
! 		    t = s+i+4;
! 		else
! 		    t = s+i+2;
! 	    } else {
  		fprintf (stderr, "Can't decode the header!\n");
  		rm ();
  		exit (1);
  	    }
  	    display (size, 0);
  	    n = (s-t)+header_len;
  	    i = fwrite (t, 1, n, file);
--- 700,728 ----
  	    }
  	} else {
  	    unsigned char *t;
+ 	    unsigned char *pp1,*pp2,*pp3,*pp,*ppmin,*plast;
  	    /* document begins with a success line. try to get size */
  	    i = match ("content-length:[ \t]*([0-9]+)", s);
  	    if (i > 0)
  		size = atoi (s+i);
  	    /* assume that the file to get begins after an empty line */
! 	    plast = &s[S];
! 	    pp1 = ( ( pp = strstr (s,"\r\n\r\n")) !=NULL )? pp : plast;
! 	    pp2 = ( ( pp = strstr (s,"\n\n")) !=NULL )? pp :  plast;
! 	    pp3 = ( ( pp = strstr (s,"\r\r")) !=NULL )? pp :  plast;
! 	    ppmin = min3( pp1, pp2, pp3 );
! 	    
! 	    if( ppmin == plast ) {
  		fprintf (stderr, "Can't decode the header!\n");
  		rm ();
  		exit (1);
  	    }
+ 	    if( pp1 == ppmin )
+ 		t = pp1+4;
+ 	    else if(  pp2 == ppmin )
+ 		t = pp2+2;
+ 	    else
+ 		t = pp3+2;
  	    display (size, 0);
  	    n = (s-t)+header_len;
  	    i = fwrite (t, 1, n, file);
>Release-Note:
>Audit-Trail:

From: Bill Fenner <fenner@parc.xerox.com>
To: freebsd-gnats-submit@freebsd.org, hyama@acm.org
Cc:  Subject: Re: bin/2443: Fetch cannot find the correct boundary between HTTP header and body.
Date: Fri, 28 Feb 1997 09:31:59 PST

 I cannot replicate this with either the fetch from 2.1.6 or the new
 fetch in 2.2 .  Are you still having this problem?  Can you supply
 another URL that you're having problems with, since
 http://www.sun.com/index.html doesn't fail?
 
 Thanks,
   Bill
State-Changed-From-To: open->closed 
State-Changed-By: phk 
State-Changed-When: Sun Apr 26 09:43:29 PDT 1998 
State-Changed-Why:  
timed out 
>Unformatted:
