public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [PATCH] MdePkg/DebugLib: Add null pointer check to CR macro
@ 2025-01-10  8:19 Richard Lyu via groups.io
  0 siblings, 0 replies; only message in thread
From: Richard Lyu via groups.io @ 2025-01-10  8:19 UTC (permalink / raw)
  To: devel; +Cc: Richard Lyu

- 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: https://github.com/tianocore/edk2/issues/10510

Signed-off-by: Richard Lyu <richard.lyu@suse.com>
---
 MdePkg/Include/Library/DebugLib.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/MdePkg/Include/Library/DebugLib.h b/MdePkg/Include/Library/DebugLib.h
index b48e08a7e4..084714d4d3 100644
--- a/MdePkg/Include/Library/DebugLib.h
+++ b/MdePkg/Include/Library/DebugLib.h
@@ -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) ?                           \
-- 
2.43.0



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#120979): https://edk2.groups.io/g/devel/message/120979
Mute This Topic: https://groups.io/mt/110531848/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2025-01-10  8:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-10  8:19 [edk2-devel] [PATCH] MdePkg/DebugLib: Add null pointer check to CR macro Richard Lyu via groups.io

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox