From nobody@FreeBSD.org  Fri Aug 24 12:56:07 2001
Return-Path: <nobody@FreeBSD.org>
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by hub.freebsd.org (Postfix) with ESMTP id EC2BC37B405
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 24 Aug 2001 12:56:06 -0700 (PDT)
	(envelope-from nobody@FreeBSD.org)
Received: (from nobody@localhost)
	by freefall.freebsd.org (8.11.4/8.11.4) id f7OJu6b08856;
	Fri, 24 Aug 2001 12:56:06 -0700 (PDT)
	(envelope-from nobody)
Message-Id: <200108241956.f7OJu6b08856@freefall.freebsd.org>
Date: Fri, 24 Aug 2001 12:56:06 -0700 (PDT)
From: Joseph Mallett <jmallett@xMach.org>
To: freebsd-gnats-submit@FreeBSD.org
Subject: ftp(1)'s fetch.c could easily have vhost support
X-Send-Pr-Version: www-1.0

>Number:         30054
>Category:       bin
>Synopsis:       ftp(1)'s fetch.c could easily have vhost support
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    mike
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 24 13:00:00 PDT 2001
>Closed-Date:    Mon Feb 25 22:04:30 PST 2002
>Last-Modified:  Mon Feb 25 22:05:53 PST 2002
>Originator:     Joseph Mallett
>Release:        4.4-RC
>Organization:
xMach
>Environment:
Aphex% uname -a
FreeBSD Aphex.NewGold.NET 4.4-RC FreeBSD 4.4-RC #0: Mon Aug 20 06:41:21 GMT 2001     jmallett@Aphex.NewGold.NET:/usr/people/jmallett/obj  i386
>Description:
As Brett Glass pointed out in an earlier PR, if virtualhosting is being used (and ICANN or whoever said they won't allocate ips to people who should use name-based vhosts instead, so this is a 'big thing') it won't be made use of by ftp(1) as it doesn't send a Host: header. Of course, patching this is really trivial (I switched to asprintf() cause you never know how long a URL is, though I suppose you could go by the standards). And a patch is attached.
>How-To-Repeat:
ftp http://srcsys.org/work/penis-slapped-by-jkh.txt
and then
fetch http://srcsys.org/work/penis-slapped-by-jkh.txt

>Fix:
Aphex% cat host.patch
--- /usr/src/usr.bin/ftp/fetch.c        Wed Jan 31 08:24:39 2001
+++ fetch.c     Fri Aug 24 19:49:29 2001
@@ -104,7 +104,7 @@
        char *port;
        volatile int s;
        size_t len;
-       char c, *cp, *ep, *portnum, *path, buf[4096];
+       char c, *cp, *ep, *http_buffer, *portnum, *path, buf[4096];
        const char *savefile;
        char *line, *proxy, *host;
        volatile sig_t oldintr;
@@ -280,12 +280,19 @@
                printf("Requesting %s\n", origline);
        else
                printf("Requesting %s (via %s)\n", origline, proxyenv);
-       len = snprintf(buf, sizeof(buf), "GET %s%s HTTP/1.0\r\n\r\n",
-           proxy ? "" : "/", path);
-       if (write(s, buf, len) < len) {
+       len = asprintf(&http_buffer, "GET %s%s HTTP/1.0\r\nHost: %s\r\n\r\n",
+           proxy ? "" : "/", path, host);
+       if (len == -1) {
+               warn("Allocating space for HTTP request");
+               goto cleanup_url_get;
+       }
+       if (write(s, http_buffer, len) < len) {
                warn("Writing HTTP request");
+               if (http_buffer != NULL)
+                       free(http_buffer);
                goto cleanup_url_get;
        }
+       free(http_buffer);
        memset(buf, 0, sizeof(buf));
        for (cp = buf; cp < buf + sizeof(buf); ) {
                if (read(s, cp, 1) != 1)
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mike 
Responsible-Changed-By: mike 
Responsible-Changed-When: Sun Aug 26 12:46:13 PDT 2001 
Responsible-Changed-Why:  

I'll look into this. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30054 
State-Changed-From-To: open->analyzed 
State-Changed-By: mike 
State-Changed-When: Wed Aug 29 18:00:53 PDT 2001 
State-Changed-Why:  

Committed a new patch from the originator to -CURRENT. 
MFC after 4.4-RELEASE. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30054 

From: Colin Percival <colin.percival@wadham.ox.ac.uk>
To: freebsd-gnats-submit@FreeBSD.org, jmallett@xMach.org
Cc:  
Subject: Re: bin/30054: ftp(1)'s fetch.c could easily have vhost support
Date: Thu, 27 Dec 2001 22:34:40 +0000

    The commit notice for this 
 (http://docs.freebsd.org/cgi/getmsg.cgi?fetch=946074+0+archive/2001/cvs-all/20010902.cvs-all) 
 on August 29 was marked "MFC after: 8 days".
    Can this be done, and then can bin/30054 and bin/33237 be closed?
 
 Colin Percival
 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mike 
State-Changed-When: Mon Feb 25 22:04:30 PST 2002 
State-Changed-Why:  

lukemftp is schedule to be MFC'd shortly, which will solve this 
problem is -stable. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=30054 
>Unformatted:
