Some code cleanup:
 - disable elf_load_phdrs() and elf_fix_phdrs() functions as there
   aren't in used. I also add a comment for elf_load_phdrs(): the code
   seems as buggy as elf_load_shdrs() against crafted input.

   Some other code could be dead too: I have not investigated a lot in
   this direction for now.
 
 - change some if(x) free(x) idioms to free(x)

-- 
Sébastien Marie


Index: elf.c
===================================================================
RCS file: /cvs/src/usr.bin/nm/elf.c,v
retrieving revision 1.28
diff -u -p -r1.28 elf.c
--- elf.c       17 May 2015 20:19:08 -0000      1.28
+++ elf.c       19 Jun 2015 06:48:48 -0000
@@ -170,6 +170,8 @@ elf_load_shdrs(const char *name, FILE *f
        return (shdr);
 }
 
+#if 0
+/* XXX: elf_load_phdrs need code review against crafted input */
 Elf_Phdr *
 elf_load_phdrs(const char *name, FILE *fp, off_t foff, Elf_Ehdr *head)
 {
@@ -195,6 +197,7 @@ elf_load_phdrs(const char *name, FILE *f
        elf_fix_phdrs(head, phdr);
        return (phdr);
 }
+#endif
 
 int
 elf_fix_shdrs(Elf_Ehdr *eh, Elf_Shdr *shdr)
@@ -221,6 +224,7 @@ elf_fix_shdrs(Elf_Ehdr *eh, Elf_Shdr *sh
        return (1);
 }
 
+#if 0
 int
 elf_fix_phdrs(Elf_Ehdr *eh, Elf_Phdr *phdr)
 {
@@ -243,6 +247,7 @@ elf_fix_phdrs(Elf_Ehdr *eh, Elf_Phdr *ph
 
        return (1);
 }
+#endif
 
 int
 elf_fix_sym(Elf_Ehdr *eh, Elf_Sym *sym)
@@ -562,10 +567,8 @@ elf_symload(const char *name, FILE *fp, 
        free(shstr);
        if (stab == NULL) {
                warnx("%s: no name list", name);
-               if (*pnames)
-                       free(*pnames);
-               if (*psnames)
-                       free(*psnames);
+               free(*pnames);
+               free(*psnames);
                return (1);
        }
 
Index: elfuncs.h
===================================================================
RCS file: /cvs/src/usr.bin/nm/elfuncs.h,v
retrieving revision 1.3
diff -u -p -r1.3 elfuncs.h
--- elfuncs.h   30 Sep 2006 14:34:13 -0000      1.3
+++ elfuncs.h   19 Jun 2015 06:48:48 -0000
@@ -30,9 +30,9 @@ extern char *stab;
 
 int    elf32_fix_header(Elf32_Ehdr *eh);
 Elf32_Shdr*elf32_load_shdrs(const char *, FILE *, off_t, Elf32_Ehdr *);
-Elf32_Phdr*elf32_load_phdrs(const char *, FILE *, off_t, Elf32_Ehdr *);
+/*Elf32_Phdr*elf32_load_phdrs(const char *, FILE *, off_t, Elf32_Ehdr *);*/
 int    elf32_fix_shdrs(Elf32_Ehdr *eh, Elf32_Shdr *shdr);
-int    elf32_fix_phdrs(Elf32_Ehdr *eh, Elf32_Phdr *phdr);
+/*int  elf32_fix_phdrs(Elf32_Ehdr *eh, Elf32_Phdr *phdr);*/
 int    elf32_fix_sym(Elf32_Ehdr *eh, Elf32_Sym *sym);
 int    elf32_size(Elf32_Ehdr *, Elf32_Shdr *, u_long *, u_long *, u_long *);
 int    elf32_symloadx(const char *, FILE *, off_t, Elf32_Ehdr *, Elf32_Shdr *,
@@ -43,9 +43,9 @@ int   elf32_symload(const char *, FILE *, 
 
 int    elf64_fix_header(Elf64_Ehdr *eh);
 Elf64_Shdr*elf64_load_shdrs(const char *, FILE *, off_t, Elf64_Ehdr *);
-Elf64_Phdr*elf64_load_phdrs(const char *, FILE *, off_t, Elf64_Ehdr *);
+/*Elf64_Phdr*elf64_load_phdrs(const char *, FILE *, off_t, Elf64_Ehdr *);*/
 int    elf64_fix_shdrs(Elf64_Ehdr *eh, Elf64_Shdr *shdr);
-int    elf64_fix_phdrs(Elf64_Ehdr *eh, Elf64_Phdr *phdr);
+/*int  elf64_fix_phdrs(Elf64_Ehdr *eh, Elf64_Phdr *phdr);*/
 int    elf64_fix_sym(Elf64_Ehdr *eh, Elf64_Sym *sym);
 int    elf64_size(Elf64_Ehdr *, Elf64_Shdr *, u_long *, u_long *, u_long *);
 int    elf64_symloadx(const char *, FILE *, off_t, Elf64_Ehdr *, Elf64_Shdr *,

Reply via email to