From nobody  Thu Feb 20 09:45:42 1997
Received: (from nobody@localhost)
          by freefall.freebsd.org (8.8.5/8.8.5) id JAA25998;
          Thu, 20 Feb 1997 09:45:42 -0800 (PST)
Message-Id: <199702201745.JAA25998@freefall.freebsd.org>
Date: Thu, 20 Feb 1997 09:45:42 -0800 (PST)
From: jrj@purdue.edu
To: freebsd-gnats-submit@freebsd.org
Subject: Uninitialized variable may cause "fetch -m" to fail
X-Send-Pr-Version: www-1.0

>Number:         2779
>Category:       bin
>Synopsis:       Uninitialized variable may cause "fetch -m" to fail
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Feb 20 09:50:01 PST 1997
>Closed-Date:    Fri Feb 21 07:01:52 PST 1997
>Last-Modified:  Fri Feb 21 07:04:04 PST 1997
>Originator:     John R. Jackson
>Release:        FreeBSD-current as of 18-Jan-97
>Organization:
Purdue University Computing Center
>Environment:
Paragon OSF/1 galaxy 1.0.4 R1.4.1+031714 paragon
(specially ported version of "fetch")
>Description:
Near line 400 of fetch/main.c, it is possible for "seekloc" to not be
initialized if mirror mode is used and the file does not exist, i.e.
size0 != size or modtime != t.  This causes the ftpGet to do random
things depending on what was on the stack, such as retrieving nothing,
getting only part of the file, etc.
>How-To-Repeat:
Create a version of fetch with initializes seekloc to a "large"
value, then try a mirror mode retrieve of a file that is not local.
You should end up with a zero length file.
>Fix:
I have a suggested patch that I will send via E-mail as a followup,
although it is fairly obvious how to fix this.


>Release-Note:
>Audit-Trail:

From: "John R. Jackson" <jrj@gandalf.cc.purdue.edu>
To: bug-followup@freebsd.org
Cc:  Subject: Re: bin/2779: Uninitialized variable may cause "fetch -m" to fail 
Date: Thu, 20 Feb 1997 13:22:16 EST

 Here is a suggested patch for this problem.  --JJ
 
 *** main.c	Wed Feb 19 17:28:16 1997
 --- main.c	Wed Feb 19 17:43:16 1997
 ***************
 *** 399,404 ****
 --- 399,405 ----
       
       if (!strcmp (outputfile, "-"))
   	restart = 0;
 +     seekloc = 0;
       if (restart || mirror) {
   	f_size (outputfile, &size0, &t);
   	if (mirror && size0 == size && modtime <= t) {
 ***************
 *** 409,419 ****
   	    if (size0 && size0 < size)
   		seekloc = size0;
   	    else
 ! 		seekloc = size0 = 0;
   	}
       }	    
       else if (!restart)
 ! 	seekloc = size0 = 0;
       
       fp = ftpGet (ftp, file_to_get, &seekloc);
       if (fp == NULL)
 --- 410,420 ----
   	    if (size0 && size0 < size)
   		seekloc = size0;
   	    else
 ! 		size0 = 0;
   	}
       }	    
       else if (!restart)
 ! 	size0 = 0;
       
       fp = ftpGet (ftp, file_to_get, &seekloc);
       if (fp == NULL)

From: John-Mark Gurney <jmg@nike.efn.org>
To: "John R. Jackson" <jrj@gandalf.cc.purdue.edu>
Cc: freebsd-bugs@freefall.freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: bin/2779: Uninitialized variable may cause "fetch -m" to fail 
Date: Fri, 21 Feb 1997 00:07:30 -0800 (PST)

 On Thu, 20 Feb 1997, John R. Jackson wrote:
 
 > The following reply was made to PR bin/2779; it has been noted by GNATS.
 > 
 > From: "John R. Jackson" <jrj@gandalf.cc.purdue.edu>
 > To: bug-followup@freebsd.org
 > Cc:  Subject: Re: bin/2779: Uninitialized variable may cause "fetch -m" to fail 
 > Date: Thu, 20 Feb 1997 13:22:16 EST
 > 
 >  Here is a suggested patch for this problem.  --JJ
 >  
 
 [patch deleted]
 
 which version of main.c is this patched against??  I can't seem to find
 the variable size0 any place in the current fetch...  
 
 a quick look at the code in ftp.c, it seems that seekloc is already set to
 0 before it is used...  so it looks like that bug is in your patches...
 and not fetch...  please confirm this...  ttyl..
 
 John-Mark
 
 gurney_j@efn.org
 http://resnet.uoregon.edu/~gurney_j/
 Modem/FAX: (541) 683-6954   (FreeBSD Box)
 
 Live in Peace, destroy Micro$oft, support free software, run FreeBSD (unix)
 

From: "John R. Jackson" <jrj@gandalf.cc.purdue.edu>
To: John-Mark Gurney <gurney_j@resnet.uoregon.edu>
Cc: freebsd-bugs@freefall.freebsd.org, freebsd-gnats-submit@freebsd.org
Subject: Re: bin/2779: Uninitialized variable may cause "fetch -m" to fail 
Date: Fri, 21 Feb 1997 09:20:01 EST

 >which version of main.c is this patched against??  I can't seem to find
 >the variable size0 any place in the current fetch...
 
 It was against FreeBSD-current/src/bin/fetch/main.c as of 18-Jan-97,
 however I just pulled another version (now in usr.bin?) and it has
 obviously been completely rewritten.  I agree the bug is no longer there.
 
 >John-Mark
 
 JJ
State-Changed-From-To: open->closed 
State-Changed-By: jmg 
State-Changed-When: Fri Feb 21 07:01:52 PST 1997 
State-Changed-Why:  
originator confirms bug is fixed in current version of fetch. 
>Unformatted:
