Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Feb 2017 18:03:24 +0000
From:      "Bjoern A. Zeeb" <bzeeb-lists@lists.zabbadoz.net>
To:        "Dag-Erling =?utf-8?q?Sm=C3=B8rgrav?=" <des@FreeBSD.org>
Cc:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   Re: svn commit: r308996 - head/lib/libfetch
Message-ID:  <77B1B45A-D837-4853-B1E9-958D3B0DD519@lists.zabbadoz.net>
In-Reply-To: <201611221330.uAMDU7fg052989@repo.freebsd.org>
References:  <201611221330.uAMDU7fg052989@repo.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <freebsd@grem.de>
>   * 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);
> +	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?77B1B45A-D837-4853-B1E9-958D3B0DD519>