NetBSD Problem Report #41988

From sjamaan@frohike.homeunix.org  Thu Sep  3 21:42:17 2009
Return-Path: <sjamaan@frohike.homeunix.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 656FA63B842
	for <gnats-bugs@gnats.NetBSD.org>; Thu,  3 Sep 2009 21:42:17 +0000 (UTC)
Message-Id: <20090903204442.2F2FAF7DFD1@frohike.homeunix.org>
Date: Thu,  3 Sep 2009 22:44:42 +0200 (CEST)
From: Peter.Bex@xs4all.nl
Reply-To: Peter.Bex@xs4all.nl
To: gnats-bugs@gnats.NetBSD.org
Subject: libfetch does not report error on fetchStatURL when using FTP
X-Send-Pr-Version: 3.95

>Number:         41988
>Category:       lib
>Synopsis:       fetchStatURL returns 0 instead of -1 when stating a nonexistant file
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Sep 03 21:45:00 +0000 2009
>Originator:     Peter Bex
>Release:        NetBSD 5.0.1_PATCH
>Organization:
>Environment:


System: NetBSD frohike.homeunix.org 5.0.1_PATCH NetBSD 5.0.1_PATCH (FROHIKE) #0: Tue Aug 11 22:31:56 CEST 2009 sjamaan@frohike.homeunix.org:/usr/obj/sys/arch/amd64/compile/FROHIKE amd64
Architecture: x86_64
Machine: amd64
>Description:
	The manpage for fetch(3) states that fetchStatURL returns -1
	in case of failure.  When stat'ing a file from FTP it returns 0
	when the file does not exist, so client code cannot detect
	absence of a file.

>How-To-Repeat:

Compile and run the following program to compare the difference in output
between a nonexistant HTTP file and a nonexistant FTP file:
---------------------------------------------------
#include <stdio.h>
#include <fetch.h>
int main(void)
{
	struct url_stat st;
	int ret = 0;
	ret = fetchStatURL("ftp://ftp.NetBSD.org/nonexistant", &st, "");
	printf("FetchStatURL for FTP returned %d\n", ret);
	ret = fetchStatURL("http://www.NetBSD.org/nonexistant", &st, "");
	printf("FetchStatURL for HTTP returned %d\n", ret);
	return 0;
}
---------------------------------------------------

Expected output (consistent):
  FetchStatURL for FTP returned -1
  FetchStatURL for HTTP returned -1

Actual output (inconsistent):
  FetchStatURL for FTP returned 0
  FetchStatURL for HTTP returned -1


>Fix:

The fix seems to be quite simple, but I have a feeling these if-checks
are there for a reason.  The returned error code when the file does not
exist is FETCH_UNAVAIL, so the original code simply continues with the
bogus stat structure and then hits the code with the "just a stat"
comment and immediately returns.

Index: ftp.c
===================================================================
RCS file: /cvsroot/src/external/bsd/fetch/dist/libfetch/ftp.c,v
retrieving revision 1.1.1.7
diff -u -r1.1.1.7 ftp.c
--- ftp.c	21 Aug 2009 15:12:52 -0000	1.1.1.7
+++ ftp.c	3 Sep 2009 20:25:45 -0000
@@ -1167,9 +1167,7 @@
 		us = &local_us;

 	/* stat file */
-	if (us && ftp_stat(conn, path, us) == -1
-	    && fetchLastErrCode != FETCH_PROTO
-	    && fetchLastErrCode != FETCH_UNAVAIL) {
+	if (us && ftp_stat(conn, path, us) == -1) {
 		free(path);
 		return (NULL);
 	}

>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.