From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,418,1496127600"; d="scan'208";a="116147091" 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 From: Dandan Bi To: edk2-devel@lists.01.org Cc: Bo Chen , Liming Gao 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: [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: , X-List-Received-Date: Thu, 27 Jul 2017 02:52:32 -0000 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=532 (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 --- 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/Source/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 == TRUE) { goto Out; } if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) { - DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName); + DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName); goto Fail; } fclose (pVfrFile); CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) + @@ -709,11 +709,11 @@ CVfrCompiler::Compile ( gCVfrErrorHandle.SetInputFile (InFileName); gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError); if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) { - DebugError (NULL, 0, 0001, "Error opening the input file", InFileName); + DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName); goto Fail; } InputInfo.CompatibleMode = mOptions.CompatibleMode; if (mOptions.HasOverrideClassGuid) { @@ -839,11 +839,11 @@ CVfrCompiler::GenBinary ( goto Fail; } if (mOptions.CreateIfrPkgFile == TRUE) { if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) { - DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName); + DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgOutputFileName); goto Fail; } if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) { fclose (pFile); goto Fail; @@ -882,11 +882,11 @@ CVfrCompiler::GenCFile ( goto Fail; } if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) { if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) { - DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName); + DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOptions.COutputFileName); goto Fail; } for (Index = 0; gSourceFileHeader[Index] != NULL; Index++) { fprintf (pFile, "%s\n", gSourceFileHeader[Index]); @@ -923,22 +923,22 @@ CVfrCompiler::GenRecordListFile ( CHAR8 LineBuf[MAX_VFR_LINE_LEN]; UINT32 LineNo; InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName; - if (mOptions.CreateRecordListFile == TRUE) { + if (mOptions.CreateRecordListFile == TRUE && InFileName != NULL && mOptions.RecordListFile != NULL) { if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) { return; } if ((pInFile = fopen (LongFilePath (InFileName), "r")) == 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; } if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) { - DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile); + DebugError (NULL, 0, 0001, "Error opening the record list file", "%s", mOptions.RecordListFile); goto Err1; } fprintf (pOutFile, "//\n// VFR compiler version " VFR_COMPILER_VERSION __BUILD_VERSION "\n//\n"); LineNo = 0; -- 1.9.5.msysgit.1