From owner-svn-src-head@FreeBSD.ORG Thu Jun 19 20:12:29 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 6FA9915B; Thu, 19 Jun 2014 20:12:29 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 430DA2693; Thu, 19 Jun 2014 20:12:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s5JKCT7t026922; Thu, 19 Jun 2014 20:12:29 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s5JKCTsU026921; Thu, 19 Jun 2014 20:12:29 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201406192012.s5JKCTsU026921@svn.freebsd.org> From: Marcel Moolenaar Date: Thu, 19 Jun 2014 20:12:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r267649 - head/usr.bin/elfdump X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jun 2014 20:12:29 -0000 Author: marcel Date: Thu Jun 19 20:12:28 2014 New Revision: 267649 URL: http://svnweb.freebsd.org/changeset/base/267649 Log: Don't dump core when the ELF file has no section headers. The ELF core files created by gcore are among those. Modified: head/usr.bin/elfdump/elfdump.c Modified: head/usr.bin/elfdump/elfdump.c ============================================================================== --- head/usr.bin/elfdump/elfdump.c Thu Jun 19 19:28:35 2014 (r267648) +++ head/usr.bin/elfdump/elfdump.c Thu Jun 19 20:12:28 2014 (r267649) @@ -495,11 +495,19 @@ main(int ac, char **av) phnum = elf_get_quarter(e, e, E_PHNUM); shentsize = elf_get_quarter(e, e, E_SHENTSIZE); p = (char *)e + phoff; - sh = (char *)e + shoff; - shnum = elf_get_shnum(e, sh); - shstrndx = elf_get_shstrndx(e, sh); - offset = elf_get_off(e, (char *)sh + shstrndx * shentsize, SH_OFFSET); - shstrtab = (char *)e + offset; + if (shoff > 0) { + sh = (char *)e + shoff; + shnum = elf_get_shnum(e, sh); + shstrndx = elf_get_shstrndx(e, sh); + offset = elf_get_off(e, (char *)sh + shstrndx * shentsize, + SH_OFFSET); + shstrtab = (char *)e + offset; + } else { + sh = NULL; + shnum = 0; + shstrndx = 0; + shstrtab = NULL; + } for (i = 0; (u_int64_t)i < shnum; i++) { name = elf_get_word(e, (char *)sh + i * shentsize, SH_NAME); offset = elf_get_off(e, (char *)sh + i * shentsize, SH_OFFSET); @@ -616,8 +624,6 @@ elf_print_ehdr(Elf32_Ehdr *e, void *sh) phentsize = elf_get_quarter(e, e, E_PHENTSIZE); phnum = elf_get_quarter(e, e, E_PHNUM); shentsize = elf_get_quarter(e, e, E_SHENTSIZE); - shnum = elf_get_shnum(e, sh); - shstrndx = elf_get_shstrndx(e, sh); fprintf(out, "\nelf header:\n"); fprintf(out, "\n"); fprintf(out, "\te_ident: %s %s %s\n", ei_classes[class], ei_data[data], @@ -633,8 +639,12 @@ elf_print_ehdr(Elf32_Ehdr *e, void *sh) fprintf(out, "\te_phentsize: %jd\n", (intmax_t)phentsize); fprintf(out, "\te_phnum: %jd\n", (intmax_t)phnum); fprintf(out, "\te_shentsize: %jd\n", (intmax_t)shentsize); - fprintf(out, "\te_shnum: %jd\n", (intmax_t)shnum); - fprintf(out, "\te_shstrndx: %jd\n", (intmax_t)shstrndx); + if (sh != NULL) { + shnum = elf_get_shnum(e, sh); + shstrndx = elf_get_shstrndx(e, sh); + fprintf(out, "\te_shnum: %jd\n", (intmax_t)shnum); + fprintf(out, "\te_shstrndx: %jd\n", (intmax_t)shstrndx); + } } static void @@ -697,6 +707,11 @@ elf_print_shdr(Elf32_Ehdr *e, void *sh) void *v; int i; + if (sh == NULL) { + fprintf(out, "\nNo section headers\n"); + return; + } + shentsize = elf_get_quarter(e, e, E_SHENTSIZE); shnum = elf_get_shnum(e, sh); fprintf(out, "\nsection header:\n");