From alane@wwweasel.geeksrus.net  Tue Sep 24 10:11:40 2002
Return-Path: <alane@wwweasel.geeksrus.net>
Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9C84D37B406
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Sep 2002 10:11:40 -0700 (PDT)
Received: from wwweasel.geeksrus.net (wwweasel.geeksrus.net [64.8.210.226])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 646D143E75
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 24 Sep 2002 10:11:39 -0700 (PDT)
	(envelope-from alane@wwweasel.geeksrus.net)
Received: from wwweasel.geeksrus.net (smmsp@localhost [127.0.0.1])
	by wwweasel.geeksrus.net (8.12.6/8.12.6) with ESMTP id g8OHB8HL083284;
	Tue, 24 Sep 2002 13:11:08 -0400 (EDT)
	(envelope-from alane@wwweasel.geeksrus.net)
Received: (from root@localhost)
	by wwweasel.geeksrus.net (8.12.6/8.12.6/Submit) id g8OHB646083266;
	Tue, 24 Sep 2002 13:11:06 -0400 (EDT)
	(envelope-from alane)
Message-Id: <200209241711.g8OHB646083266@wwweasel.geeksrus.net>
Date: Tue, 24 Sep 2002 13:11:06 -0400 (EDT)
From: Alan Eldridge <ports@geeksrus.net>
Reply-To: Alan Eldridge <ports@geeksrus.net>
To: FreeBSD-gnats-submit@freebsd.org
Cc: kris@obsecurity.org
Subject: fetch: -s fails if -4 or possibly other options given; inappropraite exit code if file does not exist on server
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         43337
>Category:       bin
>Synopsis:       [patch] fetch(1) -s fails if -4 or possibly other options given; inappropraite exit code if file does not exist on server
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    des
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 24 10:20:02 PDT 2002
>Closed-Date:    
>Last-Modified:  Sat Jan 09 12:28:49 UTC 2010
>Originator:     Alan Eldridge
>Release:        FreeBSD 4.7-RC i386
>Organization:
Geeksrus.NET
>Environment:
System: FreeBSD wwweasel.geeksrus.net 4.7-RC FreeBSD 4.7-RC #0: Sat Sep 21 10:38:39 EDT 2002 root@wwweasel.geeksrus.net:/usr/obj/usr/src/sys/WWWEASEL i386

>Description:

Kris, I Cc'd you in hopes you would know who to route this to. Thanks. Feel
free to edit-pr your name off the Cc list.

-s option to fetch is supposed to show size of remote file. it prints nothing
if the -4 option is also used, even when the file exists and the -4 option can be used to fetch it.

If the file does not exist, fetch still returns an exit code of 0, which is
inappropriate for applications trying to determine if the file exists on the
server or not.

Additionally, the value "Unknown" is not appropriate for when the file is not
there. How is one to distinguish between file-not-present and
server-won't-tell-me-size conditions, especially using http: urls?


>How-To-Repeat:

[root@wwweasel:~]# fetch -v -v -v -s -4 -p -T 60 ftp://snapshots.jp.FreeBSD.org/pub/FreeBSD/snapshots/i386/ISO-IMAGES/4.7-RC-20020918-JPSNAP.iso
---> snapshots.jp.FreeBSD.org:21
looking up snapshots.jp.FreeBSD.org
[root@wwweasel:~]# fetch -s -4 -p ftp://snapshots.jp.FreeBSD.org/pub/FreeBSD/snapshots/i386/ISO-IMAGES/4.7-RC-20020918-JPSNAP.iso
[root@wwweasel:~]# fetch -s -p ftp://snapshots.jp.FreeBSD.org/pub/FreeBSD/snapshots/i386/ISO-IMAGES/4.7-RC-20020918-JPSNAP.iso
173539328
[root@wwweasel:~]# fetch -s -p ftp://snapshots.jp.FreeBSD.org/pub/FreeBSD/snapshots/i386/ISO-IMAGES/4.7-RC-20030918-JPSNAP.iso
Unknown
[root@wwweasel:~]# echo $?
0

>Fix:

Don't know. Have not investigated. However, since these are three distinct
problems, it probably impacts more than one area of the code, and possibly
libfetch as well as the fetch program itself.


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: kris 
Responsible-Changed-When: Sat Jul 12 18:07:16 PDT 2003 
Responsible-Changed-Why:  
Assign to fetch maintainer 

http://www.freebsd.org/cgi/query-pr.cgi?pr=43337 

From: "R. Tyler Ballance" <tyler@monkeypox.org>
To: bug-followup@FreeBSD.org, ports@geeksrus.net
Cc:  
Subject: Re: bin/43337: fetch(1) -s fails if -4 or possibly other options
 given; inappropraite exit code if file does not exist on server
