Skip to content

Commit

Permalink
Merge pull request #212 from mikolajkolakowski/pbr_parser_crash_2_0
Browse files Browse the repository at this point in the history
PBR crash fix for 2_0 code base
  • Loading branch information
nolanhergert authored Jun 5, 2024
2 parents 0f2e924 + 14ff66b commit 0847aee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions DcpmPkg/common/Pbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,13 @@ PbrComposeSession(
}

pPbrMainHeader = (PbrHeader *)pContext->PbrMainHeader;

if (pPbrMainHeader == NULL)
{
// bailout if PBR session is not initialized
return EFI_NOT_FOUND;
}

ZeroMem(&pPbrMainHeader->PartitionTable, sizeof(PbrPartitionTable));
BufferSize = sizeof(PbrHeader);

Expand Down
11 changes: 11 additions & 0 deletions DcpmPkg/common/PbrOs.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ VOID DeserializePbrMode(UINT32 *pMode, UINT32 defaultMode);
if(NULL == buffer) { \
NVDIMM_ERR("Failed to allocate memory for deserializing buffer\n"); \
} \
else \
if (1 != fread(buffer, size, 1, pFile)) \
{ \
NVDIMM_ERR("Failed to read the PBR file: %s\n", file); \
Expand Down Expand Up @@ -222,7 +223,17 @@ EFI_STATUS PbrDeserializeCtx(
if (PBR_INVALID_SIG != ctx->PartitionContexts[CtxIndex].PartitionSig) {
AsciiSPrint(pbr_filename, sizeof(pbr_filename), "%x.pbr", ctx->PartitionContexts[CtxIndex].PartitionSig);
AsciiSPrint(pbr_dir, sizeof(pbr_dir), "%s%s", PBR_TMP_DIR, pbr_filename);

ctx->PartitionContexts[CtxIndex].PartitionData = NULL; // initialize buffer to NULL to allow proper error handling in case of fail to open pbr_dir file
DeserializeBufferEx(pbr_dir, ctx->PartitionContexts[CtxIndex].PartitionData, ctx->PartitionContexts[CtxIndex].PartitionSize);

if(ctx->PartitionContexts[CtxIndex].PartitionData == NULL)
{
// we do not free already allocated memory because OS will free it after process exit
NVDIMM_ERR("PBR context file corrupted, please remove "PBR_TMP_DIR PBR_CTX_FILE_NAME"\n");
ReturnCode = EFI_END_OF_FILE;
goto Finish;
}
}
}

Expand Down

0 comments on commit 0847aee

Please sign in to comment.