This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[patch] BFD ieee.c fix


While trolling my source tree for something else I noticed the
following:

bfd/ieee.c:ieee_archive_p() seems quite leaky.  I made the following
trivial patch, but there's much more badness here that I don't have
time to go into.

The patch looks trivially correct (or at least "better than what was
there" -- it's hard to describe that function's memory handling as
"correct" 8-), and i've compiled the file, but made no attempt to test
it.



cgd
===================================================================
2000-10-17  Chris Demetriou  <cgd@sibyte.com>

	* ieee.c (ieee_archive_p): Plug one of many possible
	memory leaks in error handling.

Index: ieee.c
===================================================================
RCS file: /cvsroot/systemsw/tools/src/binutils/bfd/ieee.c,v
retrieving revision 1.1.1.2
retrieving revision 1.5
diff -c -r1.1.1.2 -r1.5
*** ieee.c	2000/10/10 00:18:36	1.1.1.2
--- ieee.c	2000/10/17 23:30:10	1.5
***************
*** 1343,1361 ****
    ieee->h.abfd = abfd;
  
    if (this_byte (&(ieee->h)) != Module_Beginning)
!     {
!       abfd->tdata.ieee_ar_data = save;
!       goto got_wrong_format_error;
!     }
  
    next_byte (&(ieee->h));
    library = read_id (&(ieee->h));
    if (strcmp (library, "LIBRARY") != 0)
!     {
!       bfd_release (abfd, ieee);
!       abfd->tdata.ieee_ar_data = save;
!       goto got_wrong_format_error;
!     }
    /* Throw away the filename */
    read_id (&(ieee->h));
  
--- 1343,1355 ----
    ieee->h.abfd = abfd;
  
    if (this_byte (&(ieee->h)) != Module_Beginning)
!     goto got_wrong_format_error;
  
    next_byte (&(ieee->h));
    library = read_id (&(ieee->h));
    if (strcmp (library, "LIBRARY") != 0)
!     goto got_wrong_format_error;
! 
    /* Throw away the filename */
    read_id (&(ieee->h));
  
***************
*** 1458,1463 ****
--- 1452,1459 ----
    return abfd->xvec;
  
   got_wrong_format_error:
+   bfd_release (abfd, ieee);
+   abfd->tdata.ieee_ar_data = save;
    bfd_set_error (bfd_error_wrong_format);
   error_return:
    if (elts != NULL)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]