Date: Sat, 9 Jan 2010 03:46:12 -0800

 --ftEhullJWpWg/VHq
 Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy"
 Content-Disposition: inline
 
 
 --KsGdsel6WgEHnImy
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 
 I was trolling through old PRs and came across this one which I've fixed in=
  the
 attached patch.=20
 
 
 Cheers,
 -R. Tyler Ballance
 --------------------------------------
  Jabber: rtyler@jabber.org
  GitHub: http://github.com/rtyler
 Twitter: http://twitter.com/agentdero
    Blog: http://unethicalblogger.com
 
 
 --KsGdsel6WgEHnImy
 Content-Type: text/x-patch; charset=us-ascii
 Content-Disposition: attachment; filename="pr43337.patch"
 
 diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
 index 7553bd8..c85b914 100644
 --- a/usr.bin/fetch/fetch.c
 +++ b/usr.bin/fetch/fetch.c
 @@ -415,10 +415,18 @@ fetch(char *URL, const char *path)
                         warnx("%s", fetchLastErrString);
                         goto failure;
                 }
 -               if (us.size == -1)
 -                       printf("Unknown\n");
 -               else
 +               if (us.size == -1) {
 +                       if (fetchLastErrCode) {
 +                               printf("%s\n", fetchLastErrString);
 +                       }
 +                       else {
 +                               printf("Unknown\n");
 +                       }
 +                       goto failure;
 +               }
 +               else {
                         printf("%jd\n", (intmax_t)us.size);
 +               }
                 goto success;
         }
 
 --KsGdsel6WgEHnImy--
 
 --ftEhullJWpWg/VHq
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.12 (GNU/Linux)
 
 iEYEARECAAYFAktIbIQACgkQFCbH3D9R4W/Y/gCfX80Z8Ao/6N2AiBgMm4rvOYoW
 91IAn3Kj3tbNsIsKpJnBbfP4/xV/PFmN
 =TZdU
 -----END PGP SIGNATURE-----
 
 --ftEhullJWpWg/VHq--

From: "R. Tyler Ballance" <tyler@monkeypox.org>
To: bug-followup@FreeBSD.org, ports@geeksrus.net
Cc:  
Subject: Re: bin/43337: fetch(1) -s fails if -4 or possibly other options
 given; inappropraite exit code if file does not exist on server
Date: Sat, 9 Jan 2010 03:46:12 -0800

 --ftEhullJWpWg/VHq
 Content-Type: multipart/mixed; boundary="KsGdsel6WgEHnImy"
 Content-Disposition: inline
 
 
 --KsGdsel6WgEHnImy
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 
 I was trolling through old PRs and came across this one which I've fixed in=
  the
 attached patch.=20
 
 
 Cheers,
 -R. Tyler Ballance
 --------------------------------------
  Jabber: rtyler@jabber.org
  GitHub: http://github.com/rtyler
 Twitter: http://twitter.com/agentdero
    Blog: http://unethicalblogger.com
 
 
 --KsGdsel6WgEHnImy
 Content-Type: text/x-patch; charset=us-ascii
 Content-Disposition: attachment; filename="pr43337.patch"
 
 diff --git a/usr.bin/fetch/fetch.c b/usr.bin/fetch/fetch.c
 index 7553bd8..c85b914 100644
 --- a/usr.bin/fetch/fetch.c
 +++ b/usr.bin/fetch/fetch.c
 @@ -415,10 +415,18 @@ fetch(char *URL, const char *path)
                         warnx("%s", fetchLastErrString);
                         goto failure;
                 }
 -               if (us.size == -1)
 -                       printf("Unknown\n");
 -               else
 +               if (us.size == -1) {
 +                       if (fetchLastErrCode) {
 +                               printf("%s\n", fetchLastErrString);
 +                       }
 +                       else {
 +                               printf("Unknown\n");
 +                       }
 +                       goto failure;
 +               }
 +               else {
                         printf("%jd\n", (intmax_t)us.size);
 +               }
                 goto success;
         }
 
 --KsGdsel6WgEHnImy--
 
 --ftEhullJWpWg/VHq
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.12 (GNU/Linux)
 
 iEYEARECAAYFAktIbIQACgkQFCbH3D9R4W/Y/gCfX80Z8Ao/6N2AiBgMm4rvOYoW
 91IAn3Kj3tbNsIsKpJnBbfP4/xV/PFmN
 =TZdU
 -----END PGP SIGNATURE-----
 
 --ftEhullJWpWg/VHq--
>Unformatted:
