Browse Source

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 <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
kris/onging/CECPQ3_patch15
David Benjamin 7 years ago
committed by Adam Langley
parent
commit
55696cecde
3 changed files with 4 additions and 14 deletions
  1. +1
    -10
      crypto/lhash/lhash.c
  2. +2
    -1
      crypto/lhash/lhash_test.cc
  3. +1
    -3
      include/openssl/lhash.h

+ 1
- 10
crypto/lhash/lhash.c View File

@@ -74,9 +74,7 @@ static const size_t kMaxAverageChainLength = 2;
static const size_t kMinAverageChainLength = 1; static const size_t kMinAverageChainLength = 1;


_LHASH *lh_new(lhash_hash_func hash, lhash_cmp_func comp) { _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) { if (ret == NULL) {
return 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); OPENSSL_memset(ret->buckets, 0, sizeof(LHASH_ITEM *) * ret->num_buckets);


ret->comp = comp; ret->comp = comp;
if (ret->comp == NULL) {
ret->comp = (lhash_cmp_func) strcmp;
}
ret->hash = hash; ret->hash = hash;
if (ret->hash == NULL) {
ret->hash = (lhash_hash_func) lh_strhash;
}

return ret; return ret;
} }




+ 2
- 1
crypto/lhash/lhash_test.cc View File

@@ -60,7 +60,8 @@ static const char *Lookup(
int main(int argc, char **argv) { int main(int argc, char **argv) {
CRYPTO_library_init(); 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) { if (!lh) {
return 1; return 1;
} }


+ 1
- 3
include/openssl/lhash.h View File

@@ -144,9 +144,7 @@ typedef struct lhash_st {
lhash_hash_func hash; lhash_hash_func hash;
} _LHASH; } _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); 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 /* lh_free frees the hash table itself but none of the elements. See


Loading…
Cancel
Save