From owner-svn-src-all@freebsd.org Tue Feb 28 18:03:37 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9A55ECF17B2; Tue, 28 Feb 2017 18:03:37 +0000 (UTC) (envelope-from bzeeb-lists@lists.zabbadoz.net) Received: from mx1.sbone.de (bird.sbone.de [46.4.1.90]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mx1.sbone.de", Issuer "SBone.DE" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 2F347DFB; Tue, 28 Feb 2017 18:03:36 +0000 (UTC) (envelope-from bzeeb-lists@lists.zabbadoz.net) Received: from mail.sbone.de (mail.sbone.de [IPv6:fde9:577b:c1a9:31::2013:587]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.sbone.de (Postfix) with ESMTPS id 4FFB725D3860; Tue, 28 Feb 2017 18:03:28 +0000 (UTC) Received: from content-filter.sbone.de (content-filter.sbone.de [IPv6:fde9:577b:c1a9:31::2013:2742]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPS id 45782D1F8BC; Tue, 28 Feb 2017 18:03:27 +0000 (UTC) X-Virus-Scanned: amavisd-new at sbone.de Received: from mail.sbone.de ([IPv6:fde9:577b:c1a9:31::2013:587]) by content-filter.sbone.de (content-filter.sbone.de [fde9:577b:c1a9:31::2013:2742]) (amavisd-new, port 10024) with ESMTP id ppkKRG28UHuj; Tue, 28 Feb 2017 18:03:25 +0000 (UTC) Received: from [192.168.124.1] (fresh-tun0-ula.sbone.de [IPv6:fde9:577b:c1a9:4920:2ef0:eeff:fe03:ee34]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.sbone.de (Postfix) with ESMTPSA id 373FBD1F835; Tue, 28 Feb 2017 18:03:25 +0000 (UTC) From: "Bjoern A. Zeeb" To: "Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?=" Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r308996 - head/lib/libfetch Date: Tue, 28 Feb 2017 18:03:24 +0000 Message-ID: <77B1B45A-D837-4853-B1E9-958D3B0DD519@lists.zabbadoz.net> In-Reply-To: <201611221330.uAMDU7fg052989@repo.freebsd.org> References: <201611221330.uAMDU7fg052989@repo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailer: MailMate (2.0BETAr6080) X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2017 18:03:37 -0000 On 22 Nov 2016, at 13:30, Dag-Erling Smørgrav wrote: > Author: des > Date: Tue Nov 22 13:30:07 2016 > New Revision: 308996 > URL: https://svnweb.freebsd.org/changeset/base/308996 > > Log: > Refactor fetch_connect() and fetch_bind() to improve readability and > avoid > repeating the same DNS lookups. > > MFC after: 3 weeks > > Modified: > head/lib/libfetch/common.c > head/lib/libfetch/common.h > head/lib/libfetch/ftp.c > > Modified: head/lib/libfetch/common.c > ============================================================================== > --- head/lib/libfetch/common.c Tue Nov 22 13:24:57 2016 (r308995) > +++ head/lib/libfetch/common.c Tue Nov 22 13:30:07 2016 (r308996) > @@ -1,5 +1,5 @@ > /*- > - * Copyright (c) 1998-2014 Dag-Erling Smørgrav > + * Copyright (c) 1998-2016 Dag-Erling Smørgrav > * Copyright (c) 2013 Michael Gmelin > * All rights reserved. > * > @@ -241,27 +241,83 @@ fetch_ref(conn_t *conn) > > > /* > + * Resolve an address > + */ > +struct addrinfo * > +fetch_resolve(const char *addr, int port, int af) > +{ > + char hbuf[256], sbuf[8]; > + struct addrinfo hints, *res; > + const char *sep, *host, *service; > + int err, len; > + > + /* split address if necessary */ > + err = EAI_SYSTEM; > + if ((sep = strchr(addr, ':')) != NULL) { > + len = snprintf(hbuf, sizeof(hbuf), > + "%.*s", (int)(sep - addr), addr); > + if (len < 0) > + return (NULL); > + if (len >= (int)sizeof(hbuf)) { > + errno = ENAMETOOLONG; > + fetch_syserr(); > + return (NULL); > + } > + host = hbuf; > + service = sep + 1; I believe this code is what broke fetch http://[::1]:6666/ just to give an example; and the printf traces will not reveal this but “addr” at this point has no more addr:port in it given the function arguments, right? > + } else if (port != 0) { > + if (port < 1 || port > 65535) { > + errno = EINVAL; > + fetch_syserr(); > + return (NULL); > + } > + if (snprintf(sbuf, sizeof(sbuf), "%d", port) < 0) { > + fetch_syserr(); > + return (NULL); > + } > + host = addr; > + service = sbuf; > + } else { > + host = addr; > + service = NULL; > + } > + > + /* resolve */ > + fetch_info("resolving host = %s service = %s af = %d", > + host, service, af); > + memset(&hints, 0, sizeof(hints)); > + hints.ai_family = af; > + hints.ai_socktype = SOCK_STREAM; > + hints.ai_flags = AI_ADDRCONFIG; > + if ((err = getaddrinfo(host, service, &hints, &res)) != 0) { > + netdb_seterr(err); > + fetch_info("getaddrinfo() failed: %s", gai_strerror(err)); > + return (NULL); > + }