diff options
Diffstat (limited to 'src/lib/libcrypto/lhash/lhash.c')
| -rw-r--r-- | src/lib/libcrypto/lhash/lhash.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c index 3adec71ed6..81660419c7 100644 --- a/src/lib/libcrypto/lhash/lhash.c +++ b/src/lib/libcrypto/lhash/lhash.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: lhash.c,v 1.20 2023/07/07 13:40:44 beck Exp $ */ | 1 | /* $OpenBSD: lhash.c,v 1.21 2024/01/24 14:02:52 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -250,12 +250,21 @@ static void | |||
| 250 | doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, | 250 | doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, |
| 251 | LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) | 251 | LHASH_DOALL_ARG_FN_TYPE func_arg, void *arg) |
| 252 | { | 252 | { |
| 253 | int i; | ||
| 254 | LHASH_NODE *a, *n; | 253 | LHASH_NODE *a, *n; |
| 254 | int down_load; | ||
| 255 | int i; | ||
| 255 | 256 | ||
| 256 | if (lh == NULL) | 257 | if (lh == NULL) |
| 257 | return; | 258 | return; |
| 258 | 259 | ||
| 260 | /* | ||
| 261 | * Disable contraction of the hash while walking, as some consumers use | ||
| 262 | * it to delete hash entries. A better option would be to snapshot the | ||
| 263 | * hash, making it insert safe as well. | ||
| 264 | */ | ||
| 265 | down_load = lh->down_load; | ||
| 266 | lh->down_load = 0; | ||
| 267 | |||
| 259 | /* reverse the order so we search from 'top to bottom' | 268 | /* reverse the order so we search from 'top to bottom' |
| 260 | * We were having memory leaks otherwise */ | 269 | * We were having memory leaks otherwise */ |
| 261 | for (i = lh->num_nodes - 1; i >= 0; i--) { | 270 | for (i = lh->num_nodes - 1; i >= 0; i--) { |
| @@ -273,6 +282,10 @@ doall_util_fn(_LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, | |||
| 273 | a = n; | 282 | a = n; |
| 274 | } | 283 | } |
| 275 | } | 284 | } |
| 285 | |||
| 286 | /* Restore down load factor and trigger contraction. */ | ||
| 287 | lh->down_load = down_load; | ||
| 288 | contract(lh); | ||
| 276 | } | 289 | } |
| 277 | 290 | ||
| 278 | void | 291 | void |
