From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 8D336211B5A43 for ; Mon, 14 Jan 2019 17:26:20 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 14 Jan 2019 17:26:20 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,479,1539673200"; d="scan'208";a="108265572" Received: from jiaxinwu-mobl.ccr.corp.intel.com ([10.239.193.52]) by orsmga006.jf.intel.com with ESMTP; 14 Jan 2019 17:26:18 -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 09:26:12 +0800 Message-Id: <20190115012613.16748-2-Jiaxin.wu@intel.com> X-Mailer: git-send-email 2.17.1.windows.2 In-Reply-To: <20190115012613.16748-1-Jiaxin.wu@intel.com> References: <20190115012613.16748-1-Jiaxin.wu@intel.com> Subject: [PATCH v1 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 01:26:20 -0000 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..5b1307553a 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