Browse code

libclamav: earlier exit on hashtable growth problem

David Raynor authored on 2013/08/13 06:47:45
Showing 1 changed files
... ...
@@ -1,7 +1,7 @@
1 1
 /*
2 2
  *  Hash-table and -set data structures.
3 3
  *
4
- *  Copyright (C) 2007-2008 Sourcefire, Inc.
4
+ *  Copyright (C) 2007-2013 Sourcefire, Inc.
5 5
  *
6 6
  *  Authors: Török Edvin
7 7
  *
... ...
@@ -326,11 +326,18 @@ const struct cli_htu32_element *cli_htu32_next(const struct cli_htu32 *s, const
326 326
 static int cli_hashtab_grow(struct cli_hashtable *s)
327 327
 {
328 328
 	const size_t new_capacity = nearest_power(s->capacity + 1);
329
-	struct cli_element* htable = cli_calloc(new_capacity, sizeof(*s->htable));
329
+	struct cli_element* htable;
330 330
 	size_t i,idx, used = 0;
331
+
331 332
 	cli_dbgmsg("hashtab.c: new capacity: %lu\n",new_capacity);
332
-	if(new_capacity == s->capacity || !htable)
333
+	if(new_capacity == s->capacity) {
334
+		cli_errmsg("hashtab.c: capacity problem growing from: %lu\n",s->capacity);
333 335
 		return CL_EMEM;
336
+	}
337
+	htable = cli_calloc(new_capacity, sizeof(*s->htable));
338
+	if(!htable) {
339
+		return CL_EMEM;
340
+	}
334 341
 
335 342
 	PROFILE_GROW_START(s);
336 343
 	cli_dbgmsg("hashtab.c: Warning: growing open-addressing hashtables is slow. Either allocate more storage when initializing, or use other hashtable types!\n");