1
0
mirror of https://github.com/roytam1/UXP.git synced 2026-05-26 13:58:49 +00:00

[memory] Guard OOM reporter from incorrectly reported (too small) size.

This commit is contained in:
Moonchild
2023-09-26 21:07:29 +02:00
committed by roytam1
parent 0548a39ff3
commit 1f7d8d3a36
+3 -1
View File
@@ -64,6 +64,7 @@ extern "C" MOZ_MEMORY_API char *strndup_impl(const char *, size_t);
#include <sys/types.h>
#include "mozilla/CheckedInt.h"
#include "mozilla/Likely.h"
#include "mozilla/mozalloc.h"
#include "mozilla/mozalloc_oom.h" // for mozalloc_handle_oom
@@ -84,7 +85,8 @@ moz_xcalloc(size_t nmemb, size_t size)
{
void* ptr = calloc_impl(nmemb, size);
if (MOZ_UNLIKELY(!ptr && nmemb && size)) {
mozalloc_handle_oom(size);
mozilla::CheckedInt<size_t> totalSize = mozilla::CheckedInt<size_t>(nmemb) * size;
mozalloc_handle_oom(totalSize.isValid() ? totalSize.value() : SIZE_MAX);
return moz_xcalloc(nmemb, size);
}
return ptr;