]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/VfrCompile: Fix segmentation fault issues
authorDandan Bi <dandan.bi@intel.com>
Tue, 11 Jul 2017 07:35:14 +0000 (15:35 +0800)
committerHao Wu <hao.a.wu@intel.com>
Fri, 4 Aug 2017 06:32:42 +0000 (14:32 +0800)
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 <chenbo@pdx.edu>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Dandan Bi <dandan.bi@intel.com>
Reviewed-by: Eric Dong <eric.dong@intel.com>
BaseTools/Source/C/VfrCompile/VfrCompiler.cpp

index ff7057a64f4ca751f8da07bd45de8f9e2c5e6a50..e65a92534f0de1eb6dc568e85e08bffb5b37c480 100644 (file)
@@ -642,7 +642,7 @@ CVfrCompiler::PreProcess (
   }\r
 \r
   if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input VFR file", mOptions.VfrFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName);\r
     goto Fail;\r
   }\r
   fclose (pVfrFile);\r
@@ -711,7 +711,7 @@ CVfrCompiler::Compile (
   gCVfrErrorHandle.SetWarningAsError(mOptions.WarningAsError);\r
 \r
   if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-    DebugError (NULL, 0, 0001, "Error opening the input file", InFileName);\r
+    DebugError (NULL, 0, 0001, "Error opening the input file", "%s", InFileName);\r
     goto Fail;\r
   }\r
 \r
@@ -841,7 +841,7 @@ CVfrCompiler::GenBinary (
 \r
   if (mOptions.CreateIfrPkgFile == TRUE) {\r
     if ((pFile = fopen (LongFilePath (mOptions.PkgOutputFileName), "wb")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening file", mOptions.PkgOutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening file", "%s", mOptions.PkgOutputFileName);\r
       goto Fail;\r
     }\r
     if (gCFormPkg.BuildPkg (pFile, &gRBuffer) != VFR_RETURN_SUCCESS) {\r
@@ -884,7 +884,7 @@ CVfrCompiler::GenCFile (
   \r
   if (!mOptions.CreateIfrPkgFile || mOptions.CompatibleMode) {\r
     if ((pFile = fopen (LongFilePath (mOptions.COutputFileName), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening output C file", mOptions.COutputFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening output C file", "%s", mOptions.COutputFileName);\r
       goto Fail;\r
     }\r
 \r
@@ -925,18 +925,18 @@ CVfrCompiler::GenRecordListFile (
 \r
   InFileName = (mOptions.SkipCPreprocessor == TRUE) ? mOptions.VfrFileName : mOptions.PreprocessorOutputFileName;\r
 \r
-  if (mOptions.CreateRecordListFile == TRUE) {\r
+  if (mOptions.CreateRecordListFile == TRUE && InFileName != NULL && mOptions.RecordListFile != NULL) {\r
     if ((InFileName[0] == '\0') || (mOptions.RecordListFile[0] == '\0')) {\r
       return;\r
     }\r
 \r
     if ((pInFile = fopen (LongFilePath (InFileName), "r")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", InFileName);\r
+      DebugError (NULL, 0, 0001, "Error opening the input VFR preprocessor output file", "%s", InFileName);\r
       return;\r
     }\r
 \r
     if ((pOutFile = fopen (LongFilePath (mOptions.RecordListFile), "w")) == NULL) {\r
-      DebugError (NULL, 0, 0001, "Error opening the record list file", mOptions.RecordListFile);\r
+      DebugError (NULL, 0, 0001, "Error opening the record list file", "%s", mOptions.RecordListFile);\r
       goto Err1;\r
     }\r
 \r