Skip to content

Commit

Permalink
MdePkg/DebugLib: Add null pointer check to CR macro
Browse files Browse the repository at this point in the history
- Added a null pointer check in the CR macro.
- If Record is NULL, an assertion is triggered.
- This change improves the CR by preventing dereferencing of null pointers.

REF: #10510

Signed-off-by: Richard Lyu <[email protected]>
  • Loading branch information
r1chard-lyu committed Jan 7, 2025
1 parent f6e19ab commit d2a9618
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion MdePkg/Include/Library/DebugLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,11 +657,12 @@ UnitTestDebugAssert (
**/
#if !defined (MDEPKG_NDEBUG)
#define CR(Record, TYPE, Field, TestSignature) \
((Record == NULL) ? (TYPE *) (_ASSERT (CR has Null Pointer), Record) : \
(DebugAssertEnabled () && (BASE_CR (Record, TYPE, Field)->Signature != TestSignature)) ? \
(TYPE *) (_ASSERT (CR has Bad Signature), Record) : \
(BASE_CR (Record, TYPE, Field)->Signature != TestSignature) ? \
NULL : \
BASE_CR (Record, TYPE, Field)
BASE_CR (Record, TYPE, Field))
#else
#define CR(Record, TYPE, Field, TestSignature) \
(BASE_CR (Record, TYPE, Field)->Signature != TestSignature) ? \
Expand Down

0 comments on commit d2a9618

Please sign in to comment.