Author: kaiw
Date: Sat Sep  4 12:40:16 2010
New Revision: 212203
URL: http://svn.freebsd.org/changeset/base/212203

Log:
  MFC r210329,r210330,r210347.
  
  r210329:
    Use <unistd.h> to declare the prototype for ftruncate().
  
  r210330:
    Allow an application that updates only the ELF Ehdr to work.
  
  r210347:
    Fix a memory leak.

Modified:
  stable/7/lib/libelf/_libelf.h
  stable/7/lib/libelf/elf_begin.c
  stable/7/lib/libelf/elf_scn.c
  stable/7/lib/libelf/elf_update.c
Directory Properties:
  stable/7/lib/libelf/   (props changed)

Modified: stable/7/lib/libelf/_libelf.h
==============================================================================
--- stable/7/lib/libelf/_libelf.h       Sat Sep  4 12:40:06 2010        
(r212202)
+++ stable/7/lib/libelf/_libelf.h       Sat Sep  4 12:40:16 2010        
(r212203)
@@ -176,6 +176,7 @@ void        (*_libelf_get_translator(Elf_Type _
 void   *_libelf_getphdr(Elf *_e, int _elfclass);
 void   *_libelf_getshdr(Elf_Scn *_scn, int _elfclass);
 void   _libelf_init_elf(Elf *_e, Elf_Kind _kind);
+int    _libelf_load_scn(Elf *e, void *ehdr);
 int    _libelf_malign(Elf_Type _t, int _elfclass);
 size_t _libelf_msize(Elf_Type _t, int _elfclass, unsigned int _version);
 void   *_libelf_newphdr(Elf *_e, int _elfclass, size_t _count);

Modified: stable/7/lib/libelf/elf_begin.c
==============================================================================
--- stable/7/lib/libelf/elf_begin.c     Sat Sep  4 12:40:06 2010        
(r212202)
+++ stable/7/lib/libelf/elf_begin.c     Sat Sep  4 12:40:16 2010        
(r212203)
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
 #include <ar.h>
 #include <ctype.h>
 #include <libelf.h>
+#include <unistd.h>
 
 #include "_libelf.h"
 

Modified: stable/7/lib/libelf/elf_scn.c
==============================================================================
--- stable/7/lib/libelf/elf_scn.c       Sat Sep  4 12:40:06 2010        
(r212202)
+++ stable/7/lib/libelf/elf_scn.c       Sat Sep  4 12:40:16 2010        
(r212203)
@@ -38,7 +38,7 @@ __FBSDID("$FreeBSD$");
 /*
  * Load an ELF section table and create a list of Elf_Scn structures.
  */
-static int
+int
 _libelf_load_scn(Elf *e, void *ehdr)
 {
        int ec, swapbytes;

Modified: stable/7/lib/libelf/elf_update.c
==============================================================================
--- stable/7/lib/libelf/elf_update.c    Sat Sep  4 12:40:06 2010        
(r212202)
+++ stable/7/lib/libelf/elf_update.c    Sat Sep  4 12:40:16 2010        
(r212203)
@@ -472,6 +472,11 @@ _libelf_resync_elf(Elf *e)
         * file.
         */
 
+       if (e->e_cmd != ELF_C_WRITE &&
+           (e->e_flags & LIBELF_F_SHDRS_LOADED) == 0 &&
+           _libelf_load_scn(e, ehdr) == 0)
+               return ((off_t) -1);
+
        if ((rc = _libelf_resync_sections(e, rc)) < 0)
                return ((off_t) -1);
 
@@ -726,14 +731,9 @@ _libelf_write_elf(Elf *e, off_t newsize)
                assert(phoff % _libelf_falign(ELF_T_PHDR, ec) == 0);
                assert(fsz > 0);
 
+               src.d_buf = _libelf_getphdr(e, ec);
                src.d_version = dst.d_version = e->e_version;
                src.d_type = ELF_T_PHDR;
-
-               if (ec == ELFCLASS32)
-                       src.d_buf = e->e_u.e_elf.e_phdr.e_phdr32;
-               else
-                       src.d_buf = e->e_u.e_elf.e_phdr.e_phdr64;
-
                src.d_size = phnum * _libelf_msize(ELF_T_PHDR, ec,
                    e->e_version);
 
@@ -855,11 +855,13 @@ _libelf_write_elf(Elf *e, off_t newsize)
                e->e_u.e_elf.e_phdr.e_phdr64 = NULL;
        }
 
+       free(newfile);
+
        return (rc);
 
  error:
-       if (newfile)
-               free(newfile);
+       free(newfile);
+
        return ((off_t) -1);
 }
 
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to