Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 24 Aug 2001 12:56:06 -0700 (PDT)
From:      Joseph Mallett <jmallett@xMach.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   bin/30054: ftp(1)'s fetch.c could easily have vhost support
Message-ID:  <200108241956.f7OJu6b08856@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         30054
>Category:       bin
>Synopsis:       ftp(1)'s fetch.c could easily have vhost support
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 24 13:00:00 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200108241956.f7OJu6b08856>