Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oMd5T-00083e-AW for mharc-grub-devel@gnu.org; Fri, 12 Aug 2022 18:25:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMd5P-0007zu-Oo for grub-devel@gnu.org; Fri, 12 Aug 2022 18:24:59 -0400 Received: from mx0b-00069f02.pphosted.com ([205.220.177.32]:52584) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMd5K-0004mc-5I for grub-devel@gnu.org; Fri, 12 Aug 2022 18:24:58 -0400 Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27CLcrBV010397 for ; Fri, 12 Aug 2022 22:24:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2022-7-12; bh=aRsP5KeKyfMHlV6EKyPgTEfHrMmOnR5MuuLrVUr+ir4=; b=AcqPEowsYDMvuZE3U5c3aHVMb6REnM7jZ2ZJh1RVb4xVDODhSi8vXrAm3EwD+3uJAkZv y58h7UbuVA1hLoBIlvltdVh/oDW94uPCR/oeyaHrI9QXGjUi1PlPJ1q+rVaiMXkH4z8C qYBHure967o52JaNQ+d5P7ahkZWfpegvAxTyy6YQOLKueymx1KWkIcBgOZGDmAkT4CTV +KDIK0wjkoixHr0j67HUhO2IIOEoXcHNFxQ0jfKlW2AtWa9vnIPyWN1stUt3xbtx1hdM vg8JV4q4didIowJoBUlyui22KDIn+Y/y/7Ud2Raw7URtib7rr3t95bLid6UdamO8lB+S 7w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3huwqbru1y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 12 Aug 2022 22:24:51 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 27CJfuFN018956 for ; Fri, 12 Aug 2022 22:24:51 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3huwqmf9u4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 12 Aug 2022 22:24:50 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27CMKvOP038695 for ; Fri, 12 Aug 2022 22:24:50 GMT Received: from localhost (dhcp-10-152-14-18.usdhcp.oraclecorp.com [10.152.14.18]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3huwqmf9tw-1; Fri, 12 Aug 2022 22:24:50 +0000 From: Alec Brown To: grub-devel@gnu.org Cc: daniel.kiper@oracle.com, darren.kenny@oracle.com, alec.r.brown@oracle.com Subject: [PATCH v2 4/5] util/grub-module-verifierXX.c: Changed get_shnum() return type Date: Fri, 12 Aug 2022 18:25:48 -0400 Message-Id: <1660343149-8188-5-git-send-email-alec.r.brown@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1660343149-8188-1-git-send-email-alec.r.brown@oracle.com> References: <1660343149-8188-1-git-send-email-alec.r.brown@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-12_10,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 suspectscore=0 spamscore=0 phishscore=0 adultscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208120060 X-Proofpoint-GUID: 4EM_5u0O6AO5_sPzBTqtI5N3cdwRn1OG X-Proofpoint-ORIG-GUID: 4EM_5u0O6AO5_sPzBTqtI5N3cdwRn1OG Received-SPF: pass client-ip=205.220.177.32; envelope-from=alec.r.brown@oracle.com; helo=mx0b-00069f02.pphosted.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Aug 2022 22:25:00 -0000 In util/grub-module-verifierXX.c, the function get_shnum() returns the variable shnum, which is of the type Elf_Word. In the function, shnum can be obtained by the e_shnum member of an Elf_Ehdr or the sh_size member of an Elf_Shdr. The sh_size member can either be grub_uint32_t or grub_uint64_t, depending on the architecture, but Elf_Word is only grub_uint32_t. To account for when sh_size is grub_uint64_t, we can set shnum to have type Elf_Shnum and have get_shnum() return an Elf_Shnum. Signed-off-by: Alec Brown --- util/grub-module-verifierXX.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/util/grub-module-verifierXX.c b/util/grub-module-verifierXX.c index cf3ff0dfa..8e0cd91d9 100644 --- a/util/grub-module-verifierXX.c +++ b/util/grub-module-verifierXX.c @@ -18,6 +18,7 @@ # define Elf_Rel Elf32_Rel # define Elf_Word Elf32_Word # define Elf_Half Elf32_Half +# define Elf_Shnum Elf32_Shnum # define Elf_Section Elf32_Section # define ELF_R_SYM(val) ELF32_R_SYM(val) # define ELF_R_TYPE(val) ELF32_R_TYPE(val) @@ -36,6 +37,7 @@ # define Elf_Rel Elf64_Rel # define Elf_Word Elf64_Word # define Elf_Half Elf64_Half +# define Elf_Shnum Elf64_Shnum # define Elf_Section Elf64_Section # define ELF_R_SYM(val) ELF64_R_SYM(val) # define ELF_R_TYPE(val) ELF64_R_TYPE(val) @@ -141,11 +143,11 @@ get_shdr (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e, Elf_Word in index * grub_target_to_host16 (e->e_shentsize)); } -static Elf_Word +static Elf_Shnum get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) { Elf_Shdr *s; - Elf_Word shnum; + Elf_Shnum shnum; shnum = grub_target_to_host16 (e->e_shnum); if (shnum == SHN_UNDEF) @@ -153,12 +155,12 @@ get_shnum (const struct grub_module_verifier_arch *arch, Elf_Ehdr *e) s = get_shdr (arch, e, 0); shnum = grub_target_to_host (s->sh_size); if (shnum < SHN_LORESERVE) - grub_util_error ("Invalid number of section header table entries in sh_size: %d", shnum); + grub_util_error ("Invalid number of section header table entries in sh_size: %" PRIuGRUB_UINT64_T, (grub_uint64_t) shnum); } else { if (shnum >= SHN_LORESERVE) - grub_util_error ("Invalid number of section header table entries in e_shnum: %d", shnum); + grub_util_error ("Invalid number of section header table entries in e_shnum: %" PRIuGRUB_UINT64_T, (grub_uint64_t) shnum); } return shnum; -- 2.27.0