Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 9 Aug 2013 08:05:19 +1000 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        Ulrich =?utf-8?B?U3DDtnJsZWlu?= <uqs@FreeBSD.org>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Dag-Erling =?utf-8?B?U23Dg8W+cmdyYXY=?= <des@FreeBSD.org>
Subject:   Re: svn commit: r253680 - in head: lib/libfetch usr.bin/fetch
Message-ID:  <20130809074807.Q921@besplex.bde.org>
In-Reply-To: <20130808163451.GB54133@acme.spoerlein.net>
References:  <201307261553.r6QFrhwu084667@svn.freebsd.org> <20130808163451.GB54133@acme.spoerlein.net>

index | next in thread | previous in thread | raw e-mail

On Thu, 8 Aug 2013, Ulrich [utf-8] Spörlein wrote:

> On Fri, 2013-07-26 at 15:53:43 +0000, Dag-Erling SmÞrgrav wrote:
>> Modified: head/lib/libfetch/common.c
>> ==============================================================================
>> --- head/lib/libfetch/common.c	Fri Jul 26 14:43:38 2013	(r253679)
>> +++ head/lib/libfetch/common.c	Fri Jul 26 15:53:43 2013	(r253680)
>> +static struct addrinfo *
>> +fetch_ssl_get_numeric_addrinfo(const char *hostname, size_t len)
>> +{
>> +	struct addrinfo hints, *res;
>> +	char *host;
>> +
>> +	host = (char *)malloc(len + 1);
>> +	memcpy(host, hostname, len);
>> +	host[len] = '\0';
>> +	memset(&hints, 0, sizeof(hints));
>> +	hints.ai_family = PF_UNSPEC;
>> +	hints.ai_socktype = SOCK_STREAM;
>> +	hints.ai_protocol = 0;
>> +	hints.ai_flags = AI_NUMERICHOST;
>> +	/* port is not relevant for this purpose */
>> +	getaddrinfo(host, "443", &hints, &res);
>
> We check the return value for getaddrinfo() 210 out of 217 times in our
> tree, please check it here too. Thanks! CID 1061016

We sometimes check the return value of malloc() too.  Though checking is
usually just a waste of space and time, libraries should do it.

Style bugs in the above include:
- 'hostname' shadows a global function name
- bogus cast of malloc().  Old code in this file doesn't cast malloc().
- we labouriously use a home made strdup() since the string length is an
   arg.  But len must be strlen(hostname) for the home made strdup() to
   work.
- hints.ai_protocol is initialized twice
- the comment is neither capitalized nor terminated with a ".".  Old
   code in this file has mixed style bugs in comments, and uses the same
   style bugs often but not always.

Bruce
home | help

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