Author: emaste
Date: Wed Apr 30 18:11:53 2014
New Revision: 265157
URL: http://svnweb.freebsd.org/changeset/base/265157

Log:
  kldxref: Clean up error reporting
  
  Omit "too many sections" warnings if the ELF file is not dynamically
  linked (and is therefore skipped anyway), and otherwise output it only
  once.  An errant core file would previously cause kldxref to output a
  number of warnings.
  
  Also introduce a MAXSEGS #define and replace literal 2 with it, to make
  comparisons clear.
  
  Reviewed by:  kib
  Sponsored by: The FreeBSD Foundation

Modified:
  head/usr.sbin/kldxref/ef.c

Modified: head/usr.sbin/kldxref/ef.c
==============================================================================
--- head/usr.sbin/kldxref/ef.c  Wed Apr 30 18:02:19 2014        (r265156)
+++ head/usr.sbin/kldxref/ef.c  Wed Apr 30 18:11:53 2014        (r265157)
@@ -47,6 +47,7 @@
 
 #include "ef.h"
 
+#define        MAXSEGS 2
 struct ef_file {
        char*           ef_name;
        struct elf_file *ef_efile;
@@ -68,7 +69,7 @@ struct ef_file {
        Elf_Off         ef_symoff;
        Elf_Sym*        ef_symtab;
        int             ef_nsegs;
-       Elf_Phdr *      ef_segs[2];
+       Elf_Phdr *      ef_segs[MAXSEGS];
        int             ef_verbose;
        Elf_Rel *       ef_rel;                 /* relocation table */
        int             ef_relsz;               /* number of entries */
@@ -580,12 +581,9 @@ ef_open(const char *filename, struct elf
                                ef_print_phdr(phdr);
                        switch (phdr->p_type) {
                        case PT_LOAD:
-                               if (nsegs == 2) {
-                                       warnx("%s: too many sections",
-                                           filename);
-                                       break;
-                               }
-                               ef->ef_segs[nsegs++] = phdr;
+                               if (nsegs < MAXSEGS)
+                                       ef->ef_segs[nsegs] = phdr;
+                               nsegs++;
                                break;
                        case PT_PHDR:
                                break;
@@ -597,12 +595,15 @@ ef_open(const char *filename, struct elf
                }
                if (verbose > 1)
                        printf("\n");
-               ef->ef_nsegs = nsegs;
                if (phdyn == NULL) {
                        warnx("Skipping %s: not dynamically-linked",
                            filename);
                        break;
+               } else if (nsegs > MAXSEGS) {
+                       warnx("%s: too many sections", filename);
+                       break;
                }
+               ef->ef_nsegs = nsegs;
                if (ef_read_entry(ef, phdyn->p_offset,
                        phdyn->p_filesz, (void**)&ef->ef_dyn) != 0) {
                        printf("ef_read_entry failed\n");
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to