public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools
@ 2016-11-10  4:22 Hao Wu
  2016-11-10  4:22 ` [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0 Hao Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Hao Wu @ 2016-11-10  4:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Liming Gao, Yonghong Zhu

The series enhances the logic in GenFfs and GenSec tool to handle input
file of size 0 properly.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>

Hao Wu (2):
  BaseTools/GenFfs: Fix return too early when input file is of size 0
  BaseTools/GenSec: Return correct status when input file size is 0

 BaseTools/Source/C/GenFfs/GenFfs.c | 11 +++++++++--
 BaseTools/Source/C/GenSec/GenSec.c | 16 +++++++++++-----
 2 files changed, 20 insertions(+), 7 deletions(-)

-- 
1.9.5.msysgit.0



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0
  2016-11-10  4:22 [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Hao Wu
@ 2016-11-10  4:22 ` Hao Wu
  2016-11-10  4:22 ` [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0 Hao Wu
  2016-11-10  5:05 ` [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Gao, Liming
  2 siblings, 0 replies; 4+ messages in thread
From: Hao Wu @ 2016-11-10  4:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Liming Gao, Yonghong Zhu

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>
---
 BaseTools/Source/C/GenFfs/GenFfs.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/GenFfs/GenFfs.c b/BaseTools/Source/C/GenFfs/GenFfs.c
index 78e5097..c5d657b 100644
--- a/BaseTools/Source/C/GenFfs/GenFfs.c
+++ b/BaseTools/Source/C/GenFfs/GenFfs.c
@@ -842,7 +842,12 @@ Returns:
                );
   }
 
-  if (EFI_ERROR (Status) || (FileBuffer == NULL)) {
+  if (EFI_ERROR (Status)) {
+    goto Finish;
+  }
+
+  if (FileBuffer == NULL && FileSize != 0) {
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allocated!");
     goto Finish;
   }
   
@@ -929,7 +934,9 @@ Returns:
     //
     // write data
     //
-    fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
+    if (FileBuffer != NULL) {
+      fwrite (FileBuffer, 1, FileSize - HeaderSize, FfsFile);
+    }
 
     fclose (FfsFile);
   }
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0
  2016-11-10  4:22 [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Hao Wu
  2016-11-10  4:22 ` [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0 Hao Wu
@ 2016-11-10  4:22 ` Hao Wu
  2016-11-10  5:05 ` [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Gao, Liming
  2 siblings, 0 replies; 4+ messages in thread
From: Hao Wu @ 2016-11-10  4:22 UTC (permalink / raw)
  To: edk2-devel; +Cc: Hao Wu, Liming Gao, Yonghong Zhu

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>
---
 BaseTools/Source/C/GenSec/GenSec.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/BaseTools/Source/C/GenSec/GenSec.c b/BaseTools/Source/C/GenSec/GenSec.c
index 87d4fa8..9129b50 100644
--- a/BaseTools/Source/C/GenSec/GenSec.c
+++ b/BaseTools/Source/C/GenSec/GenSec.c
@@ -897,17 +897,23 @@ Returns:
     return Status;
   }
 
-  if (FileBuffer == NULL) {
-    return EFI_OUT_OF_RESOURCES;
-  }
-
   if (InputLength == 0) {
-    free (FileBuffer);
+    if (FileBuffer != NULL) {
+      free (FileBuffer);
+    }
     Error (NULL, 0, 2000, "Invalid parameter", "the size of input file %s can't be zero", InputFileName);
     return EFI_NOT_FOUND;
   }
 
   //
+  // InputLength != 0, but FileBuffer == NULL means out of resources.
+  //
+  if (FileBuffer == NULL) {
+    Error (NULL, 0, 4001, "Resource", "memory cannot be allcoated");
+    return EFI_OUT_OF_RESOURCES;
+  }
+
+  //
   // Now data is in FileBuffer + Offset
   //
   if (CompareGuid (VendorGuid, &mZeroGuid) == 0) {
-- 
1.9.5.msysgit.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools
  2016-11-10  4:22 [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Hao Wu
  2016-11-10  4:22 ` [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0 Hao Wu
  2016-11-10  4:22 ` [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0 Hao Wu
@ 2016-11-10  5:05 ` Gao, Liming
  2 siblings, 0 replies; 4+ messages in thread
From: Gao, Liming @ 2016-11-10  5:05 UTC (permalink / raw)
  To: Wu, Hao A, edk2-devel@lists.01.org; +Cc: Wu, Hao A

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of
> Hao Wu
> Sent: Thursday, November 10, 2016 12:22 PM
> To: edk2-devel@lists.01.org
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2] [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec
> tools
> 
> The series enhances the logic in GenFfs and GenSec tool to handle input
> file of size 0 properly.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> 
> Hao Wu (2):
>   BaseTools/GenFfs: Fix return too early when input file is of size 0
>   BaseTools/GenSec: Return correct status when input file size is 0
> 
>  BaseTools/Source/C/GenFfs/GenFfs.c | 11 +++++++++--
>  BaseTools/Source/C/GenSec/GenSec.c | 16 +++++++++++-----
>  2 files changed, 20 insertions(+), 7 deletions(-)
> 
> --
> 1.9.5.msysgit.0
> 
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.01.org
> https://lists.01.org/mailman/listinfo/edk2-devel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-11-10  5:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-10  4:22 [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Hao Wu
2016-11-10  4:22 ` [PATCH 1/2] BaseTools/GenFfs: Fix return too early when input file is of size 0 Hao Wu
2016-11-10  4:22 ` [PATCH 2/2] BaseTools/GenSec: Return correct status when input file size is 0 Hao Wu
2016-11-10  5:05 ` [PATCH 0/2] Handle input file of size 0 for GenFfs/GenSec tools Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox