Bug 10785 - memory access violation in bfd/opncls.c
Summary: memory access violation in bfd/opncls.c
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.21
: P2 critical
Target Milestone: ---
Assignee: Alan Modra
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-10-15 23:19 UTC by Jerker Bäck
Modified: 2009-10-16 20:29 UTC (History)
1 user (show)

See Also:
Host: x86_64-unknown-interix6.1
Target: x86_64-unknown-interix6.1
Build: x86_64-unknown-interix6.1
Last reconfirmed: 2009-10-16 05:34:14


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerker Bäck 2009-10-15 23:19:00 UTC
I get a memory access violation when running a 64-bit debug build of binutils 
current nm on x86_64 Interix. Like this:
nm-new /usr/lib/somelib

The shell print some lines and then become unresponsive

shell: Interix 64bit ksh (pdksh)
Compiler: Interix cc frontend of MS x64 compiler 15.00.30729.01

Running a 32bit Interix gcc 3.3 nm binary build will exit silently at same spot

The offending line is:
bfd/opncls.c(712): free (bim->buffer);
in this code block
-----------------------------------------------------------------------------  
if ((abfd->flags & BFD_IN_MEMORY) != 0)
    {
      /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
	 vector.
	 Until that's done, at least don't leak memory.  */
      struct bfd_in_memory *bim = (struct bfd_in_memory *) abfd->iostream;
      free (bim->buffer);
      free (bim);
      ret = TRUE;
    }
  else
    ret = abfd->iovec->bclose (abfd);

-----------------------------------------------------------------------------

Note that free should work even if there are no memory allocated
Comment 1 Alan Modra 2009-10-16 05:34:14 UTC
We have some dodgy memory allocation in peicode.h
Comment 2 Alan Modra 2009-10-16 07:10:53 UTC
Well, peicode.h alloc was OK until
http://sourceware.org/ml/binutils/2009-07/msg00255.html came along :-(
Comment 3 cvs-commit@gcc.gnu.org 2009-10-16 07:15:01 UTC
Subject: Bug 10785

CVSROOT:	/cvs/src
Module name:	src
Changes by:	amodra@sourceware.org	2009-10-16 07:14:44

Modified files:
	bfd            : ChangeLog opncls.c coff-alpha.c peicode.h 

Log message:
	PR binutils/10785
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Don't bfd_alloc
	bim and bim->buffer.  bfd_malloc instead.
	* peicode.h (pe_ILF_build_a_bfd): Similarly.
	(ILF_DATA_SIZE): Don't include bim.
	* opncls.c (bfd_close): Test bim->buffer non-NULL before freeing.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&r1=1.4815&r2=1.4816
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/opncls.c.diff?cvsroot=src&r1=1.58&r2=1.59
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/coff-alpha.c.diff?cvsroot=src&r1=1.40&r2=1.41
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/peicode.h.diff?cvsroot=src&r1=1.60&r2=1.61

Comment 4 Alan Modra 2009-10-16 07:51:39 UTC
Fixed
Comment 5 cvs-commit@gcc.gnu.org 2009-10-16 10:03:00 UTC
Subject: Bug 10785

CVSROOT:	/cvs/src
Module name:	src
Branch: 	binutils-2_20-branch
Changes by:	gingold@sourceware.org	2009-10-16 10:02:44

Modified files:
	bfd            : ChangeLog coff-alpha.c opncls.c peicode.h 

Log message:
	2009-10-16  Alan Modra  <amodra@bigpond.net.au>
	
	PR binutils/10785
	* coff-alpha.c (alpha_ecoff_get_elt_at_filepos): Don't bfd_alloc
	bim and bim->buffer.  bfd_malloc instead.
	* peicode.h (pe_ILF_build_a_bfd): Similarly.
	(ILF_DATA_SIZE): Don't include bim.
	* opncls.c (bfd_close): Test bim->buffer non-NULL before freeing.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.4761.2.25&r2=1.4761.2.26
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/coff-alpha.c.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.40&r2=1.40.6.1
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/opncls.c.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.57.2.1&r2=1.57.2.2
http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/bfd/peicode.h.diff?cvsroot=src&only_with_tag=binutils-2_20-branch&r1=1.59.2.1&r2=1.59.2.2

Comment 6 Jerker Bäck 2009-10-16 20:29:14 UTC
Problem gone in both 64bit and 32bit builds
Thanks