]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFfs: Avoid possible NULL pointer dereference
authorHao Wu <hao.a.wu@intel.com>
Tue, 11 Oct 2016 02:13:26 +0000 (10:13 +0800)
committerHao Wu <hao.a.wu@intel.com>
Tue, 8 Nov 2016 08:36:14 +0000 (16:36 +0800)
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/C/GenFfs/GenFfs.c

index 9a738cbb6a46f85a83d5d1ed6da636d7d44faa15..78e5097fb487db9eefbaae062be7bc0ec63d8016 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
 This file contains functions required to generate a Firmware File System file.\r
 \r
-Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2004 - 2016, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -842,7 +842,7 @@ Returns:
                );\r
   }\r
 \r
-  if (EFI_ERROR (Status)) {\r
+  if (EFI_ERROR (Status) || (FileBuffer == NULL)) {\r
     goto Finish;\r
   }\r
   \r
@@ -915,22 +915,24 @@ Returns:
   //\r
   // Open output file to write ffs data.\r
   //\r
-  remove(OutputFileName);\r
-  FfsFile = fopen (LongFilePath (OutputFileName), "wb");\r
-  if (FfsFile == NULL) {\r
-    Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
-    goto Finish;\r
-  }\r
-  //\r
-  // write header\r
-  //\r
-  fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);\r
-  //\r
-  // write data\r
-  //\r
-  fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
+  if (OutputFileName != NULL) {\r
+    remove(OutputFileName);\r
+    FfsFile = fopen (LongFilePath (OutputFileName), "wb");\r
+    if (FfsFile == NULL) {\r
+      Error (NULL, 0, 0001, "Error opening file", OutputFileName);\r
+      goto Finish;\r
+    }\r
+    //\r
+    // write header\r
+    //\r
+    fwrite (&FfsFileHeader, 1, HeaderSize, FfsFile);\r
+    //\r
+    // write data\r
+    //\r
+    fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
 \r
-  fclose (FfsFile);\r
+    fclose (FfsFile);\r
+  }\r
 \r
 Finish:\r
   if (InputFileName != NULL) {\r