- 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....@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/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to