]> git.ipfire.org Git - thirdparty/dhcp.git/commitdiff
Hankin's fixes for hash-related core dumps on HEAD.
authorShane Kerr <shane@isc.org>
Tue, 25 Jul 2006 09:59:39 +0000 (09:59 +0000)
committerShane Kerr <shane@isc.org>
Tue, 25 Jul 2006 09:59:39 +0000 (09:59 +0000)
common/parse.c
includes/omapip/hash.h
omapip/hash.c

index f146d2b113f2fc93db11c61aaa9d42e2a1b70065..e460f844b7368a2f85fdc3394efa86e64b6c7da1 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: parse.c,v 1.113 2006/07/22 02:24:16 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: parse.c,v 1.114 2006/07/25 09:59:39 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include "dhcpd.h"
@@ -991,7 +991,6 @@ parse_option_name (cfile, allocate, known, opt)
        }
 
        /* Look up the actual option info... */
-       option = (struct option *)0;
        option_name_hash_lookup(opt, universe->name_hash, val, 0, MDL);
        option = *opt;
 
@@ -1765,7 +1764,7 @@ int parse_executable_statement (result, cfile, lose, case_context)
        const char *val;
        struct executable_statement base;
        struct class *cta;
-       struct option *option;
+       struct option *option=NULL;
        struct option_cache *cache;
        int known;
        int flag;
index 15f2398fa157de22dcff7a1516ede864fe44c8ea..2a588496bcb353cadd7e349a474e3a267cb12972 100644 (file)
@@ -64,11 +64,13 @@ typedef int (*hash_comparator_t)(const void *, const void *, size_t);
 
 struct hash_table {
        unsigned hash_count;
-       struct hash_bucket *buckets [DEFAULT_HASH_SIZE];
        hash_reference referencer;
        hash_dereference dereferencer;
        hash_comparator_t cmp;
        unsigned (*do_hash)(const void *, unsigned, unsigned);
+
+       /* This must remain the last entry in this table. */
+       struct hash_bucket *buckets [1];
 };
 
 struct named_hash {
index 2d780ccfb75ac229d613f867b375e37b3e077915..29a67eb6c49792dac065f361b3ec5574a3268f4f 100644 (file)
@@ -34,7 +34,7 @@
 
 #ifndef lint
 static char copyright[] =
-"$Id: hash.c,v 1.10 2006/06/08 23:51:37 dhankins Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
+"$Id: hash.c,v 1.11 2006/07/25 09:59:39 shane Exp $ Copyright (c) 2004-2006 Internet Systems Consortium.  All rights reserved.\n";
 #endif /* not lint */
 
 #include <omapip/omapip_p.h>
@@ -62,6 +62,7 @@ int new_hash_table (tp, count, file, line)
        int line;
 {
        struct hash_table *rval;
+       unsigned extra;
 
        if (!tp) {
                log_error ("%s(%d): new_hash_table called with null pointer.",
@@ -78,9 +79,18 @@ int new_hash_table (tp, count, file, line)
                abort ();
 #endif
        }
-       rval = dmalloc (sizeof (struct hash_table) -
-                       (DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *)) +
-                       (count * sizeof (struct hash_bucket *)), file, line);
+
+       /* There is one hash bucket in the structure.  Allocate extra
+        * memory beyond the end of the structure to fulfill the requested
+        * count ("count - 1").  Do not let there be less than one.
+        */
+       if (count <= 1)
+               extra = 0;
+       else
+               extra = count - 1;
+
+       rval = dmalloc(sizeof(struct hash_table) +
+                      (extra * sizeof(struct hash_bucket *)), file, line);
        if (!rval)
                return 0;
        rval -> hash_count = count;
@@ -386,6 +396,11 @@ int hash_lookup (vp, table, key, len, file, line)
        if (!len)
                len = find_length(key, table->do_hash);
 
+       if (*vp != NULL) {
+               log_fatal("Internal inconsistency: storage value has not been "
+                         "initialized to zero (from %s:%d).", file, line);
+       }
+
        hashno = (*table->do_hash)(key, len, table->hash_count);
 
        for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {