Skip to content

Commit e568656

Browse files
authored
Merge pull request #4613 from nidu-ninja/null-deref-custom-calloc
Fix potential NULL pointer dereference in ZSTD_customCalloc when cust…
2 parents c84c8fb + 3f8f9b3 commit e568656

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

lib/common/allocations.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,13 @@ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
3333
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
3434
{
3535
if (customMem.customAlloc) {
36-
/* calloc implemented as malloc+memset;
37-
* not as efficient as calloc, but next best guess for custom malloc */
36+
/* calloc implemented as malloc+memset */
3837
void* const ptr = customMem.customAlloc(customMem.opaque, size);
38+
39+
if (ptr == NULL) {
40+
return NULL;
41+
}
42+
3943
ZSTD_memset(ptr, 0, size);
4044
return ptr;
4145
}

0 commit comments

Comments
 (0)