NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/41988: libfetch does not report error on fetchStatURL when using FTP

>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
System: NetBSD 5.0.1_PATCH NetBSD 5.0.1_PATCH (FROHIKE) 
#0: Tue Aug 11 22:31:56 CEST 2009 
Architecture: x86_64
Machine: amd64
        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.


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("";, &st, "");
        printf("FetchStatURL for FTP returned %d\n", ret);
        ret = fetchStatURL("";, &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


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
diff -u -r1.1.1.7 ftp.c
--- ftp.c       21 Aug 2009 15:12:52 -0000
+++ 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) {
                return (NULL);


Home | Main Index | Thread Index | Old Index