summaryrefslogtreecommitdiff
path: root/src/search/hsearch.c
diff options
context:
space:
mode:
authorSzabolcs Nagy <nsz@port70.net>2023-02-03 23:10:17 +0100
committerRich Felker <dalias@aerifal.cx>2023-02-12 17:41:23 -0500
commit7e6da7ac98efdc8167ed2d109298ba232a9a7ba3 (patch)
tree776606dd8b1f51d743a4808b2ae89ee600ebd437 /src/search/hsearch.c
parentf79b973d92a322800b3e8411ccc95db280d997ae (diff)
downloadmusl-7e6da7ac98efdc8167ed2d109298ba232a9a7ba3.tar.gz
musl-7e6da7ac98efdc8167ed2d109298ba232a9a7ba3.tar.bz2
musl-7e6da7ac98efdc8167ed2d109298ba232a9a7ba3.tar.xz
musl-7e6da7ac98efdc8167ed2d109298ba232a9a7ba3.zip
hsearch: fix null pointer arithmetic UB
htab->__tab->entries pointer may be 0 so delay using it in arithmetics. this did not cause any known issue other than with ubsan instrumentation.
Diffstat (limited to 'src/search/hsearch.c')
-rw-r--r--src/search/hsearch.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/search/hsearch.c b/src/search/hsearch.c
index b3ac8796..2634a67f 100644
--- a/src/search/hsearch.c
+++ b/src/search/hsearch.c
@@ -41,9 +41,9 @@ static int resize(size_t nel, struct hsearch_data *htab)
{
size_t newsize;
size_t i, j;
+ size_t oldsize = htab->__tab->mask + 1;
ENTRY *e, *newe;
ENTRY *oldtab = htab->__tab->entries;
- ENTRY *oldend = htab->__tab->entries + htab->__tab->mask + 1;
if (nel > MAXSIZE)
nel = MAXSIZE;
@@ -56,7 +56,7 @@ static int resize(size_t nel, struct hsearch_data *htab)
htab->__tab->mask = newsize - 1;
if (!oldtab)
return 1;
- for (e = oldtab; e < oldend; e++)
+ for (e = oldtab; e < oldtab + oldsize; e++)
if (e->key) {
for (i=keyhash(e->key),j=1; ; i+=j++) {
newe = htab->__tab->entries + (i & htab->__tab->mask);