mirror of
https://gitlab.gnome.org/GNOME/libxml2
synced 2025-03-28 21:33:13 +00:00
fuzz: Also set fuzzAllocFailed if a real allocation fails
Avoid false positives in real OOM situations.
This commit is contained in:
parent
20b0bd9800
commit
971ce40409
22
fuzz/fuzz.c
22
fuzz/fuzz.c
@ -68,6 +68,8 @@ xmlFuzzErrorFunc(void *ctx ATTRIBUTE_UNUSED, const char *msg ATTRIBUTE_UNUSED,
|
||||
|
||||
static void *
|
||||
xmlFuzzMalloc(size_t size) {
|
||||
void *ret;
|
||||
|
||||
if (fuzzMaxAllocs > 0) {
|
||||
fuzzNumAllocs += 1;
|
||||
if (fuzzNumAllocs == fuzzMaxAllocs) {
|
||||
@ -75,14 +77,21 @@ xmlFuzzMalloc(size_t size) {
|
||||
abort();
|
||||
#endif
|
||||
fuzzAllocFailed = 1;
|
||||
return(NULL);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return malloc(size);
|
||||
|
||||
ret = malloc(size);
|
||||
if (ret == NULL)
|
||||
fuzzAllocFailed = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void *
|
||||
xmlFuzzRealloc(void *ptr, size_t size) {
|
||||
void *ret;
|
||||
|
||||
if (fuzzMaxAllocs > 0) {
|
||||
fuzzNumAllocs += 1;
|
||||
if (fuzzNumAllocs == fuzzMaxAllocs) {
|
||||
@ -90,10 +99,15 @@ xmlFuzzRealloc(void *ptr, size_t size) {
|
||||
abort();
|
||||
#endif
|
||||
fuzzAllocFailed = 1;
|
||||
return(NULL);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return realloc(ptr, size);
|
||||
|
||||
ret = realloc(ptr, size);
|
||||
if (ret == NULL)
|
||||
fuzzAllocFailed = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
|
Loading…
x
Reference in New Issue
Block a user