Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Remove the last argument of elf_check_header(). It is ea...



details:   https://anonhg.NetBSD.org/src/rev/199cd6644f75
branches:  trunk
changeset: 793475:199cd6644f75
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Feb 15 16:17:01 2014 +0000

description:
Remove the last argument of elf_check_header(). It is easier - and faster - to
check the e_type field in the calling function. Other BSD's already do this.

ok christos@

diffstat:

 sys/kern/exec_elf.c |  31 +++++++++++++++----------------
 sys/sys/exec_elf.h  |   6 +++---
 2 files changed, 18 insertions(+), 19 deletions(-)

diffs (105 lines):

diff -r d72b43a54ec0 -r 199cd6644f75 sys/kern/exec_elf.c
--- a/sys/kern/exec_elf.c       Sat Feb 15 13:34:28 2014 +0000
+++ b/sys/kern/exec_elf.c       Sat Feb 15 16:17:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.c,v 1.55 2014/02/14 07:30:07 maxv Exp $       */
+/*     $NetBSD: exec_elf.c,v 1.56 2014/02/15 16:17:01 maxv Exp $       */
 
 /*-
  * Copyright (c) 1994, 2000, 2005 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.55 2014/02/14 07:30:07 maxv Exp $");
+__KERNEL_RCSID(1, "$NetBSD: exec_elf.c,v 1.56 2014/02/15 16:17:01 maxv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_pax.h"
@@ -283,7 +283,7 @@
  * Check header for validity; return 0 if ok, ENOEXEC if error
  */
 int
-elf_check_header(Elf_Ehdr *eh, int type)
+elf_check_header(Elf_Ehdr *eh)
 {
 
        if (memcmp(eh->e_ident, ELFMAG, SELFMAG) != 0 ||
@@ -301,9 +301,6 @@
        if (ELF_EHDR_FLAGS_OK(eh) == 0)
                return ENOEXEC;
 
-       if (eh->e_type != type)
-               return ENOEXEC;
-
        if (eh->e_shnum > MAXSHNUM || eh->e_phnum > MAXPHNUM)
                return ENOEXEC;
 
@@ -491,10 +488,9 @@
        if ((error = exec_read_from(l, vp, 0, &eh, sizeof(eh))) != 0)
                goto bad;
 
-       if ((error = elf_check_header(&eh, ET_DYN)) != 0)
+       if ((error = elf_check_header(&eh)) != 0)
                goto bad;
-
-       if (eh.e_phnum == 0) {
+       if (eh.e_type != ET_DYN || eh.e_phnum == 0) {
                error = ENOEXEC;
                goto bad;
        }
@@ -667,17 +663,20 @@
        char *interp = NULL;
        u_long phsize;
        struct elf_args *ap = NULL;
-       bool is_dyn;
+       bool is_dyn = false;
 
        if (epp->ep_hdrvalid < sizeof(Elf_Ehdr))
                return ENOEXEC;
+       if ((error = elf_check_header(eh)) != 0)
+               return error;
 
-       is_dyn = elf_check_header(eh, ET_DYN) == 0;
-       /*
-        * XXX allow for executing shared objects. It seems silly
-        * but other ELF-based systems allow it as well.
-        */
-       if (!is_dyn && elf_check_header(eh, ET_EXEC) != 0)
+       if (eh->e_type == ET_DYN)
+               /*
+                * XXX allow for executing shared objects. It seems silly
+                * but other ELF-based systems allow it as well.
+                */
+               is_dyn = true;
+       else if (eh->e_type != ET_EXEC)
                return ENOEXEC;
 
        if (eh->e_phnum == 0)
diff -r d72b43a54ec0 -r 199cd6644f75 sys/sys/exec_elf.h
--- a/sys/sys/exec_elf.h        Sat Feb 15 13:34:28 2014 +0000
+++ b/sys/sys/exec_elf.h        Sat Feb 15 16:17:01 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: exec_elf.h,v 1.138 2014/02/11 09:04:28 skrll Exp $     */
+/*     $NetBSD: exec_elf.h,v 1.139 2014/02/15 16:17:01 maxv Exp $      */
 
 /*-
  * Copyright (c) 1994 The NetBSD Foundation, Inc.
@@ -1261,7 +1261,7 @@
 void   coredump_savenote_elf32(struct note_state *, unsigned int,
            const char *, void *, size_t);
 
-int    elf32_check_header(Elf32_Ehdr *, int);
+int    elf32_check_header(Elf32_Ehdr *);
 #endif
 
 #ifdef EXEC_ELF64
@@ -1273,7 +1273,7 @@
 void   coredump_savenote_elf64(struct note_state *, unsigned int,
            const char *, void *, size_t);
 
-int    elf64_check_header(Elf64_Ehdr *, int);
+int    elf64_check_header(Elf64_Ehdr *);
 #endif
 
 #endif /* _KERNEL */



Home | Main Index | Thread Index | Old Index