From owner-svn-src-all@freebsd.org Fri Dec 16 01:39:08 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30B61C82643; Fri, 16 Dec 2016 01:39:08 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 005A91BFA; Fri, 16 Dec 2016 01:39:07 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uBG1d7bD012778; Fri, 16 Dec 2016 01:39:07 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uBG1d7hN012777; Fri, 16 Dec 2016 01:39:07 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201612160139.uBG1d7hN012777@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Fri, 16 Dec 2016 01:39:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r310136 - head/contrib/elftoolchain/libelf X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Dec 2016 01:39:08 -0000 Author: cem Date: Fri Dec 16 01:39:06 2016 New Revision: 310136 URL: https://svnweb.freebsd.org/changeset/base/310136 Log: libelf: Fix extended numbering detection Extended numbering is used for any of these fields overflowing. Reviewed by: emaste@ Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D8701 Modified: head/contrib/elftoolchain/libelf/libelf_ehdr.c Modified: head/contrib/elftoolchain/libelf/libelf_ehdr.c ============================================================================== --- head/contrib/elftoolchain/libelf/libelf_ehdr.c Fri Dec 16 01:37:44 2016 (r310135) +++ head/contrib/elftoolchain/libelf/libelf_ehdr.c Fri Dec 16 01:39:06 2016 (r310136) @@ -170,10 +170,6 @@ _libelf_ehdr(Elf *e, int ec, int allocat (*xlator)((unsigned char*) ehdr, msz, e->e_rawfile, (size_t) 1, e->e_byteorder != LIBELF_PRIVATE(byteorder)); - /* - * If extended numbering is being used, read the correct - * number of sections and program header entries. - */ if (ec == ELFCLASS32) { phnum = ((Elf32_Ehdr *) ehdr)->e_phnum; shnum = ((Elf32_Ehdr *) ehdr)->e_shnum; @@ -193,12 +189,19 @@ _libelf_ehdr(Elf *e, int ec, int allocat return (NULL); } - if (shnum != 0 || shoff == 0LL) { /* not using extended numbering */ + /* + * If extended numbering is being used, read the correct + * number of sections and program header entries. + */ + if ((shnum == 0 && shoff != 0) || phnum == PN_XNUM || strndx == SHN_XINDEX) { + if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0) + return (NULL); + } else { + /* not using extended numbering */ e->e_u.e_elf.e_nphdr = phnum; e->e_u.e_elf.e_nscn = shnum; e->e_u.e_elf.e_strndx = strndx; - } else if (_libelf_load_extended(e, ec, shoff, phnum, strndx) == 0) - return (NULL); + } return (ehdr); }