Skip to content

Commit

Permalink
Ensure pTmpBuf does not leak if MDL allocation fails
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Jun 9, 2021
1 parent 7562900 commit ba8bd43
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packetWin7/npf/npf/Loopback.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ NPF_TapLoopback(
RtlCopyMemory(pTmpBuf + numBytes, pOrigBuf + Offset, OrigLen - Offset);
pMdl = NdisAllocateMdl(pLoopbackFilter->AdapterHandle, pTmpBuf, FirstMDLLen);
if (pMdl == NULL) {
NdisFreeMemory(pTmpBuf, FirstMDLLen, 0);
TRACE_MESSAGE(PACKET_DEBUG_LOUD,
"NPF_TapLoopback: Failed to allocate MDL.");
break;
Expand Down Expand Up @@ -317,11 +318,11 @@ NPF_TapLoopback(
pMdl = (PMDL)(NET_BUFFER_PROTOCOL_RESERVED(pFakeNetBuffer)[0]);

if (pMdl != NULL) {
/* If the MDL's buffer is numBytes long, it's npBuff and we'll free it later.
/* If it's npBuff, we'll free it later.
* Otherwise it's unique and we should free it now. */
FirstMDLLen = MmGetMdlByteCount(pMdl);
if (FirstMDLLen != numBytes) {
pTmpBuf = MmGetSystemAddressForMdlSafe(pMdl, HighPagePriority|MdlMappingNoExecute);
NdisQueryMdl(pMdl, &pTmpBuf, &FirstMDLLen, HighPagePriority|MdlMappingNoExecute);
if (pTmpBuf != npBuff)
{
// See NPF_FreeNBCopies for TODO item related to this assert and
// justification for HighPagePriority above.
if (NT_VERIFY(pTmpBuf != NULL)) {
Expand Down

0 comments on commit ba8bd43

Please sign in to comment.