From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.120; helo=mga04.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 158C4211B63F0 for ; Tue, 15 Jan 2019 00:20:25 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2019 00:20:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,481,1539673200"; d="scan'208";a="311911474" Received: from jiaxinwu-mobl.ccr.corp.intel.com ([10.239.193.52]) by fmsmga005.fm.intel.com with ESMTP; 15 Jan 2019 00:20:24 -0800 From: Jiaxin Wu To: edk2-devel@lists.01.org Cc: Wu Hao A , Gao Liming , Ye Ting , Fu Siyuan , Wu Jiaxin Date: Tue, 15 Jan 2019 16:20:18 +0800 Message-Id: <20190115082018.1392-1-Jiaxin.wu@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 Subject: [PATCH v2 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer dereference issue. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Jan 2019 08:20:26 -0000 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 Cc: Gao Liming Cc: Ye Ting Cc: Fu Siyuan Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Wu Jiaxin --- 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