Module Name:    src
Committed By:   maxv
Date:           Sat Feb 15 16:17:01 UTC 2014

Modified Files:
        src/sys/kern: exec_elf.c
        src/sys/sys: exec_elf.h

Log Message:
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@


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/kern/exec_elf.c
cvs rdiff -u -r1.138 -r1.139 src/sys/sys/exec_elf.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/exec_elf.c
diff -u src/sys/kern/exec_elf.c:1.55 src/sys/kern/exec_elf.c:1.56
--- src/sys/kern/exec_elf.c:1.55	Fri Feb 14 07:30:07 2014
+++ src/sys/kern/exec_elf.c	Sat Feb 15 16:17:01 2014
@@ -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 @@ elf_copyargs(struct lwp *l, struct exec_
  * 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 @@ elf_check_header(Elf_Ehdr *eh, int type)
 	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 @@ elf_load_file(struct lwp *l, struct exec
 	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 @@ exec_elf_makecmds(struct lwp *l, struct 
 	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)

Index: src/sys/sys/exec_elf.h
diff -u src/sys/sys/exec_elf.h:1.138 src/sys/sys/exec_elf.h:1.139
--- src/sys/sys/exec_elf.h:1.138	Tue Feb 11 09:04:28 2014
+++ src/sys/sys/exec_elf.h	Sat Feb 15 16:17:01 2014
@@ -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 @@ int	coredump_elf32(struct lwp *, struct 
 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 @@ int	coredump_elf64(struct lwp *, struct 
 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 */

Reply via email to