public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v2 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer dereference issue.
@ 2019-01-15  8:20 Jiaxin Wu
  0 siblings, 0 replies; only message in thread
From: Jiaxin Wu @ 2019-01-15  8:20 UTC (permalink / raw)
  To: edk2-devel; +Cc: Wu Hao A, Gao Liming, Ye Ting, Fu Siyuan, Wu Jiaxin

v2: Fix the wrong condition in for cycle.

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1456

For the NET_LIST_FOR_EACH & NET_LIST_FOR_EACH_SAFE, "Entry" should be
checked whether it's NULL or not instead of using the pointer directly.

Cc: Wu Hao A <hao.a.wu@intel.com>
Cc: Gao Liming <liming.gao@intel.com>
Cc: Ye Ting <ting.ye@intel.com>
Cc: Fu Siyuan <siyuan.fu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Wu Jiaxin <jiaxin.wu@intel.com>
---
 MdeModulePkg/Include/Library/NetLib.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/MdeModulePkg/Include/Library/NetLib.h b/MdeModulePkg/Include/Library/NetLib.h
index 0977973921..c9a86733ec 100644
--- a/MdeModulePkg/Include/Library/NetLib.h
+++ b/MdeModulePkg/Include/Library/NetLib.h
@@ -616,21 +616,21 @@ NetRandomInitSeed (
 
 //
 // Iterate through the double linked list. It is NOT delete safe
 //
 #define NET_LIST_FOR_EACH(Entry, ListHead) \
-  for(Entry = (ListHead)->ForwardLink; Entry != (ListHead); Entry = Entry->ForwardLink)
+  for(Entry = (ListHead)->ForwardLink; Entry != (ListHead) && Entry != NULL; Entry = Entry->ForwardLink)
 
 //
 // Iterate through the double linked list. This is delete-safe.
 // Don't touch NextEntry. Also, don't use this macro if list
 // entries other than the Entry may be deleted when processing
 // the current Entry.
 //
 #define NET_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \
-  for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink; \
-      Entry != (ListHead); \
+  for(Entry = (ListHead)->ForwardLink, (Entry != NULL) ? (NextEntry = Entry->ForwardLink) : (Entry = NULL); \
+      Entry != (ListHead) && Entry != NULL; \
       Entry = NextEntry, NextEntry = Entry->ForwardLink \
      )
 
 //
 // Make sure the list isn't empty before getting the first/last record.
-- 
2.17.1.windows.2



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

only message in thread, other threads:[~2019-01-15  8:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-15  8:20 [PATCH v2 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer dereference issue Jiaxin Wu

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