public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
@ 2018-06-07  2:02 Yonghong Zhu
  2018-06-08  3:38 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Zhu @ 2018-06-07  2:02 UTC (permalink / raw)
  To: edk2-devel; +Cc: Yunhua Feng, Liming Gao

From: Yunhua Feng <yunhuax.feng@intel.com>

Add the logic to check whether mCoffAlignment is larger than
MAX_COFF_ALIGNMENT, and report error for it.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
---
 BaseTools/Source/C/GenFw/Elf32Convert.c | 10 +++++++++-
 BaseTools/Source/C/GenFw/Elf64Convert.c | 11 ++++++++++-
 2 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
index 14fe4a2..e0f6491 100644
--- a/BaseTools/Source/C/GenFw/Elf32Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
@@ -1,9 +1,9 @@
 /** @file
 Elf32 Convert solution
 
-Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
 distribution.  The full text of the license may be found at
@@ -382,10 +382,18 @@ ScanSections32 (
       mCoffAlignment = (UINT32)shdr->sh_addralign;
     }
   }
 
   //
+  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
+  //
+  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
+    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
+    assert (FALSE);
+  }
+
+  //
   // Move the PE/COFF header right before the first section. This will help us
   // save space when converting to TE.
   //
   if (mCoffAlignment > mCoffOffset) {
     mNtHdrOffset += mCoffAlignment - mCoffOffset;
diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
index c39bdff..9e68d22 100644
--- a/BaseTools/Source/C/GenFw/Elf64Convert.c
+++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
@@ -1,9 +1,9 @@
 /** @file
 Elf64 convert solution
 
-Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
 Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
 
 This program and the accompanying materials are licensed and made available
 under the terms and conditions of the BSD License which accompanies this
 distribution.  The full text of the license may be found at
@@ -375,10 +375,19 @@ ScanSections64 (
       mCoffAlignment = (UINT32)shdr->sh_addralign;
     }
   }
 
   //
+  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
+  //
+  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
+    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
+    assert (FALSE);
+  }
+
+
+  //
   // Move the PE/COFF header right before the first section. This will help us
   // save space when converting to TE.
   //
   if (mCoffAlignment > mCoffOffset) {
     mNtHdrOffset += mCoffAlignment - mCoffOffset;
-- 
2.6.1.windows.1



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

* Re: [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
  2018-06-07  2:02 [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT Yonghong Zhu
@ 2018-06-08  3:38 ` Gao, Liming
  0 siblings, 0 replies; 2+ messages in thread
From: Gao, Liming @ 2018-06-08  3:38 UTC (permalink / raw)
  To: Zhu, Yonghong, edk2-devel@lists.01.org; +Cc: Feng, YunhuaX

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

> -----Original Message-----
> From: Zhu, Yonghong
> Sent: Thursday, June 7, 2018 10:03 AM
> To: edk2-devel@lists.01.org
> Cc: Feng, YunhuaX <yunhuax.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT
> 
> From: Yunhua Feng <yunhuax.feng@intel.com>
> 
> Add the logic to check whether mCoffAlignment is larger than
> MAX_COFF_ALIGNMENT, and report error for it.
> 
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Yonghong Zhu <yonghong.zhu@intel.com>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Yunhua Feng <yunhuax.feng@intel.com>
> ---
>  BaseTools/Source/C/GenFw/Elf32Convert.c | 10 +++++++++-
>  BaseTools/Source/C/GenFw/Elf64Convert.c | 11 ++++++++++-
>  2 files changed, 19 insertions(+), 2 deletions(-)
> 
> diff --git a/BaseTools/Source/C/GenFw/Elf32Convert.c b/BaseTools/Source/C/GenFw/Elf32Convert.c
> index 14fe4a2..e0f6491 100644
> --- a/BaseTools/Source/C/GenFw/Elf32Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf32Convert.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Elf32 Convert solution
> 
> -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
>  Portions copyright (c) 2013, ARM Ltd. All rights reserved.<BR>
> 
>  This program and the accompanying materials are licensed and made available
>  under the terms and conditions of the BSD License which accompanies this
>  distribution.  The full text of the license may be found at
> @@ -382,10 +382,18 @@ ScanSections32 (
>        mCoffAlignment = (UINT32)shdr->sh_addralign;
>      }
>    }
> 
>    //
> +  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
> +  //
> +  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
> +    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
> +    assert (FALSE);
> +  }
> +
> +  //
>    // Move the PE/COFF header right before the first section. This will help us
>    // save space when converting to TE.
>    //
>    if (mCoffAlignment > mCoffOffset) {
>      mNtHdrOffset += mCoffAlignment - mCoffOffset;
> diff --git a/BaseTools/Source/C/GenFw/Elf64Convert.c b/BaseTools/Source/C/GenFw/Elf64Convert.c
> index c39bdff..9e68d22 100644
> --- a/BaseTools/Source/C/GenFw/Elf64Convert.c
> +++ b/BaseTools/Source/C/GenFw/Elf64Convert.c
> @@ -1,9 +1,9 @@
>  /** @file
>  Elf64 convert solution
> 
> -Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.<BR>
> +Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
>  Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.<BR>
> 
>  This program and the accompanying materials are licensed and made available
>  under the terms and conditions of the BSD License which accompanies this
>  distribution.  The full text of the license may be found at
> @@ -375,10 +375,19 @@ ScanSections64 (
>        mCoffAlignment = (UINT32)shdr->sh_addralign;
>      }
>    }
> 
>    //
> +  // Check if mCoffAlignment larger than MAX_COFF_ALIGNMENT
> +  //
> +  if (mCoffAlignment > MAX_COFF_ALIGNMENT) {
> +    Error (NULL, 0, 3000, "Invalid", "Section alignment larger than MAX_COFF_ALIGNMENT.");
> +    assert (FALSE);
> +  }
> +
> +
> +  //
>    // Move the PE/COFF header right before the first section. This will help us
>    // save space when converting to TE.
>    //
>    if (mCoffAlignment > mCoffOffset) {
>      mNtHdrOffset += mCoffAlignment - mCoffOffset;
> --
> 2.6.1.windows.1



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

end of thread, other threads:[~2018-06-08  3:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-07  2:02 [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT Yonghong Zhu
2018-06-08  3:38 ` Gao, Liming

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