From: "Richard Lyu via groups.io" <richard.lyu=suse.com@groups.io>
To: devel@edk2.groups.io
Cc: Richard Lyu <richard.lyu@suse.com>
Subject: [edk2-devel] [PATCH] MdePkg/DebugLib: Add null pointer check to CR macro
Date: Fri, 10 Jan 2025 16:19:23 +0800 [thread overview]
Message-ID: <20250110081608.26400-3-richard.lyu@suse.com> (raw)
- 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]
-=-=-=-=-=-=-=-=-=-=-=-
reply other threads:[~2025-01-10 8:19 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250110081608.26400-3-richard.lyu@suse.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox