Skip to content

Commit 5eddb9e

Browse files
committed
Fix potential integer overflow vulnerability when allocating memory
1 parent 6feb999 commit 5eddb9e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

libdispatch/nchashmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ extern nchashkey_t hash_fast(const char*, size_t length);
6868

6969
#define MAX(a,b) ((a) > (b) ? (a) : (b))
7070

71+
#ifndef SIZE_MAX
72+
#define SIZE_MAX ((size_t)-1)
73+
#endif
74+
7175
/* Forward */
7276
static const unsigned int NC_nprimes;
7377
static const unsigned int NC_primes[16386];
@@ -175,6 +179,7 @@ NC_hashmapnew(size_t startsize)
175179
if(startsize == 0 || startsize < MINTABLESIZE)
176180
startsize = MINTABLESIZE;
177181
else {
182+
if(startsize > SIZE_MAX / 4){nullfree(hm);return 0;}
178183
startsize *= 4;
179184
startsize /= 3;
180185
startsize = findPrimeGreaterThan(startsize);

0 commit comments

Comments
 (0)