diff options
| author | Doug Barton <dougb@FreeBSD.org> | 2011-08-02 05:18:50 +0000 | 
|---|---|---|
| committer | Doug Barton <dougb@FreeBSD.org> | 2011-08-02 05:18:50 +0000 | 
| commit | 0842d663b7cfb84b478ec937fc1dbc640ceae92b (patch) | |
| tree | 4385ddab756952a705f233916d0536e76fe9cc58 /lib/isc/netaddr.c | |
| parent | 6a50a75ead6b2f11f0321914c033e8c8670cbb60 (diff) | |
Notes
Diffstat (limited to 'lib/isc/netaddr.c')
| -rw-r--r-- | lib/isc/netaddr.c | 44 | 
1 files changed, 21 insertions, 23 deletions
diff --git a/lib/isc/netaddr.c b/lib/isc/netaddr.c index 92c4fe5b4d4cb..aa6aa09152ca3 100644 --- a/lib/isc/netaddr.c +++ b/lib/isc/netaddr.c @@ -1,5 +1,5 @@  /* - * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC") + * Copyright (C) 2004, 2005, 2007, 2011  Internet Systems Consortium, Inc. ("ISC")   * Copyright (C) 1999-2002  Internet Software Consortium.   *   * Permission to use, copy, modify, and/or distribute this software for any @@ -15,7 +15,7 @@   * PERFORMANCE OF THIS SOFTWARE.   */ -/* $Id: netaddr.c,v 1.38 2007-06-18 23:47:44 tbox Exp $ */ +/* $Id: netaddr.c,v 1.38.332.3 2011-03-11 10:49:58 marka Exp $ */  /*! \file */ @@ -69,10 +69,10 @@ isc_boolean_t  isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,  		     unsigned int prefixlen)  { -	const unsigned char *pa, *pb; -	unsigned int ipabytes; /* Length of whole IP address in bytes */ -	unsigned int nbytes;   /* Number of significant whole bytes */ -	unsigned int nbits;    /* Number of significant leftover bits */ +	const unsigned char *pa = NULL, *pb = NULL; +	unsigned int ipabytes = 0; /* Length of whole IP address in bytes */ +	unsigned int nbytes;       /* Number of significant whole bytes */ +	unsigned int nbits;        /* Number of significant leftover bits */  	REQUIRE(a != NULL && b != NULL); @@ -94,8 +94,6 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b,  		ipabytes = 16;  		break;  	default: -		pa = pb = NULL; /* Avoid silly compiler warning. */ -		ipabytes = 0; /* Ditto. */  		return (ISC_FALSE);  	} @@ -188,6 +186,9 @@ isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) {  	isc_buffer_init(&buf, array, size);  	result = isc_netaddr_totext(na, &buf); +	if (size == 0) +		return; +  	/*  	 * Null terminate.  	 */ @@ -212,7 +213,7 @@ isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) {  isc_result_t  isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen) {  	static const unsigned char zeros[16]; -	unsigned int nbits, nbytes, ipbytes; +	unsigned int nbits, nbytes, ipbytes = 0;  	const unsigned char *p;  	switch (na->family) { @@ -229,7 +230,6 @@ isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen) {  			return (ISC_R_RANGE);  		break;  	default: -		ipbytes = 0;  		return (ISC_R_NOTIMPLEMENTED);  	}  	nbytes = prefixlen / 8; @@ -246,7 +246,7 @@ isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen) {  isc_result_t  isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) { -	unsigned int nbits, nbytes, ipbytes, i; +	unsigned int nbits = 0, nbytes = 0, ipbytes = 0, i;  	const unsigned char *p;  	switch (s->family) { @@ -259,10 +259,8 @@ isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) {  		ipbytes = 16;  		break;  	default: -		ipbytes = 0;  		return (ISC_R_NOTIMPLEMENTED);  	} -	nbytes = nbits = 0;  	for (i = 0; i < ipbytes; i++) {  		if (p[i] != 0xFF)  			break; @@ -303,18 +301,18 @@ isc_netaddr_fromin6(isc_netaddr_t *netaddr, const struct in6_addr *ina6) {  isc_result_t  isc_netaddr_frompath(isc_netaddr_t *netaddr, const char *path) {  #ifdef ISC_PLATFORM_HAVESYSUNH -        if (strlen(path) > sizeof(netaddr->type.un) - 1) -                return (ISC_R_NOSPACE); - -        memset(netaddr, 0, sizeof(*netaddr)); -        netaddr->family = AF_UNIX; -        strcpy(netaddr->type.un, path); -        netaddr->zone = 0; -        return (ISC_R_SUCCESS); -#else  +	if (strlen(path) > sizeof(netaddr->type.un) - 1) +		return (ISC_R_NOSPACE); + +	memset(netaddr, 0, sizeof(*netaddr)); +	netaddr->family = AF_UNIX; +	strcpy(netaddr->type.un, path); +	netaddr->zone = 0; +	return (ISC_R_SUCCESS); +#else  	UNUSED(netaddr);  	UNUSED(path); -        return (ISC_R_NOTIMPLEMENTED); +	return (ISC_R_NOTIMPLEMENTED);  #endif  }  | 
