From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=yonghong.zhu@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CBE3821157FFF for ; Wed, 6 Jun 2018 19:02:36 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jun 2018 19:02:36 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.49,485,1520924400"; d="scan'208";a="64962487" Received: from shwdeopenpsi168.ccr.corp.intel.com ([10.239.158.129]) by orsmga002.jf.intel.com with ESMTP; 06 Jun 2018 19:02:35 -0700 From: Yonghong Zhu To: edk2-devel@lists.01.org Cc: Yunhua Feng , Liming Gao Date: Thu, 7 Jun 2018 10:02:31 +0800 Message-Id: <1528336951-6212-1-git-send-email-yonghong.zhu@intel.com> X-Mailer: git-send-email 2.6.1.windows.1 Subject: [Patch] BaseTools: Check elf sections alignment with MAX_COFF_ALIGNMENT X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jun 2018 02:02:37 -0000 From: Yunhua Feng Add the logic to check whether mCoffAlignment is larger than MAX_COFF_ALIGNMENT, and report error for it. Cc: Liming Gao Cc: Yonghong Zhu Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Yunhua Feng --- 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.
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
Portions copyright (c) 2013, ARM Ltd. All rights reserved.
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.
+Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.
Portions copyright (c) 2013-2014, ARM Ltd. All rights reserved.
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