From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web12.69.1668015197122684025 for ; Wed, 09 Nov 2022 09:33:17 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=o/jb+2hG; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.201.8.94]) by linux.microsoft.com (Postfix) with ESMTPSA id F07A320C28B1; Wed, 9 Nov 2022 09:33:15 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com F07A320C28B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1668015196; bh=B6WHlNmsosxm149bu08v585UYwhrmGnjTBpIRuBJkpU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o/jb+2hGtiohJh/NEhiF3kiqL0p5snDB60HwJCihpWdtn85WMnVAK5OxrqoUY0OQR 4ORvzRRWED3AYnHyhH/NEBsKuTSa9uQXwr8HvIRJHqhX8LkG9sDDPTyYhRd6ByqwvM oygN4igZd5i0Y6EQvWvjgTlK7g5Jfu8R5c2xs3Eg= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Erich McMillan , Guomin Jiang , Jian J Wang , Jiewen Yao , Michael Kubacki , Xiaoyu Lu Subject: [PATCH v1 04/12] CryptoPkg: Fix conditionally uninitialized variable Date: Wed, 9 Nov 2022 12:32:38 -0500 Message-Id: <20221109173246.174-5-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20221109173246.174-1-mikuback@linux.microsoft.com> References: <20221109173246.174-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Fixes CodeQL alerts for CWE-457: https://cwe.mitre.org/data/definitions/457.html Checks the return value from `ASN1_get_object()` to verify values set by the function are valid. Note that the function returns literal `0x80`: `return (0x80);` That is used to check the return value is as the case in other areas of the code. Cc: Erich McMillan Cc: Guomin Jiang Cc: Jian J Wang Cc: Jiewen Yao Cc: Michael Kubacki Cc: Xiaoyu Lu Co-authored-by: Erich McMillan Signed-off-by: Michael Kubacki --- CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c b/CryptoPkg/Li= brary/BaseCryptLib/Pk/CryptX509.c index 2333157e0d17..f867656e888c 100644 --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptX509.c @@ -807,6 +807,7 @@ X509GetTBSCert ( UINT32 Asn1Tag; UINT32 ObjClass; UINTN Length; + UINTN Inf; =20 // // Check input parameters. @@ -836,9 +837,9 @@ X509GetTBSCert ( // Temp =3D Cert; Length =3D 0; - ASN1_get_object (&Temp, (long *)&Length, (int *)&Asn1Tag, (int *)&ObjC= lass, (long)CertSize); + Inf =3D ASN1_get_object (&Temp, (long *)&Length, (int *)&Asn1Tag, (= int *)&ObjClass, (long)CertSize); =20 - if (Asn1Tag !=3D V_ASN1_SEQUENCE) { + if (!(Inf & 0x80) && (Asn1Tag !=3D V_ASN1_SEQUENCE)) { return FALSE; } =20 @@ -848,7 +849,7 @@ X509GetTBSCert ( // // Verify the parsed TBSCertificate is one correct SEQUENCE data. // - if (Asn1Tag !=3D V_ASN1_SEQUENCE) { + if (!(Inf & 0x80) && (Asn1Tag !=3D V_ASN1_SEQUENCE)) { return FALSE; } =20 @@ -1888,18 +1889,20 @@ Asn1GetTag ( IN UINT32 Tag ) { - UINT8 *PtrOld; - INT32 ObjTag; - INT32 ObjCls; - long ObjLength; + UINT8 *PtrOld; + INT32 ObjTag; + INT32 ObjCls; + long ObjLength; + UINT32 Inf; =20 // // Save Ptr position // PtrOld =3D *Ptr; =20 - ASN1_get_object ((CONST UINT8 **)Ptr, &ObjLength, &ObjTag, &ObjCls, (I= NT32)(End - (*Ptr))); - if ((ObjTag =3D=3D (INT32)(Tag & CRYPTO_ASN1_TAG_VALUE_MASK)) && + Inf =3D ASN1_get_object ((CONST UINT8 **)Ptr, &ObjLength, &ObjTag, &Ob= jCls, (INT32)(End - (*Ptr))); + if (!(Inf & 0x80) && + (ObjTag =3D=3D (INT32)(Tag & CRYPTO_ASN1_TAG_VALUE_MASK)) && (ObjCls =3D=3D (INT32)(Tag & CRYPTO_ASN1_TAG_CLASS_MASK))) { *Length =3D (UINTN)ObjLength; --=20 2.28.0.windows.1