Author: emaste
Date: Wed Jul 23 14:30:58 2014
New Revision: 269014
URL: http://svnweb.freebsd.org/changeset/base/269014

Log:
  MFC r265157: 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:
  stable/10/usr.sbin/kldxref/ef.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/kldxref/ef.c
==============================================================================
--- stable/10/usr.sbin/kldxref/ef.c     Wed Jul 23 14:29:28 2014        
(r269013)
+++ stable/10/usr.sbin/kldxref/ef.c     Wed Jul 23 14:30:58 2014        
(r269014)
@@ -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-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