From 55696cecde12355a6e55749d4d70a1042e53431b Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Thu, 22 Dec 2016 03:32:19 -0500 Subject: [PATCH] Remove lh_new's default hash and comparator. This is a memory error for anything other than LHASH_OF(char), which does not exist. No code outside the library creates (or even queries) an LHASH, so we can change this module freely. Change-Id: Ifbc7a1c69a859e07650fcfaa067bdfc68d83fbbc Reviewed-on: https://boringssl-review.googlesource.com/12978 Commit-Queue: David Benjamin Reviewed-by: Adam Langley --- crypto/lhash/lhash.c | 11 +---------- crypto/lhash/lhash_test.cc | 3 ++- include/openssl/lhash.h | 4 +--- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index 6bb330c8..27960d98 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -74,9 +74,7 @@ static const size_t kMaxAverageChainLength = 2; static const size_t kMinAverageChainLength = 1; _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) { - _LHASH *ret; - - ret = OPENSSL_malloc(sizeof(_LHASH)); + _LHASH *ret = OPENSSL_malloc(sizeof(_LHASH)); if (ret == NULL) { return NULL; } @@ -91,14 +89,7 @@ _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) { OPENSSL_memset(ret->buckets, 0, sizeof(LHASH_ITEM *) * ret->num_buckets); ret->comp = comp; - if (ret->comp == NULL) { - ret->comp = (lhash_cmp_func) strcmp; - } ret->hash = hash; - if (ret->hash == NULL) { - ret->hash = (lhash_hash_func) lh_strhash; - } - return ret; } diff --git a/crypto/lhash/lhash_test.cc b/crypto/lhash/lhash_test.cc index 05375d5e..cbeb15b1 100644 --- a/crypto/lhash/lhash_test.cc +++ b/crypto/lhash/lhash_test.cc @@ -60,7 +60,8 @@ static const char *Lookup( int main(int argc, char **argv) { CRYPTO_library_init(); - std::unique_ptr<_LHASH, FreeLHASH> lh(lh_new(NULL, NULL)); + std::unique_ptr<_LHASH, FreeLHASH> lh( + lh_new((lhash_hash_func)lh_strhash, (lhash_cmp_func)strcmp)); if (!lh) { return 1; } diff --git a/include/openssl/lhash.h b/include/openssl/lhash.h index 130ffb1f..b95d4f21 100644 --- a/include/openssl/lhash.h +++ b/include/openssl/lhash.h @@ -144,9 +144,7 @@ typedef struct lhash_st { lhash_hash_func hash; } _LHASH; -/* lh_new returns a new, empty hash table or NULL on error. If |comp| is NULL, - * |strcmp| will be used. If |hash| is NULL, a generic hash function will be - * used. */ +/* lh_new returns a new, empty hash table or NULL on error. */ OPENSSL_EXPORT _LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp); /* lh_free frees the hash table itself but none of the elements. See