From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654164599320.13041974601344; Mon, 18 Dec 2017 19:29:24 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E25C02035BA32; Mon, 18 Dec 2017 19:24:35 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 0C76D2035BA25 for ; Mon, 18 Dec 2017 19:24:35 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:21 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:20 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196691" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:28:56 +0800 Message-Id: <20171219032912.14404-2-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 01/17] BaseTools/C/Common: Add checks for array access 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/Decompress.c | 8 ++++---- BaseTools/Source/C/Common/SimpleFileParsing.c | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/BaseTools/Source/C/Common/Decompress.c b/BaseTools/Source/C/Co= mmon/Decompress.c index b2049bd01c..8f1afb4e40 100644 --- a/BaseTools/Source/C/Common/Decompress.c +++ b/BaseTools/Source/C/Common/Decompress.c @@ -2,7 +2,7 @@ Decompressor. Algorithm Ported from OPSD code (Decomp.asm) for Efi and Tia= no=20 compress algorithm. =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at @@ -394,7 +394,7 @@ Returns: =20 Index =3D 0; =20 - while (Index < Number) { + while (Index < Number && Index < NPT) { =20 CharC =3D (UINT16) (Sd->mBitBuf >> (BITBUFSIZ - 3)); =20 @@ -413,14 +413,14 @@ Returns: if (Index =3D=3D Special) { CharC =3D (UINT16) GetBits (Sd, 2); CharC--; - while ((INT16) (CharC) >=3D 0) { + while ((INT16) (CharC) >=3D 0 && Index < NPT) { Sd->mPTLen[Index++] =3D 0; CharC--; } } } =20 - while (Index < nn) { + while (Index < nn && Index < NPT) { Sd->mPTLen[Index++] =3D 0; } =20 diff --git a/BaseTools/Source/C/Common/SimpleFileParsing.c b/BaseTools/Sour= ce/C/Common/SimpleFileParsing.c index 868c6b794b..209a0954b3 100644 --- a/BaseTools/Source/C/Common/SimpleFileParsing.c +++ b/BaseTools/Source/C/Common/SimpleFileParsing.c @@ -1,7 +1,7 @@ /** @file Generic but simple file parsing routines. =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -1232,12 +1232,10 @@ GetHexChars ( { UINT32 Len; Len =3D 0; - while (!EndOfFile (&mGlobals.SourceFile) && (BufferLen > 0)) { + while (!EndOfFile (&mGlobals.SourceFile) && (Len < BufferLen)) { if (isxdigit ((int)mGlobals.SourceFile.FileBufferPtr[0])) { - *Buffer =3D mGlobals.SourceFile.FileBufferPtr[0]; - Buffer++; + Buffer[Len] =3D mGlobals.SourceFile.FileBufferPtr[0]; Len++; - BufferLen--; mGlobals.SourceFile.FileBufferPtr++; } else { break; @@ -1246,8 +1244,8 @@ GetHexChars ( // // Null terminate if we can // - if ((Len > 0) && (BufferLen > 0)) { - *Buffer =3D 0; + if ((Len > 0) && (Len < BufferLen)) { + Buffer[Len] =3D 0; } =20 return Len; --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654167383286.3158440878675; Mon, 18 Dec 2017 19:29:27 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 27D252035BA36; Mon, 18 Dec 2017 19:24:37 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 5AA772035BA2D for ; Mon, 18 Dec 2017 19:24:36 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:22 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:21 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196696" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:28:57 +0800 Message-Id: <20171219032912.14404-3-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 02/17] BaseTools/EfiRom: Refine the logic in main() 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This commit refines the logic for main(). It makes the logic more straightforward to prevent possible mis-reports by static code checkers. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/EfiRom/EfiRom.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/BaseTools/Source/C/EfiRom/EfiRom.c b/BaseTools/Source/C/EfiRom= /EfiRom.c index 0f89280251..6648f4c738 100644 --- a/BaseTools/Source/C/EfiRom/EfiRom.c +++ b/BaseTools/Source/C/EfiRom/EfiRom.c @@ -101,11 +101,13 @@ Returns: // Find the last . on the line and replace the filename extension wi= th // the default // - for (Ext =3D mOptions.OutFileName + strlen (mOptions.OutFileName) - = 1; - (Ext >=3D mOptions.OutFileName) && (*Ext !=3D '.') && (*Ext != =3D '\\'); - Ext-- - ) - ; + Ext =3D mOptions.OutFileName + strlen (mOptions.OutFileName) - 1; + while (Ext >=3D mOptions.OutFileName) { + if ((*Ext =3D=3D '.') || (*Ext =3D=3D '\\')) { + break; + } + Ext--; + } // // If dot here, then insert extension here, otherwise append // --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654169870850.5802518311311; Mon, 18 Dec 2017 19:29:29 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 60B982035BA39; Mon, 18 Dec 2017 19:24:41 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 9F1D92035BA2D for ; Mon, 18 Dec 2017 19:24:37 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:23 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:22 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196700" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:28:58 +0800 Message-Id: <20171219032912.14404-4-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 03/17] BaseTools/LzmaCompress: Fix possible uninitialized variable 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c b/BaseTools/Sou= rce/C/LzmaCompress/Sdk/C/7zFile.c index 98fe7164f5..b2fed368a4 100644 --- a/BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c +++ b/BaseTools/Source/C/LzmaCompress/Sdk/C/7zFile.c @@ -213,7 +213,7 @@ WRes File_GetLength(CSzFile *p, UInt64 *length) { #ifdef USE_WINDOWS_FILE =20 - DWORD sizeHigh; + DWORD sizeHigh =3D 0; DWORD sizeLow =3D GetFileSize(p->handle, &sizeHigh); if (sizeLow =3D=3D 0xFFFFFFFF) { --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 15136541721611016.5304916485316; Mon, 18 Dec 2017 19:29:32 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 97AB92035BA3C; Mon, 18 Dec 2017 19:24:41 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 B93B62035BA2D for ; Mon, 18 Dec 2017 19:24:38 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:24 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:23 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196703" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:28:59 +0800 Message-Id: <20171219032912.14404-5-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 04/17] BaseTools/C/Common: Remove redundant type cast 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/BasePeCoff.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/C/Common/BasePeCoff.c b/BaseTools/Source/C/Co= mmon/BasePeCoff.c index 692663d0e4..fb7ce25122 100644 --- a/BaseTools/Source/C/Common/BasePeCoff.c +++ b/BaseTools/Source/C/Common/BasePeCoff.c @@ -2,7 +2,7 @@ =20 Functions to get info and load PE/COFF image. =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 @@ -1080,12 +1080,10 @@ Returns: PeHdr->Pe3= 2.OptionalHeader.AddressOfEntryPoint ); } else { - ImageContext->EntryPoint =3D (PHYSICAL_ADDRESS) ( - (UINTN)ImageContext->ImageAddress + - (UINTN)TeHdr->AddressOfEntryPoint + - (UINTN)sizeof(EFI_TE_IMAGE_HEADER) - - (UINTN) TeHdr->StrippedSize - ); + ImageContext->EntryPoint =3D (UINTN)ImageContext->ImageAddress + + (UINTN)TeHdr->AddressOfEntryPoint + + (UINTN)sizeof(EFI_TE_IMAGE_HEADER) - + (UINTN) TeHdr->StrippedSize; } =20 // --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654174681973.2244930399524; Mon, 18 Dec 2017 19:29:34 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CFF3D2035BA3F; Mon, 18 Dec 2017 19:24:41 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 DE6582035BA2D for ; Mon, 18 Dec 2017 19:24:39 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:26 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:25 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196706" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:00 +0800 Message-Id: <20171219032912.14404-6-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 05/17] BaseTools/VfrCompile: Assign 'NULL' for closed file handle 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Assign 'NULL' value to the already-closed file handle to avoid closing the handle multiple times. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/VfrCompile/VfrCompiler.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp b/BaseTools/Sour= ce/C/VfrCompile/VfrCompiler.cpp index 831f6b5174..ff2a837dfc 100644 --- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp @@ -2,7 +2,7 @@ =20 VfrCompiler main class and main function. =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -703,6 +703,7 @@ CVfrCompiler::Compile ( } =20 fclose (pInFile); + pInFile =3D NULL; =20 if (gCFormPkg.HavePendingUnassigned () =3D=3D TRUE) { gCFormPkg.PendingAssignPrintAll (); --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654177256435.0008662181489; Mon, 18 Dec 2017 19:29:37 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 174832035B2EF; Mon, 18 Dec 2017 19:24:45 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 2AD772035BA2E for ; Mon, 18 Dec 2017 19:24:41 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:27 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:26 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196710" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:01 +0800 Message-Id: <20171219032912.14404-7-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 06/17] BaseTools/GenFv: Add check to ensure the file handle status is correct 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add an extra NULL check for the file handle to ensure that its status is correct. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenFv/GenFv.c | 38 ++++++++++++++++++++----------------= -- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/BaseTools/Source/C/GenFv/GenFv.c b/BaseTools/Source/C/GenFv/Ge= nFv.c index 4de24b9f7e..be31840310 100644 --- a/BaseTools/Source/C/GenFv/GenFv.c +++ b/BaseTools/Source/C/GenFv/GenFv.c @@ -4,7 +4,7 @@ can be found in the Tiano Firmware Volume Generation Utility=20 Specification, review draft. =20 -Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -607,23 +607,25 @@ Returns: return STATUS_ERROR; } } - fprintf (FpFile, "Capsule %s Image Header Information\n", InfFileName); - fprintf (FpFile, " GUID %08X-%04X-%04X-%02X%02X-%02X= %02X%02X%02X%02X%02X\n",=20 - (unsigned) CapsuleHeader->CapsuleGuid.Data1, - (unsigned) CapsuleHeader->CapsuleGuid.Data2, - (unsigned) CapsuleHeader->CapsuleGuid.Data3, - (unsigned) CapsuleHeader->CapsuleGuid.Data4[0], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[1], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[2], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[3], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[4], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[5], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[6], - (unsigned) CapsuleHeader->CapsuleGuid.Data4[7]); - fprintf (FpFile, " Header size 0x%08X\n", (unsigned) Capsul= eHeader->HeaderSize); - fprintf (FpFile, " Flags 0x%08X\n", (unsigned) Capsul= eHeader->Flags); - fprintf (FpFile, " Capsule image size 0x%08X\n", (unsigned) Capsul= eHeader->CapsuleImageSize); - fclose (FpFile); + if (FpFile !=3D NULL) { + fprintf (FpFile, "Capsule %s Image Header Information\n", InfFileNam= e); + fprintf (FpFile, " GUID %08X-%04X-%04X-%02X%02X-%0= 2X%02X%02X%02X%02X%02X\n", + (unsigned) CapsuleHeader->CapsuleGuid.Data1, + (unsigned) CapsuleHeader->CapsuleGuid.Data2, + (unsigned) CapsuleHeader->CapsuleGuid.Data3, + (unsigned) CapsuleHeader->CapsuleGuid.Data4[0], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[1], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[2], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[3], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[4], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[5], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[6], + (unsigned) CapsuleHeader->CapsuleGuid.Data4[7]); + fprintf (FpFile, " Header size 0x%08X\n", (unsigned) Caps= uleHeader->HeaderSize); + fprintf (FpFile, " Flags 0x%08X\n", (unsigned) Caps= uleHeader->Flags); + fprintf (FpFile, " Capsule image size 0x%08X\n", (unsigned) Caps= uleHeader->CapsuleImageSize); + fclose (FpFile); + } } else if (CapsuleFlag) { VerboseMsg ("Create capsule image"); // --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 151365417985222.426991416958913; Mon, 18 Dec 2017 19:29:39 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 5348D2208586B; Mon, 18 Dec 2017 19:24:45 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 6DF582035BA35 for ; Mon, 18 Dec 2017 19:24:42 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:28 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:27 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196714" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:02 +0800 Message-Id: <20171219032912.14404-8-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 07/17] BaseTools/C/Common: Add/refine boundary checks for strcpy/strcat calls 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/CommonLib.c | 24 +++++++++++++++++------- BaseTools/Source/C/Common/EfiUtilityMsgs.c | 9 +++------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Com= mon/CommonLib.c index 2f0aecf252..4a62bec85e 100644 --- a/BaseTools/Source/C/Common/CommonLib.c +++ b/BaseTools/Source/C/Common/CommonLib.c @@ -1,7 +1,7 @@ /** @file Common basic Library Functions =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -638,12 +638,22 @@ Returns: // RootPath =3D getcwd (NULL, 0); if (RootPath !=3D NULL) { - strcat (mCommonLibFullPath, RootPath); + if (strlen (mCommonLibFullPath) + strlen (RootPath) > MAX_LONG_FIL= E_PATH - 1) { + Error (NULL, 0, 2000, "Invalid parameter", "RootPath is too long= !"); + free (RootPath); + return NULL; + } + strncat (mCommonLibFullPath, RootPath, MAX_LONG_FILE_PATH - strlen= (mCommonLibFullPath) - 1); if (FileName[0] !=3D '\\' && FileName[0] !=3D '/') { + if (strlen (mCommonLibFullPath) + 1 > MAX_LONG_FILE_PATH - 1) { + Error (NULL, 0, 2000, "Invalid parameter", "RootPath is too lo= ng!"); + free (RootPath); + return NULL; + } // // Attach directory separator // - strcat (mCommonLibFullPath, "\\"); + strncat (mCommonLibFullPath, "\\", MAX_LONG_FILE_PATH - strlen (= mCommonLibFullPath) - 1); } free (RootPath); } @@ -673,7 +683,7 @@ Returns: // if ((PathPointer =3D strstr (mCommonLibFullPath, ":\\\\")) !=3D NULL) { *(PathPointer + 2) =3D '\0'; - strcat (mCommonLibFullPath, PathPointer + 3); + strncat (mCommonLibFullPath, PathPointer + 3, MAX_LONG_FILE_PATH - s= trlen (mCommonLibFullPath) - 1); } =20 // @@ -681,7 +691,7 @@ Returns: // while ((PathPointer =3D strstr (mCommonLibFullPath, ".\\")) !=3D NULL)= { *PathPointer =3D '\0'; - strcat (mCommonLibFullPath, PathPointer + 2); + strncat (mCommonLibFullPath, PathPointer + 2, MAX_LONG_FILE_PATH - s= trlen (mCommonLibFullPath) - 1); } =20 // @@ -689,7 +699,7 @@ Returns: // while ((PathPointer =3D strstr (mCommonLibFullPath, "\\.\\")) !=3D NUL= L) { *PathPointer =3D '\0'; - strcat (mCommonLibFullPath, PathPointer + 2); + strncat (mCommonLibFullPath, PathPointer + 2, MAX_LONG_FILE_PATH - s= trlen (mCommonLibFullPath) - 1); } =20 // @@ -706,7 +716,7 @@ Returns: // Skip one directory // *PathPointer =3D '\0'; - strcat (mCommonLibFullPath, NextPointer); + strncat (mCommonLibFullPath, NextPointer, MAX_LONG_FILE_PATH - str= len (mCommonLibFullPath) - 1); } else { // // No directory is found. Just break. diff --git a/BaseTools/Source/C/Common/EfiUtilityMsgs.c b/BaseTools/Source/= C/Common/EfiUtilityMsgs.c index 7b4c2310ca..5496a439e2 100644 --- a/BaseTools/Source/C/Common/EfiUtilityMsgs.c +++ b/BaseTools/Source/C/Common/EfiUtilityMsgs.c @@ -1,7 +1,7 @@ /** @file EFI tools utility functions to display warning, error, and informational m= essages =20 -Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD = License which accompanies this distribution. The full text of the license may be = found at @@ -608,12 +608,9 @@ Returns: if (UtilityName !=3D NULL) { if (strlen (UtilityName) >=3D sizeof (mUtilityName)) { Error (UtilityName, 0, 0, "application error", "utility name length = exceeds internal buffer size"); - strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1); - mUtilityName[sizeof (mUtilityName) - 1] =3D 0; - return ; - } else { - strcpy (mUtilityName, UtilityName); } + strncpy (mUtilityName, UtilityName, sizeof (mUtilityName) - 1); + mUtilityName[sizeof (mUtilityName) - 1] =3D 0; } else { Error (NULL, 0, 0, "application error", "SetUtilityName() called with = NULL utility name"); } --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654182596353.7460429341504; Mon, 18 Dec 2017 19:29:42 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 89DF522212C08; Mon, 18 Dec 2017 19:24:45 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 928662035BA25 for ; Mon, 18 Dec 2017 19:24:43 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:29 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:28 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196718" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:03 +0800 Message-Id: <20171219032912.14404-9-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 08/17] BaseTools/C/Common: Refine using sprintf() with '%s' in format string 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The commit removes the usages of sprintf() function calls with '%s' in the format string. And uses strncpy/strncat instead to ensure the destination string buffers will not be accessed beyond their boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/Common/EfiUtilityMsgs.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/BaseTools/Source/C/Common/EfiUtilityMsgs.c b/BaseTools/Source/= C/Common/EfiUtilityMsgs.c index 5496a439e2..44925c642b 100644 --- a/BaseTools/Source/C/Common/EfiUtilityMsgs.c +++ b/BaseTools/Source/C/Common/EfiUtilityMsgs.c @@ -462,10 +462,11 @@ Notes: ); } if (Cptr !=3D NULL) { - sprintf (Line, ": %s", Cptr); + strcpy (Line, ": "); + strncat (Line, Cptr, MAX_LINE_LEN - strlen (Line) - 1); if (LineNumber !=3D 0) { sprintf (Line2, "(%u)", (unsigned) LineNumber); - strcat (Line, Line2); + strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } } } else { @@ -476,14 +477,16 @@ Notes: if (mUtilityName[0] !=3D '\0') { fprintf (stdout, "%s...\n", mUtilityName); } - sprintf (Line, "%s", Cptr); + strncpy (Line, Cptr, MAX_LINE_LEN - 1); + Line[MAX_LINE_LEN - 1] =3D 0; if (LineNumber !=3D 0) { sprintf (Line2, "(%u)", (unsigned) LineNumber); - strcat (Line, Line2); + strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } } else { if (mUtilityName[0] !=3D '\0') { - sprintf (Line, "%s", mUtilityName); + strncpy (Line, mUtilityName, MAX_LINE_LEN - 1); + Line[MAX_LINE_LEN - 1] =3D 0; } } =20 @@ -501,12 +504,12 @@ Notes: // Have to print an error code or Visual Studio won't find the // message for you. It has to be decimal digits too. // + strncat (Line, ": ", MAX_LINE_LEN - strlen (Line) - 1); + strncat (Line, Type, MAX_LINE_LEN - strlen (Line) - 1); if (MessageCode !=3D 0) { - sprintf (Line2, ": %s %04u", Type, (unsigned) MessageCode); - } else { - sprintf (Line2, ": %s", Type); + sprintf (Line2, " %04u", (unsigned) MessageCode); + strncat (Line, Line2, MAX_LINE_LEN - strlen (Line) - 1); } - strcat (Line, Line2); fprintf (stdout, "%s", Line); // // If offending text was provided, then print it --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654184816647.2267749526055; Mon, 18 Dec 2017 19:29:44 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C99272035BA2E; Mon, 18 Dec 2017 19:24:48 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 DAFD42035B2EB for ; Mon, 18 Dec 2017 19:24:44 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:31 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:29 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196723" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:04 +0800 Message-Id: <20171219032912.14404-10-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 09/17] BaseTools/EfiRom: Add/refine boundary checks for strcpy/strcat calls 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/EfiRom/EfiRom.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/EfiRom/EfiRom.c b/BaseTools/Source/C/EfiRom= /EfiRom.c index 6648f4c738..fc3b5ad277 100644 --- a/BaseTools/Source/C/EfiRom/EfiRom.c +++ b/BaseTools/Source/C/EfiRom/EfiRom.c @@ -96,7 +96,13 @@ Returns: // if (!mOptions.OutFileName[0]) { if (mOptions.FileList !=3D NULL) { - strcpy (mOptions.OutFileName, mOptions.FileList->FileName); + if (strlen (mOptions.FileList->FileName) >=3D MAX_PATH) { + Status =3D STATUS_ERROR; + Error (NULL, 0, 2000, "Invalid parameter", "Input file name is too= long - %s.", mOptions.FileList->FileName); + goto BailOut; + } + strncpy (mOptions.OutFileName, mOptions.FileList->FileName, MAX_PATH= - 1); + mOptions.OutFileName[MAX_PATH - 1] =3D 0; // // Find the last . on the line and replace the filename extension wi= th // the default --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654187187197.8452409789321; Mon, 18 Dec 2017 19:29:47 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0BCD222212C1C; Mon, 18 Dec 2017 19:24:49 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 559B12035BA2E for ; Mon, 18 Dec 2017 19:24:46 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:32 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:31 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196727" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:05 +0800 Message-Id: <20171219032912.14404-11-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 10/17] BaseTools/GenBootSector: Add/refine boundary checks for strcpy/strcat 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenBootSector/GenBootSector.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/BaseTools/Source/C/GenBootSector/GenBootSector.c b/BaseTools/S= ource/C/GenBootSector/GenBootSector.c index 3908c589af..c02de49ba2 100644 --- a/BaseTools/Source/C/GenBootSector/GenBootSector.c +++ b/BaseTools/Source/C/GenBootSector/GenBootSector.c @@ -4,7 +4,7 @@ Reading/writing MBR/DBR. If we write MBR to disk, we just update the MBR code and the partition= table wouldn't be over written. If we process DBR, we will patch MBR to set first partition active if = no active partition exists. =20 -Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials =20 are licensed and made available under the terms and conditions of the BSD = License =20 which accompanies this distribution. The full text of the license may be = found at =20 @@ -631,6 +631,14 @@ GetPathInfo ( return ErrorSuccess; }=20 =20 + // + // Check the path length + // + if (strlen (PathInfo->Path) >=3D (sizeof (PathInfo->PhysicalPath) / size= of (PathInfo->PhysicalPath[0]))) { + fprintf (stderr, "ERROR, Path is too long for - %s", PathInfo->Path); + return ErrorPath; + } + PathInfo->Type =3D PathFile; if (PathInfo->Input) { // @@ -644,7 +652,12 @@ GetPathInfo ( fclose (f); } PathInfo->Type =3D PathFile; - strcpy(PathInfo->PhysicalPath, PathInfo->Path); + strncpy( + PathInfo->PhysicalPath, + PathInfo->Path, + sizeof (PathInfo->PhysicalPath) / sizeof (PathInfo->PhysicalPath[0]) -= 1 + ); + PathInfo->PhysicalPath[sizeof (PathInfo->PhysicalPath) / sizeof (PathInf= o->PhysicalPath[0]) - 1] =3D 0; =20 return ErrorSuccess; } =20 --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654189661482.3977809161048; Mon, 18 Dec 2017 19:29:49 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 449E0221C1923; Mon, 18 Dec 2017 19:24:49 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 65F942035BA25 for ; Mon, 18 Dec 2017 19:24:47 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:33 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:32 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196732" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:06 +0800 Message-Id: <20171219032912.14404-12-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 11/17] BaseTools/GenFv: Add/refine boundary checks for strcpy/strcat calls 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenFv/GenFvInternalLib.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source= /C/GenFv/GenFvInternalLib.c index 2b80e7919b..fc1a7602ab 100644 --- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c +++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c @@ -824,7 +824,11 @@ Returns: // // Construct Map file Name=20 // - strcpy (PeMapFileName, FileName); + if (strlen (FileName) >=3D MAX_LONG_FILE_PATH) { + return EFI_ABORTED; + } + strncpy (PeMapFileName, FileName, MAX_LONG_FILE_PATH - 1); + PeMapFileName[MAX_LONG_FILE_PATH - 1] =3D 0; =20 // // Change '\\' to '/', unified path format. @@ -861,7 +865,11 @@ Returns: Cptr --; } *Cptr2 =3D '\0'; - strcpy (KeyWord, Cptr + 1); + if (strlen (Cptr + 1) >=3D MAX_LINE_LEN) { + return EFI_ABORTED; + } + strncpy (KeyWord, Cptr + 1, MAX_LINE_LEN - 1); + KeyWord[MAX_LINE_LEN - 1] =3D 0; *Cptr2 =3D '.'; =20 // @@ -3534,7 +3542,12 @@ Returns: // // Construct the original efi file Name=20 // - strcpy (PeFileName, FileName); + if (strlen (FileName) >=3D MAX_LONG_FILE_PATH) { + Error (NULL, 0, 2000, "Invalid", "The file name %s is too long= .", FileName); + return EFI_ABORTED; + } + strncpy (PeFileName, FileName, MAX_LONG_FILE_PATH - 1); + PeFileName[MAX_LONG_FILE_PATH - 1] =3D 0; Cptr =3D PeFileName + strlen (PeFileName); while (*Cptr !=3D '.') { Cptr --; @@ -3789,7 +3802,12 @@ Returns: // // Construct the original efi file name=20 // - strcpy (PeFileName, FileName); + if (strlen (FileName) >=3D MAX_LONG_FILE_PATH) { + Error (NULL, 0, 2000, "Invalid", "The file name %s is too long.", = FileName); + return EFI_ABORTED; + } + strncpy (PeFileName, FileName, MAX_LONG_FILE_PATH - 1); + PeFileName[MAX_LONG_FILE_PATH - 1] =3D 0; Cptr =3D PeFileName + strlen (PeFileName); while (*Cptr !=3D '.') { Cptr --; --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654192250704.4031377922335; Mon, 18 Dec 2017 19:29:52 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 91D00221C192A; Mon, 18 Dec 2017 19:24:52 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 800712035BA2E for ; Mon, 18 Dec 2017 19:24:48 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:34 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:33 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196738" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:07 +0800 Message-Id: <20171219032912.14404-13-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 12/17] BaseTools/GenVtf: Add/refine boundary checks for strcpy/strcat calls 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenVtf/GenVtf.c | 43 ++++++++++++++++++++++++++++++++--= ---- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/BaseTools/Source/C/GenVtf/GenVtf.c b/BaseTools/Source/C/GenVtf= /GenVtf.c index 2ae9a7be2c..65ae08eece 100644 --- a/BaseTools/Source/C/GenVtf/GenVtf.c +++ b/BaseTools/Source/C/GenVtf/GenVtf.c @@ -362,10 +362,20 @@ Returns: } } else if (strnicmp (*TokenStr, "COMP_BIN", 8) =3D=3D 0) { TokenStr++; - strcpy (VtfInfo->CompBinName, *TokenStr); + if (strlen (*TokenStr) >=3D FILE_NAME_SIZE) { + Error (NULL, 0, 3000, "Invalid", "The 'COMP_BIN' name is too long.= "); + return ; + } + strncpy (VtfInfo->CompBinName, *TokenStr, FILE_NAME_SIZE - 1); + VtfInfo->CompBinName[FILE_NAME_SIZE - 1] =3D 0; } else if (strnicmp (*TokenStr, "COMP_SYM", 8) =3D=3D 0) { TokenStr++; - strcpy (VtfInfo->CompSymName, *TokenStr); + if (strlen (*TokenStr) >=3D FILE_NAME_SIZE) { + Error (NULL, 0, 3000, "Invalid", "The 'COMP_SYM' name is too long.= "); + return ; + } + strncpy (VtfInfo->CompSymName, *TokenStr, FILE_NAME_SIZE - 1); + VtfInfo->CompSymName[FILE_NAME_SIZE - 1] =3D 0; } else if (strnicmp (*TokenStr, "COMP_SIZE", 9) =3D=3D 0) { TokenStr++; if (strnicmp (*TokenStr, "-", 1) =3D=3D 0) { @@ -444,14 +454,24 @@ Returns: if (SectionOptionFlag) { if (stricmp (*TokenStr, "IA32_RST_BIN") =3D=3D 0) { TokenStr++; - strcpy (IA32BinFile, *TokenStr); + if (strlen (*TokenStr) >=3D FILE_NAME_SIZE) { + Error (NULL, 0, 3000, "Invalid", "The 'IA32_RST_BIN' name is too= long."); + break; + } + strncpy (IA32BinFile, *TokenStr, FILE_NAME_SIZE - 1); + IA32BinFile[FILE_NAME_SIZE - 1] =3D 0; } } =20 if (SectionCompFlag) { if (stricmp (*TokenStr, "COMP_NAME") =3D=3D 0) { TokenStr++; - strcpy (FileListPtr->CompName, *TokenStr); + if (strlen (*TokenStr) >=3D COMPONENT_NAME_SIZE) { + Error (NULL, 0, 3000, "Invalid", "The 'COMP_NAME' name is too lo= ng."); + break; + } + strncpy (FileListPtr->CompName, *TokenStr, COMPONENT_NAME_SIZE - 1= ); + FileListPtr->CompName[COMPONENT_NAME_SIZE - 1] =3D 0; TokenStr++; ParseAndUpdateComponents (FileListPtr); } @@ -2240,9 +2260,20 @@ Returns: // // Use the file name minus extension as the base for tokens // - strcpy (BaseToken, SourceFileName); + if (strlen (SourceFileName) >=3D MAX_LONG_FILE_PATH) { + fclose (SourceFile); + Error (NULL, 0, 2000, "Invalid parameter", "The source file name is to= o long."); + return EFI_ABORTED; + } + strncpy (BaseToken, SourceFileName, MAX_LONG_FILE_PATH - 1); + BaseToken[MAX_LONG_FILE_PATH - 1] =3D 0; strtok (BaseToken, ". \t\n"); - strcat (BaseToken, "__"); + if (strlen (BaseToken) + strlen ("__") >=3D MAX_LONG_FILE_PATH) { + fclose (SourceFile); + Error (NULL, 0, 2000, "Invalid parameter", "The source file name is to= o long."); + return EFI_ABORTED; + } + strncat (BaseToken, "__", MAX_LONG_FILE_PATH - strlen (BaseToken) - 1); =20 // // Open the destination file --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654194924454.700048930422; Mon, 18 Dec 2017 19:29:54 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CC71A221C192E; Mon, 18 Dec 2017 19:24:52 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 90820221C1926 for ; Mon, 18 Dec 2017 19:24:49 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:35 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:34 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196743" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:08 +0800 Message-Id: <20171219032912.14404-14-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 13/17] BaseTools/VfrCompile: Add/refine boundary checks for strcpy/strcat 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add checks to ensure when the destination string buffer is of fixed size, the strcpy/strcat functions calls will not access beyond the boundary. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/So= urce/C/VfrCompile/VfrUtilityLib.cpp index 0fe14b0d29..4866639aab 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp @@ -15,6 +15,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER= EXPRESS OR IMPLIED. =20 #include "stdio.h" #include "stdlib.h" +#include "assert.h" #include "CommonLib.h" #include "VfrUtilityLib.h" #include "VfrFormPkg.h" @@ -842,7 +843,9 @@ CVfrVarDataTypeDB::InternalTypesListInit ( for (Index =3D 0; gInternalTypesTable[Index].mTypeName !=3D NULL; Index+= +) { New =3D new SVfrDataType; if (New !=3D NULL) { - strcpy (New->mTypeName, gInternalTypesTable[Index].mTypeName); + assert (strlen (gInternalTypesTable[Index].mTypeName) < MAX_NAME_LEN= ); + strncpy (New->mTypeName, gInternalTypesTable[Index].mTypeName, MAX_N= AME_LEN - 1); + New->mTypeName[MAX_NAME_LEN - 1] =3D 0; New->mType =3D gInternalTypesTable[Index].mType; New->mAlign =3D gInternalTypesTable[Index].mAlign; New->mTotalSize =3D gInternalTypesTable[Index].mSize; @@ -1084,7 +1087,8 @@ CVfrVarDataTypeDB::SetNewTypeName ( } } =20 - strcpy(mNewDataType->mTypeName, TypeName); + strncpy(mNewDataType->mTypeName, TypeName, MAX_NAME_LEN - 1); + mNewDataType->mTypeName[MAX_NAME_LEN - 1] =3D 0; return VFR_RETURN_SUCCESS; } =20 @@ -1145,7 +1149,8 @@ CVfrVarDataTypeDB::DataTypeAddBitField ( =20 MaxDataTypeSize =3D mNewDataType->mTotalSize; if (FieldName !=3D NULL) { - strcpy (pNewField->mFieldName, FieldName); + strncpy (pNewField->mFieldName, FieldName, MAX_NAME_LEN - 1); + pNewField->mFieldName[MAX_NAME_LEN - 1] =3D 0; } pNewField->mFieldType =3D pFieldType; pNewField->mIsBitField =3D TRUE; @@ -1239,7 +1244,8 @@ CVfrVarDataTypeDB::DataTypeAddField ( if ((pNewField =3D new SVfrDataField) =3D=3D NULL) { return VFR_RETURN_OUT_FOR_RESOURCES; } - strcpy (pNewField->mFieldName, FieldName); + strncpy (pNewField->mFieldName, FieldName, MAX_NAME_LEN - 1); + pNewField->mFieldName[MAX_NAME_LEN - 1] =3D 0; pNewField->mFieldType =3D pFieldType; pNewField->mArrayNum =3D ArrayNum; pNewField->mIsBitField =3D FALSE; --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654197510434.94944770703194; Mon, 18 Dec 2017 19:29:57 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 0ECAE221C1930; Mon, 18 Dec 2017 19:24:53 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 9D922221C1926 for ; Mon, 18 Dec 2017 19:24:50 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:36 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:35 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196748" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:09 +0800 Message-Id: <20171219032912.14404-15-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 14/17] BaseTools/VfrCompile: Resolve uninit class variables in constructor 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The commit initializes those possibly uninitialized class variables in class constructors. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/VfrCompile/VfrError.cpp | 1 + BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp | 6 ++++++ BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp | 3 +++ 3 files changed, 10 insertions(+) diff --git a/BaseTools/Source/C/VfrCompile/VfrError.cpp b/BaseTools/Source/= C/VfrCompile/VfrError.cpp index 0f8f7dd891..2366fac5a7 100644 --- a/BaseTools/Source/C/VfrCompile/VfrError.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrError.cpp @@ -67,6 +67,7 @@ CVfrErrorHandle::CVfrErrorHandle ( mScopeRecordListTail =3D NULL; mVfrErrorHandleTable =3D VFR_ERROR_HANDLE_TABLE; mVfrWarningHandleTable =3D VFR_WARNING_HANDLE_TABLE; + mWarningAsError =3D FALSE; } =20 CVfrErrorHandle::~CVfrErrorHandle ( diff --git a/BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp b/BaseTools/Sourc= e/C/VfrCompile/VfrFormPkg.cpp index b8350623f2..0f0efd4c6d 100644 --- a/BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrFormPkg.cpp @@ -104,8 +104,13 @@ CFormPkg::CFormPkg ( SBufferNode *Node; =20 mPkgLength =3D 0; + mBufferSize =3D 0; mBufferNodeQueueHead =3D NULL; + mBufferNodeQueueTail =3D NULL; mCurrBufferNode =3D NULL; + mReadBufferNode =3D NULL; + mReadBufferOffset =3D 0; + PendingAssignList =3D NULL; =20 Node =3D new SBufferNode; if (Node =3D=3D NULL) { @@ -2421,6 +2426,7 @@ CIfrObj::CIfrObj ( mObjBinLen =3D (ObjBinLen =3D=3D 0) ? gOpcodeSizesScopeTable[OpCode].m= Size : ObjBinLen; mObjBinBuf =3D ((DelayEmit =3D=3D FALSE) && (gCreateOp =3D=3D TRUE)) ?= gCFormPkg.IfrBinBufferGet (mObjBinLen) : new CHAR8[EFI_IFR_MAX_LENGTH]; mRecordIdx =3D (gCreateOp =3D=3D TRUE) ? gCIfrRecordInfoDB.IfrRecordRe= gister (0xFFFFFFFF, mObjBinBuf, mObjBinLen, mPkgOffset) : EFI_IFR_RECORDINF= O_IDX_INVALUD; + mLineNo =3D 0; =20 assert (mObjBinBuf !=3D NULL); =20 diff --git a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp b/BaseTools/So= urce/C/VfrCompile/VfrUtilityLib.cpp index 4866639aab..c536498d77 100644 --- a/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp @@ -958,6 +958,7 @@ CVfrVarDataTypeDB::CVfrVarDataTypeDB ( mPackAlign =3D DEFAULT_PACK_ALIGN; mPackStack =3D NULL; mFirstNewDataTypeName =3D NULL; + mCurrDataType =3D NULL; =20 InternalTypesListInit (); } @@ -1605,6 +1606,7 @@ SVfrVarStorageNode::SVfrVarStorageNode ( IN EFI_VARSTORE_ID VarStoreId ) { + memset (&mGuid, 0, sizeof (EFI_GUID)); if (StoreName !=3D NULL) { mVarStoreName =3D new CHAR8[strlen(StoreName) + 1]; strcpy (mVarStoreName, StoreName); @@ -1616,6 +1618,7 @@ SVfrVarStorageNode::SVfrVarStorageNode ( mVarStoreType =3D EFI_VFR_VARSTORE_NAME; mStorageInfo.mNameSpace.mNameTable =3D new EFI_VARSTORE_ID[DEFAULT_NAME_= TABLE_ITEMS]; mStorageInfo.mNameSpace.mTableSize =3D 0; + mAssignedFlag =3D FALSE; } =20 SVfrVarStorageNode::~SVfrVarStorageNode ( --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654199959171.5952667514274; Mon, 18 Dec 2017 19:29:59 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 483FB221C1933; Mon, 18 Dec 2017 19:24:55 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 B5C15221C1929 for ; Mon, 18 Dec 2017 19:24:51 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:37 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:36 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196753" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:10 +0800 Message-Id: <20171219032912.14404-16-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 15/17] BaseTools/GenFfs: Enlarge the size of 'AlignmentBuffer' 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" As a workaround for the static code checkers, enlarge the size of the string buffer 'AlignmentBuffer' so that it can hold all the digits of an unsigned 32-bit integer plus the size unit character (e.g. 'M' & 'K'). Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenFfs/GenFfs.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs= /GenFfs.c index 3b4a9b7761..eb40c30ea7 100644 --- a/BaseTools/Source/C/GenFfs/GenFfs.c +++ b/BaseTools/Source/C/GenFfs/GenFfs.c @@ -606,7 +606,12 @@ Returns: UINT8 PeSectionNum; UINT32 HeaderSize; UINT32 Alignment; - CHAR8 AlignmentBuffer[8]; + // + // Workaround for static code checkers. + // Ensures the size of 'AlignmentBuffer' can hold all the digits of an + // unsigned 32-bit integer plus the size unit character. + // + CHAR8 AlignmentBuffer[16]; =20 // // Init local variables --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654202310105.6694062175145; Mon, 18 Dec 2017 19:30:02 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 83B5A221C1936; Mon, 18 Dec 2017 19:24:55 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 C38CF221C192C for ; Mon, 18 Dec 2017 19:24:52 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:38 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:38 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196757" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:11 +0800 Message-Id: <20171219032912.14404-17-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 16/17] BaseTools/GenSec: Fix potential memory leak 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenSec/GenSec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec= /GenSec.c index 5545f12b74..01d3bc4448 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -1670,7 +1670,11 @@ Finish: if (OutFile !=3D NULL) { fclose (OutFile); } - =20 + + if (DummyFileBuffer !=3D NULL) { + free (DummyFileBuffer); + } + VerboseMsg ("%s tool done with return code is 0x%x.", UTILITY_NAME, GetU= tilityStatus ()); =20 return GetUtilityStatus (); --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Sat May 4 05:29:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1513654204700990.1782869553822; Mon, 18 Dec 2017 19:30:04 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C7655221C1939; Mon, 18 Dec 2017 19:24:55 -0800 (PST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 DAA26221C1928 for ; Mon, 18 Dec 2017 19:24:53 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Dec 2017 19:29:40 -0800 Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.10]) by fmsmga006.fm.intel.com with ESMTP; 18 Dec 2017 19:29:39 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=hao.a.wu@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,424,1508828400"; d="scan'208";a="188196761" From: Hao Wu To: edk2-devel@lists.01.org Date: Tue, 19 Dec 2017 11:29:12 +0800 Message-Id: <20171219032912.14404-18-hao.a.wu@intel.com> X-Mailer: git-send-email 2.12.0.windows.1 In-Reply-To: <20171219032912.14404-1-hao.a.wu@intel.com> References: <20171219032912.14404-1-hao.a.wu@intel.com> Subject: [edk2] [PATCH 17/17] BaseTools/GenSec: Fix potential null pointer dereference 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: , Cc: Hao Wu , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Hao Wu Reviewed-by: Liming Gao --- BaseTools/Source/C/GenSec/GenSec.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec= /GenSec.c index 01d3bc4448..fb5bc5e992 100644 --- a/BaseTools/Source/C/GenSec/GenSec.c +++ b/BaseTools/Source/C/GenSec/GenSec.c @@ -1333,10 +1333,20 @@ Returns: DummyFileSize =3D ftell (DummyFile); fseek (DummyFile, 0, SEEK_SET); DummyFileBuffer =3D (UINT8 *) malloc (DummyFileSize); + if (DummyFileBuffer =3D=3D NULL) { + fclose(DummyFile); + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } + fread(DummyFileBuffer, 1, DummyFileSize, DummyFile); fclose(DummyFile); DebugMsg (NULL, 0, 9, "Dummy files", "the dummy file name is %s and = the size is %u bytes", DummyFileName, (unsigned) DummyFileSize); =20 + if (InputFileName =3D=3D NULL) { + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } InFile =3D fopen(LongFilePath(InputFileName[0]), "rb"); if (InFile =3D=3D NULL) { Error (NULL, 0, 0001, "Error opening file", InputFileName[0]); @@ -1347,6 +1357,12 @@ Returns: InFileSize =3D ftell (InFile); fseek (InFile, 0, SEEK_SET); InFileBuffer =3D (UINT8 *) malloc (InFileSize); + if (InFileBuffer =3D=3D NULL) { + fclose(InFile); + Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated"); + goto Finish; + } + fread(InFileBuffer, 1, InFileSize, InFile); fclose(InFile); DebugMsg (NULL, 0, 9, "Input files", "the input file name is %s and = the size is %u bytes", InputFileName[0], (unsigned) InFileSize); --=20 2.12.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel