From nobody Mon May 6 06:10:00 2024 Delivered-To: importer@patchew.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; 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 1501124081309594.6332217332457; Wed, 26 Jul 2017 19:54:41 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B46A421D09181; Wed, 26 Jul 2017 19:52:33 -0700 (PDT) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 F25CF2095DB87 for ; Wed, 26 Jul 2017 19:52:31 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jul 2017 19:54:34 -0700 Received: from shwdeopenpsi114.ccr.corp.intel.com ([10.239.157.135]) by orsmga002.jf.intel.com with ESMTP; 26 Jul 2017 19:54:33 -0700 X-Original-To: edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,418,1496127600"; d="scan'208";a="116147091" From: Dandan Bi To: edk2-devel@lists.01.org Date: Thu, 27 Jul 2017 10:53:09 +0800 Message-Id: <1501123989-197208-1-git-send-email-dandan.bi@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.1 Subject: [edk2] [patch] BaseTools/VfrCompile: Fix segmentation fault issues 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: Bo Chen , 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" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D532 (1) Add NULL check before using a pointer. (2) Use "%s" format string in DebugError function to avoid crash caused by incorrect input. Cc: Bo Chen Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Dandan Bi Reviewed-by: Eric Dong --- BaseTools/Source/C/VfrCompile/VfrCompiler.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp b/BaseTools/Sour= ce/C/VfrCompile/VfrCompiler.cpp index ff7057a..e65a925 100644 --- a/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp +++ b/BaseTools/Source/C/VfrCompile/VfrCompiler.cpp @@ -640,11 +640,11 @@ CVfrCompiler::PreProcess ( if (mOptions.SkipCPreprocessor =3D=3D TRUE) { goto Out; } =20 if ((pVfrFile =3D fopen (LongFilePath (mOptions.VfrFileName), "r")) =3D= =3D NULL) { - DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOption= s.VfrFileName); + DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", m= Options.VfrFileName); goto Fail; } fclose (pVfrFile); =20 CmdLen =3D strlen (mPreProcessCmd) + strlen (mPreProcessOpt) +=20 @@ -709,11 +709,11 @@ CVfrCompiler::Compile ( =20 gCVfrErrorHandle.SetInputFile (InFileName); gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError); =20 if ((pInFile =3D fopen (LongFilePath (InFileName), "r")) =3D=3D NULL) { - DebugError (NULL, 0, 0001, "Error opening the input file", InFileName); + DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFil= eName); goto Fail; } =20 InputInfo.CompatibleMode =3D mOptions.CompatibleMode; if (mOptions.HasOverrideClassGuid) { @@ -839,11 +839,11 @@ CVfrCompiler::GenBinary ( goto Fail; } =20 if (mOptions.CreateIfrPkgFile =3D=3D TRUE) { if ((pFile =3D fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")= ) =3D=3D NULL) { - DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputF= ileName); + DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgO= utputFileName); goto Fail; } if (gCFormPkg.BuildPkg (pFile, &gRBuffer) !=3D VFR_RETURN_SUCCESS) { fclose (pFile); goto Fail; @@ -882,11 +882,11 @@ CVfrCompiler::GenCFile ( goto Fail; } =20 if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) { if ((pFile =3D fopen (LongFilePath (mOptions.COutputFileName), "w")) = =3D=3D NULL) { - DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.C= OutputFileName); + DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOpt= ions.COutputFileName); goto Fail; } =20 for (Index =3D 0; gSourceFileHeader[Index] !=3D NULL; Index++) { fprintf (pFile, "%s\n", gSourceFileHeader[Index]); @@ -923,22 +923,22 @@ CVfrCompiler::GenRecordListFile ( CHAR8 LineBuf[MAX_VFR_LINE_LEN]; UINT32 LineNo; =20 InFileName =3D (mOptions.SkipCPreprocessor =3D=3D TRUE) ? mOptions.VfrFi= leName : mOptions.PreprocessorOutputFileName; =20 - if (mOptions.CreateRecordListFile =3D=3D TRUE) { + if (mOptions.CreateRecordListFile =3D=3D TRUE && InFileName !=3D NULL &&= mOptions.RecordListFile !=3D NULL) { if ((InFileName[0] =3D=3D '\0') || (mOptions.RecordListFile[0] =3D=3D = '\0')) { return; } =20 if ((pInFile =3D fopen (LongFilePath (InFileName), "r")) =3D=3D NULL) { - DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor= output file", InFileName); + DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor= output file", "%s", InFileName); return; } =20 if ((pOutFile =3D fopen (LongFilePath (mOptions.RecordListFile), "w"))= =3D=3D NULL) { - DebugError (NULL, 0, 0001, "Error opening the record list file", mOp= tions.RecordListFile); + DebugError (NULL, 0, 0001, "Error opening the record list file", "%s= ", mOptions.RecordListFile); goto Err1; } =20 fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSIO= N __BUILD_VERSION "\n//\n"); LineNo =3D 0; --=20 1.9.5.msysgit.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel