From owner-freebsd-bugs@FreeBSD.ORG Sun Feb 17 05:40:02 2013 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 3858CB0A for ; Sun, 17 Feb 2013 05:40:02 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) by mx1.freebsd.org (Postfix) with ESMTP id 2B29DA5A for ; Sun, 17 Feb 2013 05:40:02 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.6/8.14.6) with ESMTP id r1H5e2Ep006926 for ; Sun, 17 Feb 2013 05:40:02 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.6/8.14.6/Submit) id r1H5e2cF006925; Sun, 17 Feb 2013 05:40:02 GMT (envelope-from gnats) Date: Sun, 17 Feb 2013 05:40:02 GMT Message-Id: <201302170540.r1H5e2cF006925@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Mark Johnston Subject: Re: bin/175491: [libelf] elf_getdata may return NULL without setting error-message X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: Mark Johnston List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Feb 2013 05:40:02 -0000 The following reply was made to PR bin/175491; it has been noted by GNATS. From: Mark Johnston To: bug-followup@FreeBSD.org, mi@aldan.algebra.com Cc: Subject: Re: bin/175491: [libelf] elf_getdata may return NULL without setting error-message Date: Sun, 17 Feb 2013 00:31:03 -0500 --jousvV0MzM2p6OtC Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Looks like this was fixed in upstream libelf with r1765 and r1766. The same bug exists in elf_rawdata(), and this han't been fixed upstream either. I'll try to get this fixed both upstream and in FreeBSD's libelf; in the meantime, the attached patch should fix the problem. -Mark --jousvV0MzM2p6OtC Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="libelf_nullscn.diff" diff --git a/lib/libelf/elf_data.c b/lib/libelf/elf_data.c index c34c4ad..d3bd390 100644 --- a/lib/libelf/elf_data.c +++ b/lib/libelf/elf_data.c @@ -78,8 +78,10 @@ elf_getdata(Elf_Scn *s, Elf_Data *d) sh_align = s->s_shdr.s_shdr64.sh_addralign; } - if (sh_type == SHT_NULL) + if (sh_type == SHT_NULL) { + LIBELF_SET_ERROR(SECTION, 0); return (NULL); + } if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST || elftype > ELF_T_LAST || (sh_type != SHT_NOBITS && @@ -219,8 +221,10 @@ elf_rawdata(Elf_Scn *s, Elf_Data *d) sh_align = s->s_shdr.s_shdr64.sh_addralign; } - if (sh_type == SHT_NULL) + if (sh_type == SHT_NULL) { + LIBELF_SET_ERROR(SECTION, 0); return (NULL); + } if ((d = _libelf_allocate_data(s)) == NULL) return (NULL); --jousvV0MzM2p6OtC--