svn commit: r308996 - head/lib/libfetch
Bjoern A. Zeeb
bzeeb-lists at lists.zabbadoz.net
Tue Feb 28 18:03:37 UTC 2017
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 at 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);
> + }
More information about the svn-src-all
mailing list