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.100; helo=mga07.intel.com; envelope-from=jiaxin.wu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 78EE821962301 for ; Wed, 16 Jan 2019 00:23:09 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 00:23:08 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,485,1539673200"; d="scan'208";a="110273093" Received: from fmsmsx104.amr.corp.intel.com ([10.18.124.202]) by orsmga008.jf.intel.com with ESMTP; 16 Jan 2019 00:23:08 -0800 Received: from fmsmsx126.amr.corp.intel.com (10.18.125.43) by fmsmsx104.amr.corp.intel.com (10.18.124.202) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 00:23:08 -0800 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by FMSMSX126.amr.corp.intel.com (10.18.125.43) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 00:23:08 -0800 Received: from shsmsx107.ccr.corp.intel.com ([169.254.9.239]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.150]) with mapi id 14.03.0415.000; Wed, 16 Jan 2019 16:23:06 +0800 From: "Wu, Jiaxin" To: Laszlo Ersek , "edk2-devel@lists.01.org" CC: "Wu, Hao A" , "Ye, Ting" , "Fu, Siyuan" , "Gao, Liming" Thread-Topic: [edk2] [PATCH v1 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer dereference issue. Thread-Index: AQHUrHFXGDFDCWQ09E+0kqqJHZi046Wvm3iAgAF+eWA= Date: Wed, 16 Jan 2019 08:23:05 +0000 Message-ID: <895558F6EA4E3B41AC93A00D163B727416EC5A13@SHSMSX107.ccr.corp.intel.com> References: <20190115012613.16748-1-Jiaxin.wu@intel.com> <20190115012613.16748-2-Jiaxin.wu@intel.com> <953600c3-5346-3d17-cdaa-9574c3d94d14@redhat.com> In-Reply-To: <953600c3-5346-3d17-cdaa-9574c3d94d14@redhat.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNGJkN2NhOTQtZGNiMC00NzY3LTg3NGMtYjVmM2NkMjdiZTU1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiOE5zMnczZzBjTmxYV0hkcHBzTGRXYUZzcHJSenpJTUEwcVVMTEN6NEd5NDhEZEczTDNsZ2FtVHRvZ0lSdnVOQyJ9 x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.400.15 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [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: Wed, 16 Jan 2019 08:23:09 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Hi Laszlo, Thanks review the patch. >=20 > (1) The linked list from BaseLib (LIST_ENTRY) always has at least one > element (the head element), and the list is empty if the head element > points back to itself. In other words, ForwardLink may never be NULL. >=20 > So why is it necessary to check against that case here? >=20 I agree the ForwardLink in valid LIST_ENTRY can't be NULL. Here, I added th= e more condition check was considering the possible broken case of the LIST= _ENTRY. But I also checked the other usage of *_FOR_EACH_SAFE /*_FOR_EACH, = looks never or unnecessary to consider that case. If so, please drop the series patches and I will create another series pat= ches to remove the unnecessary check after retrieving the value from list E= ntry. > (2) If the NULL check is indeed necessary for some reason, then we > should write >=20 > Entry !=3D (ListHead) && Entry !=3D NULL >=20 > in the controlling expression. Because, with the comma operator, the > (Entry !=3D (ListHead)) expression would be evaluated, but its result > would be ignored. >=20 Yes, I was also awared that, so I created patch v2 to fix that:=20 [edk2] [PATCH v2 1/2] MdeModulePkg/NetLib.h: Fix the possible NULL pointer = dereference issue. Fix the wrong condition in for cycle. Thanks, Jiaxin