From 0e00aeb638f883542f12c19d49c95676439b27d6 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Wed, 2 Apr 2014 18:40:03 +0200 Subject: [PATCH] Bug fix: Prevent allocation of empty hash tables. Thanks Richard Nolde. --- libisofs/ecma119_tree.c | 3 +++ libisofs/util_htable.c | 7 ++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/libisofs/ecma119_tree.c b/libisofs/ecma119_tree.c index 9e517ad..afc3450 100644 --- a/libisofs/ecma119_tree.c +++ b/libisofs/ecma119_tree.c @@ -592,6 +592,9 @@ int mangle_single_dir(Ecma119Image *img, Ecma119Node *dir, int max_file_len, nchildren = dir->info.dir->nchildren; children = dir->info.dir->children; + if (nchildren <= 0) + return ISO_SUCCESS; /* nothing to do */ + /* a hash table will temporary hold the names, for fast searching */ ret = iso_htable_create((nchildren * 100) / 80, iso_str_hash, (compare_function_t)strcmp, &table); diff --git a/libisofs/util_htable.c b/libisofs/util_htable.c index 1a0a8e5..5e55273 100644 --- a/libisofs/util_htable.c +++ b/libisofs/util_htable.c @@ -322,9 +322,10 @@ int iso_htable_create(size_t size, hash_funtion_t hash, { IsoHTable *t; - if (table == NULL) { - return ISO_OUT_OF_MEM; - } + if (size <= 0) + return ISO_WRONG_ARG_VALUE; + if (table == NULL) + return ISO_NULL_POINTER; t = malloc(sizeof(IsoHTable)); if (t == NULL) {