https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1d6ec8555d98976f6492a…
commit 1d6ec8555d98976f6492ad07a4ca304f1b404372
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Wed Apr 27 11:11:49 2016 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Thu Feb 2 14:58:08 2023 +0100
[WINESYNC] msvcrt: Handle overflow in calloc().
Signed-off-by: Nikolay Sivov <nsivov(a)codeweavers.com>
Signed-off-by: Piotr Caban <piotr(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
wine commit id 50dd4b892825c75db35cd1f378291b51fa782f3e by Nikolay Sivov
<nsivov(a)codeweavers.com>
---
sdk/lib/crt/wine/heap.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/sdk/lib/crt/wine/heap.c b/sdk/lib/crt/wine/heap.c
index 5cf7d6bd4ee..1b7eb529f31 100644
--- a/sdk/lib/crt/wine/heap.c
+++ b/sdk/lib/crt/wine/heap.c
@@ -418,7 +418,15 @@ size_t CDECL _aligned_msize(void *p, MSVCRT_size_t alignment,
MSVCRT_size_t offs
*/
void* CDECL MSVCRT_calloc(MSVCRT_size_t count, MSVCRT_size_t size)
{
- return msvcrt_heap_alloc(HEAP_ZERO_MEMORY, count*size);
+ MSVCRT_size_t bytes = count*size;
+
+ if (size && bytes / size != count)
+ {
+ *MSVCRT__errno() = MSVCRT_ENOMEM;
+ return NULL;
+ }
+
+ return msvcrt_heap_alloc(HEAP_ZERO_MEMORY, bytes);
}
/*********************************************************************