svn commit: r253680 - in head: lib/libfetch usr.bin/fetch

Bruce Evans brde at optusnet.com.au
Thu Aug 8 22:05:31 UTC 2013


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


More information about the svn-src-head mailing list