]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Alleviate the potential sizeof(bool) discrepancies by:
authorWillem Toorop <willem@NLnetLabs.nl>
Thu, 12 May 2011 09:52:34 +0000 (09:52 +0000)
committerWillem Toorop <willem@NLnetLabs.nl>
Thu, 12 May 2011 09:52:34 +0000 (09:52 +0000)
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)

compat/calloc.c [new file with mode: 0644]
configure.ac
dnssec_verify.c
dnssec_zone.c
ldns/common.h
ldns/dnssec_zone.h

diff --git a/compat/calloc.c b/compat/calloc.c
new file mode 100644 (file)
index 0000000..c86b956
--- /dev/null
@@ -0,0 +1,24 @@
+/* Just a replacement, if the original malloc is not
+   GNU-compliant. See autoconf documentation. */
+
+#if HAVE_CONFIG_H
+#include <ldns/config.h>
+#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;
+}
+
index 12f88b37d3775169ae79d2b062606ce169079c94..ce31eba42d0f7a3497812bfbb2d366aebf9a29d3 100644 (file)
@@ -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
index e1c75d56c7182174f132de8fbdad1d29f644718c..b1fd0506c70910ab59e6321d91f8bf010053ecc3 100644 (file)
 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;
 }
 
index e2a5fce6edd321f294fb8dec42a89d8789fdadbd..1c6695bc269041b220c8db3e8f9ca337b8482f9c 100644 (file)
@@ -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)
index cc7dd89d1adf9a8079a85ffe675333f8ae0259a0..71e594eae987216357c7ecae04de719751829217 100644 (file)
 #ifndef LDNS_COMMON_H
 #define LDNS_COMMON_H
 
-#if !defined(__cplusplus) && !defined(__bool_true_false_are_defined)
-
-#if defined(HAVE_STDBOOL_H)
-#include <stdbool.h>
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
 #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
index 88117dafb3a95035682a8a6a91a128d9d7857187..bdb5a3c41986a74fbc4fee7f743bbe68e7803cd0 100644 (file)
@@ -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