]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/GenFfs: Fix return too early when input file is of size 0
authorHao Wu <hao.a.wu@intel.com>
Wed, 9 Nov 2016 15:00:01 +0000 (23:00 +0800)
committerHao Wu <hao.a.wu@intel.com>
Thu, 10 Nov 2016 08:28:33 +0000 (16:28 +0800)
Commit 2cb874352423fcfd180199e6de8298567dff8e7f eliminates possible NULL
pointer dereference in GenFfs tool source codes. However, it doesn't
correctly handle the case when the input file is of size 0. This will lead
to possible build issues.

This commits refine the logic to handle the above case.

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 78e5097fb487db9eefbaae062be7bc0ec63d8016..c5d657bd093cc3dcf2b407ea98063468e4a3aff7 100644 (file)
@@ -842,7 +842,12 @@ Returns:
                );\r
   }\r
 \r
-  if (EFI_ERROR (Status) || (FileBuffer == NULL)) {\r
+  if (EFI_ERROR (Status)) {\r
+    goto Finish;\r
+  }\r
+\r
+  if (FileBuffer == NULL && FileSize != 0) {\r
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");\r
     goto Finish;\r
   }\r
   \r
@@ -929,7 +934,9 @@ Returns:
     //\r
     // write data\r
     //\r
-    fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
+    if (FileBuffer != NULL) {\r
+      fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);\r
+    }\r
 \r
     fclose (FfsFile);\r
   }\r