From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR03-DB5-obe.outbound.protection.outlook.com (mail-oln040092071099.outbound.protection.outlook.com [40.92.71.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 7196A21CB02F6 for ; Sun, 23 Jul 2017 03:08:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=hbobl5k5dzikm7EwscrohsD5HbV6ZnnTP4To87xLYhk=; b=ZcJ7JAnLA87JWgS5w7Uws9DRaefZVfOv82nKB3/dz5o9DzdUvI/B8LNDPL4rY0ikhmouvDpw+T41njdW/mK637duCsTIktAE8ENuVAuqttM4x9q4hI4P74ORhSYvceNFjfdF9aVaT25iNBPnt6TOlycnNhXB8507qFTQU8FdKgqmHZ3DosL5iGdm0qt8WojjV+6ZH8Cn2cSkPt95XskgOtpIiCbxh/fT7P8uYUUTfvq2Tf27QB214e7XIxVfhwEQbSPNe7BIh2qglkBo/Vx7ilb6uo7K4Vpox5thXnUizWN2DEiBJ+HuWRJ+o2x0c0jr+UxI2CD3fX0axPm1JXfgHg== Received: from AM5EUR03FT015.eop-EUR03.prod.protection.outlook.com (10.152.16.59) by AM5EUR03HT072.eop-EUR03.prod.protection.outlook.com (10.152.17.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1240.9; Sun, 23 Jul 2017 10:10:42 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.16.56) by AM5EUR03FT015.mail.protection.outlook.com (10.152.16.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1240.9 via Frontend Transport; Sun, 23 Jul 2017 10:10:42 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::dcd0:60e6:90e0:871b]) by AM4PR06MB1491.eurprd06.prod.outlook.com ([fe80::dcd0:60e6:90e0:871b%13]) with mapi id 15.01.1282.017; Sun, 23 Jul 2017 10:10:42 +0000 From: =?iso-8859-1?Q?Marvin_H=E4user?= To: "edk2-devel@lists.01.org" CC: "michael.d.kinney@intel.com" , "liming.gao@intel.com" Thread-Topic: [PATCH 2/2] MdePkg/BaseLib: Update internal LinkedList verifications. Thread-Index: AQHTA5vxnBYIcy+OY06LVjAafmMCwQ== Date: Sun, 23 Jul 2017 10:10:42 +0000 Message-ID: References: <20170723101022.3780-1-Marvin.Haeuser@outlook.com> In-Reply-To: <20170723101022.3780-1-Marvin.Haeuser@outlook.com> Accept-Language: de-DE, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: lists.01.org; dkim=none (message not signed) header.d=none;lists.01.org; dmarc=none action=none header.from=outlook.com; x-incomingtopheadermarker: OriginalChecksum:FF85CD52EA8714B1B382FB2592A90FB811FF1FDD891FEA5D37263662A9F7EA7D; UpperCasedChecksum:6A93383E49CACD97156FBE2B84DAADB706D299E573115BA92A051E87652580CE; SizeAsReceived:7397; Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [z5yxKs2US1+Y90/ulJc4obZh9toULqJg] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; AM5EUR03HT072; 7:v38Fb2O17QiMZ7sOEGN4DVDD9X4UF/Q6DGp6E3UpgEBBPsiaDOc1RoUUXkqKo845tMPB7x7WwKZQhi8GJdK6QgG92IG78qkNHny9cE6aErvdmvnsMCOmtKO7NEi+Q9lo6ULvIkVA0cISZKGYK9Ynj/0NsGa/TEgk3xM48cyE9DKD4/tNkRP3GmEpPKJawAIvuxoyUchI/jpIxoh6dLFAJHXd7XmCjCQae8WR26RkXTKLRsvx1z+gk24kHSWYU4opFrDk01M0LoarO3uZRe8yoYxIRruafArj7hudOFy+b65j3fStsb7LyWter8flX0AQnvVBinp9ZcFP0GpvHmhJ7npYwEqrVj7o35Iphy15Avd17MHSxktW4D0WK810pwX30Rr/XT09wnL/zWMZKfUSVW29ZYQKHAjhCgtI26giknu4VQIj16br2IedtGR/bDC1M8bGlmLOA8yea2BJHMzw2CZpmXM046EqdsZs6LMFk00zNLN0PT+nl7yJ2HdOd/b1dh/qpMqyNDqeWUf0rt9kjHc2WnJqM2gMu7pF8sLYxBUrOgFDYYx0bjjAhskJOOJJfNkARFnMsI3dALAOjSaOqFF343TWXTDbb1Qrnl6oTdlcFZrumbAqMQjDodtg+cX/gDmywG8LTv4FyadKKGO8ZGxvxMlbCol6P5XOmBqtQAbNdLpJUDTYRfdKY9HoKhh/tRtVMF2t539eGzs99/X5aw1y2/UVQ5iYrLtocTPNb03ibf3e+vRnLfRuzxWKLLXjFX+S5pg9DZq09LTA9L4SrQ== x-incomingheadercount: 46 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:AM5EUR03HT072; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: 02bd9423-4d93-446c-2b2c-08d4d1b31361 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(22001)(300000502095)(300135100095)(300000503095)(300135400095)(201702061074)(5061506573)(5061507331)(1603103135)(2017031320274)(2017031324274)(2017031323274)(2017031322350)(1603101448)(1601125374)(1701031045)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:AM5EUR03HT072; x-ms-traffictypediagnostic: AM5EUR03HT072: x-exchange-antispam-report-test: UriScan:(189930954265078)(788757137089); x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(444000031); SRVR:AM5EUR03HT072; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5EUR03HT072; x-forefront-prvs: 0377802854 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jul 2017 10:10:42.5725 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5EUR03HT072 Subject: [PATCH 2/2] MdePkg/BaseLib: Update internal LinkedList verifications. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 23 Jul 2017 10:08:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable 1) Replace InternalBaseLibIsNodeInList() with InternalBaseLibIsListValid(). - The verification whether Node is within the doubly-linked List is now done by IsNodeInList(). - Whether the list is valid is returned. 2) The comments within InsertHeadList() and InsertTailList() stated that it is checked whether Entry is not part of the doubly-linked list. This was not done as argument 3 of InternalBaseLibIsNodeInList() indicated whether the check is done, not whether to check if the node is or is not in the list. This has been fixed by using IsNodeInList() for the ASSERTs. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Library/BaseLib/LinkedList.c | 79 +++++--------------- 1 file changed, 19 insertions(+), 60 deletions(-) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/L= inkedList.c index b364ae41c647..e3734fd85057 100644 --- a/MdePkg/Library/BaseLib/LinkedList.c +++ b/MdePkg/Library/BaseLib/LinkedList.c @@ -15,25 +15,15 @@ #include "BaseLibInternals.h" =20 /** - Worker function that locates the Node in the List. - - By searching the List, finds the location of the Node in List. At the sa= me time, - verifies the validity of this list. + Worker function that verifies the validity of this list. =20 If List is NULL, then ASSERT(). If List->ForwardLink is NULL, then ASSERT(). - If List->backLink is NULL, then ASSERT(). - If Node is NULL, then ASSERT(). - If PcdVerifyNodeInList is TRUE and DoMembershipCheck is TRUE and Node=20 - is in not a member of List, then return FALSE + If List->BackLink is NULL, then ASSERT(). If PcdMaximumLinkedListLength is not zero, and List contains more than PcdMaximumLinkedListLength nodes, then ASSERT(). =20 @param List A pointer to a node in a linked list. - @param Node A pointer to a node in a linked list. - @param VerifyNodeInList TRUE if a check should be made to see if Node = is a=20 - member of List. FALSE if no membership test s= hould=20 - be performed. =20 @retval TRUE if PcdVerifyNodeInList is FALSE @retval TRUE if DoMembershipCheck is FALSE @@ -45,10 +35,8 @@ **/ BOOLEAN EFIAPI -InternalBaseLibIsNodeInList ( - IN CONST LIST_ENTRY *List, - IN CONST LIST_ENTRY *Node, - IN BOOLEAN VerifyNodeInList +InternalBaseLibIsListValid ( + IN CONST LIST_ENTRY *List ) { UINTN Count; @@ -60,40 +48,11 @@ InternalBaseLibIsNodeInList ( ASSERT (List !=3D NULL); ASSERT (List->ForwardLink !=3D NULL); ASSERT (List->BackLink !=3D NULL); - ASSERT (Node !=3D NULL); - - Count =3D 0; - Ptr =3D List; - - if (FeaturePcdGet (PcdVerifyNodeInList) && VerifyNodeInList) { - // - // Check to see if Node is a member of List. =20 - // Exit early if the number of nodes in List >=3D PcdMaximumLinkedList= Length - // - do { - Ptr =3D Ptr->ForwardLink; - if (PcdGet32 (PcdMaximumLinkedListLength) > 0) { - Count++; - // - // ASSERT() if the linked list is too long - // - ASSERT (Count < PcdGet32 (PcdMaximumLinkedListLength)); - - // - // Return if the linked list is too long - // - if (Count >=3D PcdGet32 (PcdMaximumLinkedListLength)) { - return (BOOLEAN)(Ptr =3D=3D Node); - } - } - } while ((Ptr !=3D List) && (Ptr !=3D Node));=20 - - if (Ptr !=3D Node) { - return FALSE; - } - } =20 if (PcdGet32 (PcdMaximumLinkedListLength) > 0) { + Count =3D 0; + Ptr =3D List; + // // Count the total number of nodes in List. // Exit early if the number of nodes in List >=3D PcdMaximumLinkedList= Length @@ -104,9 +63,9 @@ InternalBaseLibIsNodeInList ( } while ((Ptr !=3D List) && (Count < PcdGet32 (PcdMaximumLinkedListLen= gth))); =20 // - // ASSERT() if the linked list is too long + // return whether linked list is too long // - ASSERT (Count < PcdGet32 (PcdMaximumLinkedListLength)); + return (BOOLEAN)(Count < PcdGet32 (PcdMaximumLinkedListLength)); } =20 return TRUE; @@ -150,7 +109,7 @@ IsNodeInList ( // // ASSERT List not too long // - ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + ASSERT (InternalBaseLibIsListValid (List)); =20 Count =3D 0; Ptr =3D List; @@ -242,7 +201,7 @@ InsertHeadList ( // // ASSERT List not too long and Entry is not one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + ASSERT (!IsNodeInList (ListHead, Entry)); =20 Entry->ForwardLink =3D ListHead->ForwardLink; Entry->BackLink =3D ListHead; @@ -283,7 +242,7 @@ InsertTailList ( // // ASSERT List not too long and Entry is not one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + ASSERT (!IsNodeInList (ListHead, Entry)); =20 Entry->ForwardLink =3D ListHead; Entry->BackLink =3D ListHead->BackLink; @@ -321,7 +280,7 @@ GetFirstNode ( // // ASSERT List not too long // - ASSERT (InternalBaseLibIsNodeInList (List, List, FALSE)); + ASSERT (InternalBaseLibIsListValid (List)); =20 return List->ForwardLink; } @@ -357,7 +316,7 @@ GetNextNode ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (IsNodeInList (List, Node)); =20 return Node->ForwardLink; } @@ -393,7 +352,7 @@ GetPreviousNode ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (IsNodeInList (List, Node)); =20 return Node->BackLink; } @@ -426,7 +385,7 @@ IsListEmpty ( // // ASSERT List not too long // - ASSERT (InternalBaseLibIsNodeInList (ListHead, ListHead, FALSE)); + InternalBaseLibIsListValid (ListHead); =20 return (BOOLEAN)(ListHead->ForwardLink =3D=3D ListHead); } @@ -467,7 +426,7 @@ IsNull ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (IsNodeInList (List, Node)); =20 return (BOOLEAN)(Node =3D=3D List); } @@ -505,7 +464,7 @@ IsNodeAtEnd ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (IsNodeInList (List, Node)); =20 return (BOOLEAN)(!IsNull (List, Node) && List->BackLink =3D=3D Node); } @@ -552,7 +511,7 @@ SwapListEntries ( // // ASSERT Entry1 and Entry2 are in the same linked list // - ASSERT (InternalBaseLibIsNodeInList (FirstEntry, SecondEntry, TRUE)); + ASSERT (IsNodeInList (FirstEntry, SecondEntry)); =20 // // Ptr is the node pointed to by FirstEntry->ForwardLink --=20 2.12.2.windows.2