From roberto@keltia.freenix.fr  Thu Apr  3 10:15:33 1997
Received: from mexico.brainstorm.eu.org (mexico.brainstorm.fr [193.56.58.253])
          by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id KAA06527
          for <FreeBSD-gnats-submit@freebsd.org>; Thu, 3 Apr 1997 10:15:30 -0800 (PST)
Received: from brasil.brainstorm.eu.org (brasil.brainstorm.fr [193.56.58.33])
          by mexico.brainstorm.eu.org (8.8.4/8.8.4) with ESMTP
	  id UAA30426 for <FreeBSD-gnats-submit@freebsd.org>; Thu, 3 Apr 1997 20:15:24 +0200
Received: (from uucp@localhost) by brasil.brainstorm.eu.org (8.8.4/8.6.12) with UUCP id UAA07081 for FreeBSD-gnats-submit@freebsd.org; Thu, 3 Apr 1997 20:15:01 +0200
Received: (from roberto@localhost) by keltia.freenix.fr (8.8.5/keltia-uucp-2.9) id UAA01773;
          Thu, 3 Apr 1997 20:06:14 +0200 (CEST)
Message-Id: <199704031806.UAA01773@keltia.freenix.fr>
Date: Thu, 3 Apr 1997 20:06:14 +0200 (CEST)
From: Ollivier Robert <roberto@keltia.freenix.fr>
Reply-To: roberto@keltia.freenix.fr
To: FreeBSD-gnats-submit@freebsd.org
Subject: file(1) 3.22 doesn't work well with ELF binaries
X-Send-Pr-Version: 3.2

>Number:         3188
>Category:       bin
>Synopsis:       Reading the ELF header leads to an error
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    mpp
>State:          closed
>Quarter:
>Keywords:
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr  3 10:20:04 PST 1997
>Closed-Date:    Thu Apr 3 18:23:48 PST 1997
>Last-Modified:  Thu Apr  3 18:24:15 PST 1997
>Originator:     Ollivier Robert
>Release:        FreeBSD 3.0-CURRENT i386
>Organization:
Usenet Canal Historique
>Environment:

CURRENT from March, 23th.

285 [19:58] roberto@keltia:/tmp/file> file -v
file-3.22

>Description:

The new file(1) is trying to directly read ELF headers to show
information. It seems that the following section of code is failing:

static void
doshn(fd, off, num, size, buf)
        int fd;
        off_t off;
        int num;
        size_t size;
        char *buf;
{
        /*
         * This works for both 32-bit and 64-bit ELF formats,
         * because it looks only at the "sh_type" field, which is
         * always 32 bits, and is preceded only by the "sh_name"
         * field which is also always 32 bits, and because it uses
         * the shdr size from the ELF header rather than using
         * the size of an "Elf32_Shdr".
         */
        Elf32_Shdr *sh = (Elf32_Shdr *) buf;

        if (lseek(fd, off, SEEK_SET) == -1)
                error("lseek failed (%s).\n", strerror(errno));

        for ( ; num; num--) {
                if (read(fd, buf, size) == -1)
                        error("read failed (%s).\n", strerror(errno));
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>How-To-Repeat:

Trying to identify some ELF binaries (both Linux and FreeBSD ones)
leads to the following error message:

Linux:

284 [19:58] roberto@keltia:/tmp/file> file acroread 
acroread: ELF 32-bit LSB executable, Intel 80386, version 1file: read failed (Invalid argument).

FreeBSD:

286 [19:59] roberto@keltia:/tmp/file> file ../foo
../foo: ELF 32-bit LSB executable, Intel 80386, version 1file: read failed (Invalid argument).

The old method -- using /etc/magic ELF section -- worked right.

>Fix:
	
Unknown.
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mpp 
Responsible-Changed-By: mpp 
Responsible-Changed-When: Thu Apr 3 16:03:49 PST 1997 
Responsible-Changed-Why:  
I imported file 3.22. 
State-Changed-From-To: open->closed 
State-Changed-By: mpp 
State-Changed-When: Thu Apr 3 18:23:48 PST 1997 
State-Changed-Why:  
This was fixed in rev 1.2 of file/readelf.c on 3/29/97. 
>Unformatted:
