From: Willem Toorop Date: Thu, 12 May 2011 09:52:34 +0000 (+0000) Subject: Alleviate the potential sizeof(bool) discrepancies by: X-Git-Tag: release-1.6.10rc1~15 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4af241441921357d743aa1ba152e7c806c844ac9;p=thirdparty%2Fldns.git Alleviate the potential sizeof(bool) discrepancies by: 1. Allocating scructures with (aligned) bool attributes with LDNS_CALLOC (that fills the freshly allocated struct with zero's) 2. signed char as a fall back type for bool, as recommended in the autoconf manual 3. An access function for the is_glueattribute: bool ldns_dnssec_name_is_glue(ldns_dnssec_name *name) --- diff --git a/compat/calloc.c b/compat/calloc.c new file mode 100644 index 00000000..c86b9567 --- /dev/null +++ b/compat/calloc.c @@ -0,0 +1,24 @@ +/* Just a replacement, if the original malloc is not + GNU-compliant. See autoconf documentation. */ + +#if HAVE_CONFIG_H +#include +#endif + +void *calloc(); + +#if !HAVE_BZERO && HAVE_MEMSET +# define bzero(buf, bytes) ((void) memset (buf, 0, bytes)) +#endif + +void * +calloc(size_t num, size_t size) +{ + void *new = malloc(num * size); + if (!new) { + return NULL; + } + bzero(new, num * size); + return new; +} + diff --git a/configure.ac b/configure.ac index 12f88b37..ce31eba4 100644 --- a/configure.ac +++ b/configure.ac @@ -229,10 +229,11 @@ AC_C_BIGENDIAN # Checks for header files. AC_HEADER_STDC +AC_HEADER_STDBOOL #AC_HEADER_SYS_WAIT #AC_CHECK_HEADERS([getopt.h fcntl.h stdlib.h string.h strings.h unistd.h]) # do the very minimum - we can always extend this -AC_CHECK_HEADERS([getopt.h stdarg.h stdbool.h openssl/ssl.h netinet/in.h time.h arpa/inet.h netdb.h],,, [AC_INCLUDES_DEFAULT]) +AC_CHECK_HEADERS([getopt.h stdarg.h openssl/ssl.h netinet/in.h time.h arpa/inet.h netdb.h],,, [AC_INCLUDES_DEFAULT]) AC_CHECK_HEADERS(sys/param.h sys/mount.h,,, [AC_INCLUDES_DEFAULT [ @@ -322,6 +323,7 @@ AC_REPLACE_FUNCS(b64_pton) AC_REPLACE_FUNCS(b64_ntop) AC_REPLACE_FUNCS(b32_pton) AC_REPLACE_FUNCS(b32_ntop) +AC_REPLACE_FUNCS(calloc) AC_REPLACE_FUNCS(timegm) AC_REPLACE_FUNCS(gmtime_r) AC_REPLACE_FUNCS(ctime_r) @@ -333,7 +335,7 @@ AC_REPLACE_FUNCS(inet_ntop) AC_REPLACE_FUNCS(snprintf) AC_REPLACE_FUNCS(strlcpy) AC_REPLACE_FUNCS(memmove) -AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul]) +AC_CHECK_FUNCS([endprotoent endservent sleep random fcntl strtoul bzero memset]) ACX_CHECK_GETADDRINFO_WITH_INCLUDES if test $ac_cv_func_getaddrinfo = no; then diff --git a/dnssec_verify.c b/dnssec_verify.c index e1c75d56..b1fd0506 100644 --- a/dnssec_verify.c +++ b/dnssec_verify.c @@ -18,8 +18,11 @@ ldns_dnssec_data_chain * ldns_dnssec_data_chain_new() { - ldns_dnssec_data_chain *nc = LDNS_XMALLOC(ldns_dnssec_data_chain, 1); + ldns_dnssec_data_chain *nc = LDNS_CALLOC(ldns_dnssec_data_chain, 1); if(!nc) return NULL; + /* + * not needed anymore because of CALLOC + nc->rrset = NULL; nc->parent_type = 0; nc->parent = NULL; @@ -27,6 +30,8 @@ ldns_dnssec_data_chain_new() nc->packet_rcode = 0; nc->packet_qtype = 0; nc->packet_nodata = false; + + */ return nc; } diff --git a/dnssec_zone.c b/dnssec_zone.c index e2a5fce6..1c6695bc 100644 --- a/dnssec_zone.c +++ b/dnssec_zone.c @@ -297,10 +297,12 @@ ldns_dnssec_name_new() { ldns_dnssec_name *new_name; - new_name = LDNS_MALLOC(ldns_dnssec_name); + new_name = LDNS_CALLOC(ldns_dnssec_name, 1); if (!new_name) { return NULL; } + /* + * not needed anymore because of CALLOC new_name->name = NULL; new_name->rrsets = NULL; @@ -311,6 +313,7 @@ ldns_dnssec_name_new() new_name->is_glue = false; new_name->hashed_name = NULL; + */ return new_name; } @@ -375,6 +378,15 @@ ldns_dnssec_name_name(ldns_dnssec_name *name) return NULL; } +bool +ldns_dnssec_name_is_glue(ldns_dnssec_name *name) +{ + if (name) { + return name->is_glue; + } + return false; +} + void ldns_dnssec_name_set_name(ldns_dnssec_name *rrset, ldns_rdf *dname) diff --git a/ldns/common.h b/ldns/common.h index cc7dd89d..71e594ea 100644 --- a/ldns/common.h +++ b/ldns/common.h @@ -15,23 +15,20 @@ #ifndef LDNS_COMMON_H #define LDNS_COMMON_H -#if !defined(__cplusplus) && !defined(__bool_true_false_are_defined) - -#if defined(HAVE_STDBOOL_H) -#include +#ifdef HAVE_STDBOOL_H +# include #else - -/*@ignore@*/ -/* splint barfs on this construct */ -typedef unsigned int bool; -#define bool bool -#define false 0 -#define true 1 -#define __bool_true_false_are_defined 1 -/*@end@*/ - -#endif - +# ifndef HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# else +# define _Bool signed char +# endif +# endif +# define bool _Bool +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 #endif #ifdef HAVE_ATTR_FORMAT diff --git a/ldns/dnssec_zone.h b/ldns/dnssec_zone.h index 88117daf..bdb5a3c4 100644 --- a/ldns/dnssec_zone.h +++ b/ldns/dnssec_zone.h @@ -237,6 +237,15 @@ ldns_rdf *ldns_dnssec_name_name(ldns_dnssec_name *name); */ void ldns_dnssec_name_set_name(ldns_dnssec_name *name, ldns_rdf *dname); +/** + * Returns if dnssec_name structure is marked as glue. + * Note that the ldns_dnssec_zone_mark_glue function has to be called + * on a zone before using this function. + * + * \param[in] name the dnssec name to get the domain name from + * \return true if the structure is marked as glue, false otherwise. + */ +bool ldns_dnssec_name_is_glue(ldns_dnssec_name *name); /** * Sets the NSEC(3) RR of the given dnssec_name structure