From owner-freebsd-bugs Fri Aug 24 13: 0:14 2001 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id AF36637B408 for ; Fri, 24 Aug 2001 13:00:00 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.11.4/8.11.4) id f7OK00O09264; Fri, 24 Aug 2001 13:00:00 -0700 (PDT) (envelope-from gnats) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by hub.freebsd.org (Postfix) with ESMTP id EC2BC37B405 for ; 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 To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: bin/30054: ftp(1)'s fetch.c could easily have vhost support Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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