From nobody@FreeBSD.org  Thu Jan  6 23:23:40 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 42F351065670
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Jan 2011 23:23:40 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (unknown [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 321B48FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  6 Jan 2011 23:23:40 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id p06NNdaj041458
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 6 Jan 2011 23:23:39 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id p06NNdXi041455;
	Thu, 6 Jan 2011 23:23:39 GMT
	(envelope-from nobody)
Message-Id: <201101062323.p06NNdXi041455@red.freebsd.org>
Date: Thu, 6 Jan 2011 23:23:39 GMT
From: Aleksey <rndfax@yandex.ru>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [libfetch] in ftp_request: closing of the connection happens too earlier
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         153748
>Category:       kern
>Synopsis:       [libfetch] [patch] in ftp_request: closing of the connection happens too earlier
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    des
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 06 23:30:05 UTC 2011
>Closed-Date:    Fri May 13 06:54:33 UTC 2011
>Last-Modified:  Fri May 13 06:54:33 UTC 2011
>Originator:     Aleksey
>Release:        
>Organization:
>Environment:
FreeBSD r2d2.homenet 8.1-STABLE FreeBSD 8.1-STABLE #7 r215308: Sun Nov 14 21:31:16 UTC 2010     admin@r2d2.homenet:/usr/obj/usr/src/sys/kernel  i386
>Description:
libfetch/ftp.c - ftp_request sends command QUIT when it is called only for stat. Therefore, after calling fetchStatURL(..) it's not possible to work with this ftp-cached_connection, because the server closes this connection.
>How-To-Repeat:
#include <sys/param.h>
#include <stdio.h>
#include <fetch.h>

int
main()
{
    FILE *ftp;
    const char *url = "ftp://ftp2.freebsd.org/pub/FreeBSD/ports/i386/packages-8-stable/UPDATING";
    struct url_stat f_stat;

    if (fetchStatURL(url, &f_stat, "") == -1) {
        printf("fetchStatURL error\n");
        return -1;
    }
    
    if ((ftp = fetchGetURL(url, "")) == NULL) {
        printf("fetchGetURL error\n");
        return -1;
    }
    fclose(ftp);
    return 0;
}


this code produces "Broken pipe".
>Fix:
To fix this problem, don't send QUIT in the ftp_request(..), just decrease the count reference to this cached connection. Patch attached.

Patch attached with submission follows:

--- /usr/src/lib/libfetch/ftp.c	2011-01-06 03:00:01.000000000 +0000
+++ /usr/src/lib/libfetch/ftp.c	2011-01-06 03:00:27.000000000 +0000
@@ -1132,7 +1132,7 @@
 
 	/* just a stat */
 	if (strcmp(op, "STAT") == 0) {
-		ftp_disconnect(conn);
+		fetch_close(conn);
 		return (FILE *)1; /* bogus return value */
 	}
 	if (strcmp(op, "STOR") == 0 || strcmp(op, "APPE") == 0)


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->des 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Wed Jan 12 18:01:30 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer.  OTOH maintainer says he has a different patch in 
the works. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/153748: commit references a PR
Date: Mon, 17 Jan 2011 17:25:52 +0000 (UTC)

 Author: des
 Date: Mon Jan 17 17:25:46 2011
 New Revision: 217505
 URL: http://svn.freebsd.org/changeset/base/217505
 
 Log:
   Fix a bug related to connection caching which could cause a crash after
   a STAT command.
   
   PR:		kern/153748 (different patch)
   Submitted by:	Mark Johnston <markjdb@gmail.com>
   MFC after:	2 weeks
 
 Modified:
   head/lib/libfetch/ftp.c
 
 Modified: head/lib/libfetch/ftp.c
 ==============================================================================
 --- head/lib/libfetch/ftp.c	Mon Jan 17 17:23:59 2011	(r217504)
 +++ head/lib/libfetch/ftp.c	Mon Jan 17 17:25:46 2011	(r217505)
 @@ -1132,6 +1132,7 @@ ftp_request(struct url *url, const char 
  
  	/* just a stat */
  	if (strcmp(op, "STAT") == 0) {
 +		--conn->ref;
  		ftp_disconnect(conn);
  		return (FILE *)1; /* bogus return value */
  	}
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: eadler 
State-Changed-When: Sat Feb 26 21:15:25 EST 2011 
State-Changed-Why:  
In head already 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153748 
State-Changed-From-To: patched->closed 
State-Changed-By: des 
State-Changed-When: Fri May 13 06:54:32 UTC 2011 
State-Changed-Why:  
fixed in head, 8 and 7 

http://www.freebsd.org/cgi/query-pr.cgi?pr=153748 
>Unformatted:
