Merge pull request #4613 from nidu-ninja/null-deref-custom-calloc
Fix potential NULL pointer dereference in ZSTD_customCalloc when cust…
This commit is contained in:
@@ -33,9 +33,13 @@ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
|||||||
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
||||||
{
|
{
|
||||||
if (customMem.customAlloc) {
|
if (customMem.customAlloc) {
|
||||||
/* calloc implemented as malloc+memset;
|
/* calloc implemented as malloc+memset */
|
||||||
* not as efficient as calloc, but next best guess for custom malloc */
|
|
||||||
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
||||||
|
|
||||||
|
if (ptr == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ZSTD_memset(ptr, 0, size);
|
ZSTD_memset(ptr, 0, size);
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user