Skip to content

Commit 2cff916

Browse files
committed
cryptopp: Fixing an infinite loop scenario in case of memory exhaustion
Cherry-pick 1c9262735a87ec6f029e4a875f77dd9f7634c31f from upstream PR
1 parent 7b58ea9 commit 2cff916

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

vendor/cryptopp/allocate.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void CallNewHandler()
3939

4040
void * AlignedAllocate(size_t size)
4141
{
42+
unsigned int cnt = 0;
4243
byte *p;
4344
#if defined(CRYPTOPP_MM_MALLOC_AVAILABLE)
4445
while ((p = (byte *)_mm_malloc(size, 16)) == NULLPTR)
@@ -51,8 +52,12 @@ void * AlignedAllocate(size_t size)
5152
#else
5253
while ((p = (byte *)malloc(size + 16)) == NULLPTR)
5354
#endif
54-
CallNewHandler();
55-
55+
{
56+
if (cnt >= 10)
57+
throw std::bad_alloc();
58+
CallNewHandler();
59+
cnt++;
60+
}
5661
#ifdef CRYPTOPP_NO_ALIGNED_ALLOC
5762
size_t adjustment = 16-((size_t)p%16);
5863
CRYPTOPP_ASSERT(adjustment > 0);

0 commit comments

Comments
 (0)