Skip to content

Commit 77be323

Browse files
committed
fix wrong checks introduced during code analysis cleanup
1 parent aa4301a commit 77be323

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

lib/Backend/Encoder.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ Encoder::Encode()
372372
if (this->m_func->IsOOPJIT())
373373
{
374374
pinnedTypeRefs = (PinnedTypeRefsIDL*)midl_user_allocate(offsetof(PinnedTypeRefsIDL, typeRefs) + sizeof(void*)*pinnedTypeRefCount);
375+
if (!pinnedTypeRefs)
376+
{
377+
Js::Throw::OutOfMemory();
378+
}
379+
__analysis_assume(pinnedTypeRefs);
380+
375381
pinnedTypeRefs->count = pinnedTypeRefCount;
376382
pinnedTypeRefs->isOOPJIT = true;
377383
this->m_func->GetJITOutput()->GetOutputData()->pinnedTypeRefs = pinnedTypeRefs;
@@ -538,7 +544,7 @@ Encoder::Encode()
538544
{
539545
auto count = srcSet->Count();
540546
(*entry) = (TypeGuardTransferEntryIDL*)midl_user_allocate(offsetof(TypeGuardTransferEntryIDL, guardOffsets) + count*sizeof(int));
541-
if (*entry)
547+
if (!*entry)
542548
{
543549
Js::Throw::OutOfMemory();
544550
}
@@ -584,12 +590,17 @@ Encoder::Encode()
584590
m_func->GetJITOutput()->GetOutputData()->ctorCachesCount = propertyCount;
585591
m_func->GetJITOutput()->GetOutputData()->ctorCacheEntries = (CtorCacheTransferEntryIDL**)midl_user_allocate(propertyCount * sizeof(CtorCacheTransferEntryIDL*));
586592
CtorCacheTransferEntryIDL** entries = m_func->GetJITOutput()->GetOutputData()->ctorCacheEntries;
593+
if (!entries)
594+
{
595+
Js::Throw::OutOfMemory();
596+
}
597+
__analysis_assume(entries);
587598

588599
uint propIndex = 0;
589600
m_func->ctorCachesByPropertyId->Map([func, entries, &propIndex](Js::PropertyId propertyId, Func::CtorCacheSet* srcCacheSet) -> void
590601
{
591602
entries[propIndex] = (CtorCacheTransferEntryIDL*)midl_user_allocate(srcCacheSet->Count() * sizeof(intptr_t) + sizeof(CtorCacheTransferEntryIDL));
592-
if (entries[propIndex])
603+
if (!entries[propIndex])
593604
{
594605
Js::Throw::OutOfMemory();
595606
}

lib/Backend/Func.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,14 +577,20 @@ Func::TryCodegen()
577577
JITOutputIDL* jitOutputData = m_output.GetOutputData();
578578
size_t allocSize = offsetof(NativeDataFixupTable, fixupRecords) + sizeof(NativeDataFixupRecord)* (dataAllocator->allocCount);
579579
jitOutputData->nativeDataFixupTable = (NativeDataFixupTable*)midl_user_allocate(allocSize);
580-
if (jitOutputData->nativeDataFixupTable)
580+
if (!jitOutputData->nativeDataFixupTable)
581581
{
582582
Js::Throw::OutOfMemory();
583583
}
584584
__analysis_assume(jitOutputData->nativeDataFixupTable);
585585
jitOutputData->nativeDataFixupTable->count = dataAllocator->allocCount;
586586

587587
jitOutputData->buffer = (NativeDataBuffer*)midl_user_allocate(offsetof(NativeDataBuffer, data) + dataAllocator->totalSize);
588+
if (!jitOutputData->buffer)
589+
{
590+
Js::Throw::OutOfMemory();
591+
}
592+
__analysis_assume(jitOutputData->buffer);
593+
588594
jitOutputData->buffer->len = dataAllocator->totalSize;
589595

590596
unsigned int len = 0;

lib/Backend/NativeCodeData.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ NativeCodeData::AddFixupEntry(void* targetAddr, void* targetStartAddr, void* add
6969
DataChunk* chunk = NativeCodeData::GetDataChunk(startAddress);
7070

7171
NativeDataFixupEntry* entry = (NativeDataFixupEntry*)midl_user_allocate(sizeof(NativeDataFixupEntry));
72-
if (entry)
72+
if (!entry)
7373
{
7474
Js::Throw::OutOfMemory();
7575
}
@@ -119,7 +119,7 @@ NativeCodeData::AddFixupEntryForPointerArray(void* startAddress, DataChunk * chu
119119
#endif
120120

121121
NativeDataFixupEntry* entry = (NativeDataFixupEntry*)midl_user_allocate(sizeof(NativeDataFixupEntry));
122-
if (entry)
122+
if (!entry)
123123
{
124124
Js::Throw::OutOfMemory();
125125
}

lib/Backend/NativeCodeGenerator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ NativeCodeGenerator::CodeGen(PageAllocator * pageAllocator, CodeGenWorkItem* wor
905905
case E_ABORT:
906906
throw Js::OperationAbortedException();
907907
case E_OUTOFMEMORY:
908-
throw Js::OutOfMemoryException();
908+
Js::Throw::OutOfMemory();
909909
case VBSERR_OutOfStack:
910910
throw Js::StackOverflowException();
911911
default:

lib/JITServer/JITServer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,15 @@ ServerRemoteCodeGen(
412412
#endif
413413

414414
jitData->numberPageSegments = (XProcNumberPageSegment*)midl_user_allocate(sizeof(XProcNumberPageSegment));
415+
if (!jitData->numberPageSegments)
416+
{
417+
scriptContextInfo->EndJIT();
418+
threadContextInfo->EndJIT();
419+
420+
return E_OUTOFMEMORY;
421+
}
422+
__analysis_assume(jitData->numberPageSegments);
423+
415424
memcpy_s(jitData->numberPageSegments, sizeof(XProcNumberPageSegment), jitWorkItem->GetWorkItemData()->xProcNumberPageSegment, sizeof(XProcNumberPageSegment));
416425

417426
HRESULT hr = S_OK;
@@ -433,14 +442,17 @@ ServerRemoteCodeGen(
433442
}
434443
catch (Js::OutOfMemoryException)
435444
{
445+
memset(jitData, 0, sizeof(JITOutputIDL));
436446
hr = E_OUTOFMEMORY;
437447
}
438448
catch (Js::StackOverflowException)
439449
{
450+
memset(jitData, 0, sizeof(JITOutputIDL));
440451
hr = VBSERR_OutOfStack;
441452
}
442453
catch (Js::OperationAbortedException)
443454
{
455+
memset(jitData, 0, sizeof(JITOutputIDL));
444456
hr = E_ABORT;
445457
}
446458
scriptContextInfo->EndJIT();

0 commit comments

Comments
 (0)