From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-oln040092065013.outbound.protection.outlook.com [40.92.65.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 93C8B2095DB8D for ; Wed, 2 Aug 2017 06:09:52 -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=bUGB7jdx5pXAg/7dhgbIETD2kptqFV2VDHN874kGA64=; b=MHnluFHHM9MCmn3fIbgNzpb+lkq4LjBkt+tisyEPyB4rdF8dZhEyZ6R1XlER2PYXXULP3gm2e3pEXMzhTOF1F4NLSokb6iBfEd+1+M6qKRY5BIKNNm1lhwK66ceqAnuyfbaCvPFd9QZI4o7dGlg456NH5Zbh9nxyoxfsc0EXngn6vM64mqOmXRzjArrjOZgJJLEPVdpl2eT3qK9TsYx+vWx068A2MHyz8KSuI/M/WgCEnEzIAwhCCrH7m+u1Qo7MiIKFJE3IRdh7BpCQEa8ITjdXlcGKLUS0B4dETgAQO9lT2APeImJDUXwRbtx+SsTrwmA3TlEEKtj0Gr9YYATkyg== Received: from VE1EUR01FT035.eop-EUR01.prod.protection.outlook.com (10.152.2.52) by VE1EUR01HT247.eop-EUR01.prod.protection.outlook.com (10.152.3.233) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.1240.9; Wed, 2 Aug 2017 13:12:01 +0000 Received: from AM4PR06MB1491.eurprd06.prod.outlook.com (10.152.2.58) by VE1EUR01FT035.mail.protection.outlook.com (10.152.2.236) 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; Wed, 2 Aug 2017 13:12:00 +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.1304.023; Wed, 2 Aug 2017 13:12:00 +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 v2 2/2] MdePkg/BaseLib: Update internal LinkedList verifications. Thread-Index: AQHTC5DsjyJXg/Rms0aldga9ZPjpbg== Date: Wed, 2 Aug 2017 13:12:00 +0000 Message-ID: References: <20170802131136.3128-1-Marvin.Haeuser@outlook.com> In-Reply-To: <20170802131136.3128-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:C0820719DFA7DA459148BB8B8AA54D2A234D8A506BB3314061CFEC2DAB2E501E; UpperCasedChecksum:CDE1D0C78BFC65B5A3D534A801204BF7E5DB5D821839E6A4B0F41C6FF07B1F04; SizeAsReceived:7404; Count:46 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [T+fLmz3MqflS5Ejlsq0kNoizc/+7Dwch] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1; VE1EUR01HT247; 7:R3hAbf2WQt39b+zJddMkxNN9nQx2+SjosvgbSayuk/NNx0ZWkZHIMLb4SfuBXNkinxB5aF0LVNW3u2T8ozQ1GywfbqhSJXpq02SN/kZf7E8oRuhdxUZ2U5xfKhcsmq7idAiMO1qtR2eSoCE3LiiAKAm7Is0AjnLTv4qM7HB7fx1oWvVK/TjetVzAQ8xgUMd/QSTgtK9xtTdfHo2lvLZ+RgcSMGCARBF3Vvm2fffl3t/PajAszvBWcvLppOQtNu8X0VDfbAZup3VjAL5K8wLbs7AEAeMfIabF0HgtTZuKMEpk3KS6lMTRKud1E9Z05/JYBzx8ld4kLsq2B2XAhhOeJabt94SIJFUNHYX7AKgQXPXx37XR14CDQ9062lnKtcIsQ/+KTvjl0mSUyR3e7t00toGPgYW0RT+cKRNgOX7gi9Qzs4nfx/eTOCLppq6kV3edt3ABhb6rT/Zb5vqFBoqxOfpzLa/wlegZ5PzGNFvzh8JfmH6Vvi73ygbXcJF8lZhyn2TDH0f6mr3h76iEKY64WEJGDLZexGEvj4lZJKZWrjKYf3+vqo8Og5uf5rhESIYIV4VYej3NVNs2GZZfqB9jF6BLWyMisi+Q5rx51vLL0DPenrI3l2RRYni7qqfue9rZVPNhjNJ8Fv31csMh6iAJy5xg6hSdm6xOqTrmbRT9bDizzCtRK4DrhFazWAHtECs98FKc1ma4n0amsuHKDTYP/ts2NOPlAzaEAzQPpiDEUzvcujwGynDuBWnqyXGpaSTaaCdp2Zz03V95VWR15RyKkg== x-incomingheadercount: 46 x-eopattributedmessage: 0 x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(7070007)(98901004); DIR:OUT; SFP:1901; SCL:1; SRVR:VE1EUR01HT247; H:AM4PR06MB1491.eurprd06.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: c71d9394-71c9-43ef-97e4-08d4d9a80f01 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)(2017031322377)(1603101448)(1601125374)(1701031045)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:VE1EUR01HT247; x-ms-traffictypediagnostic: VE1EUR01HT247: 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:VE1EUR01HT247; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VE1EUR01HT247; x-forefront-prvs: 0387D64A71 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Aug 2017 13:12:00.1828 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR01HT247 Subject: [PATCH v2 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: Wed, 02 Aug 2017 13:09:53 -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. V2: - Fix IsListEmpty() to ASSERT when the passed list is invalid. - Introduce the VERIFY_IS_NODE_IN_LIST() macro to only verify whether the passed node is part of the list when PcdVerifyNodeInList is TRUE. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Marvin Haeuser --- MdePkg/Library/BaseLib/LinkedList.c | 105 +++++++++----------- 1 file changed, 47 insertions(+), 58 deletions(-) diff --git a/MdePkg/Library/BaseLib/LinkedList.c b/MdePkg/Library/BaseLib/L= inkedList.c index 484ee836b8c2..6864fae7d939 100644 --- a/MdePkg/Library/BaseLib/LinkedList.c +++ b/MdePkg/Library/BaseLib/LinkedList.c @@ -15,25 +15,38 @@ #include "BaseLibInternals.h" =20 /** - Worker function that locates the Node in the List. + If PcdVerifyNodeInList is TRUE, checks whether FirstNode and SecondNode = are + part of the same doubly-linked list. =20 - By searching the List, finds the location of the Node in List. At the sa= me time, - verifies the validity of this list. + If FirstEntry is NULL, then ASSERT(). + If FirstEntry->ForwardLink is NULL, then ASSERT(). + If FirstEntry->BackLink is NULL, then ASSERT(). + If SecondEntry is NULL, then ASSERT(); + If PcdMaximumLinkedListLength is not zero, and List contains more than + PcdMaximumLinkedListLength nodes, then ASSERT(). + + @param FirstEntry A pointer to a node in a linked list. + @param SecondEntry A pointer to the node to locate. + + @retval TRUE SecondEntry is in the same doubly-linked list as FirstEnt= ry + or PcdVerifyNodeInList is FALSE. + @retval FALSE SecondEntry isn't in the same doubly-linked list as First= Entry, + or FirstEntry is invalid. + +**/ +#define VERIFY_IS_NODE_IN_LIST(FirstEntry, SecondEntry) \ + (!FeaturePcdGet (PcdVerifyNodeInList) || IsNodeInList ((FirstEntry), (Se= condEntry))) + +/** + 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 +58,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 +71,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 +86,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; @@ -244,7 +226,8 @@ InsertHeadList ( // // ASSERT List not too long and Entry is not one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + ASSERT (InternalBaseLibIsListValid (ListHead)); + ASSERT (!VERIFY_IS_NODE_IN_LIST (ListHead, Entry)); =20 Entry->ForwardLink =3D ListHead->ForwardLink; Entry->BackLink =3D ListHead; @@ -285,7 +268,8 @@ InsertTailList ( // // ASSERT List not too long and Entry is not one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (ListHead, Entry, FALSE)); + ASSERT (InternalBaseLibIsListValid (ListHead)); + ASSERT (!VERIFY_IS_NODE_IN_LIST (ListHead, Entry)); =20 Entry->ForwardLink =3D ListHead; Entry->BackLink =3D ListHead->BackLink; @@ -323,7 +307,7 @@ GetFirstNode ( // // ASSERT List not too long // - ASSERT (InternalBaseLibIsNodeInList (List, List, FALSE)); + ASSERT (InternalBaseLibIsListValid (List)); =20 return List->ForwardLink; } @@ -359,7 +343,8 @@ GetNextNode ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (InternalBaseLibIsListValid (List)); + ASSERT (VERIFY_IS_NODE_IN_LIST (List, Node)); =20 return Node->ForwardLink; } @@ -395,7 +380,8 @@ GetPreviousNode ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (InternalBaseLibIsListValid (List)); + ASSERT (VERIFY_IS_NODE_IN_LIST (List, Node)); =20 return Node->BackLink; } @@ -428,7 +414,7 @@ IsListEmpty ( // // ASSERT List not too long // - ASSERT (InternalBaseLibIsNodeInList (ListHead, ListHead, FALSE)); + ASSERT (InternalBaseLibIsListValid (ListHead)); =20 return (BOOLEAN)(ListHead->ForwardLink =3D=3D ListHead); } @@ -469,7 +455,8 @@ IsNull ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (InternalBaseLibIsListValid (List)); + ASSERT (VERIFY_IS_NODE_IN_LIST (List, Node)); =20 return (BOOLEAN)(Node =3D=3D List); } @@ -507,7 +494,8 @@ IsNodeAtEnd ( // // ASSERT List not too long and Node is one of the nodes of List // - ASSERT (InternalBaseLibIsNodeInList (List, Node, TRUE)); + ASSERT (InternalBaseLibIsListValid (List)); + ASSERT (VERIFY_IS_NODE_IN_LIST (List, Node)); =20 return (BOOLEAN)(!IsNull (List, Node) && List->BackLink =3D=3D Node); } @@ -554,7 +542,8 @@ SwapListEntries ( // // ASSERT Entry1 and Entry2 are in the same linked list // - ASSERT (InternalBaseLibIsNodeInList (FirstEntry, SecondEntry, TRUE)); + ASSERT (InternalBaseLibIsListValid (FirstEntry)); + ASSERT (VERIFY_IS_NODE_IN_LIST (FirstEntry, SecondEntry)); =20 // // Ptr is the node pointed to by FirstEntry->ForwardLink --=20 2.12.2.windows.2