summaryrefslogtreecommitdiff
path: root/sys/kern/exec_script.c
diff options
context:
space:
mode:
authormatt <matt@NetBSD.org>2004-11-04 23:55:28 +0000
committermatt <matt@NetBSD.org>2004-11-04 23:55:28 +0000
commit2f15be42ae2bfa486941b4a6ad733dac876b41af (patch)
tree0e3450e45c39ea4b89ffae093c67a9a926d1b1ba /sys/kern/exec_script.c
parentd26e77c79fb18fd082f385529d3c1c9b1f0b58fb (diff)
Check to see if the script has an ELF header, and if so, return ENOEXEC.
Diffstat (limited to 'sys/kern/exec_script.c')
-rw-r--r--sys/kern/exec_script.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/sys/kern/exec_script.c b/sys/kern/exec_script.c
index 3974872ddef..d076ae0a734 100644
--- a/sys/kern/exec_script.c
+++ b/sys/kern/exec_script.c
@@ -1,4 +1,4 @@
-/* $NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp $ */
+/* $NetBSD: exec_script.c,v 1.38 2004/11/04 23:55:28 matt Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp $");
+__KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.38 2004/11/04 23:55:28 matt Exp $");
#if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS)
#define FDSCRIPTS /* Need this for safe set-id scripts. */
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.37 2004/04/21 18:40:38 itojun Exp
#include <sys/resourcevar.h>
#include <sys/exec_script.h>
+#include <sys/exec_elf.h>
/*
* exec_script_makecmds(): Check if it's an executable shell script.
@@ -107,6 +108,13 @@ exec_script_makecmds(struct proc *p, struct exec_package *epp)
if (cp >= hdrstr + hdrlinelen)
return ENOEXEC;
+ /*
+ * If the script has an ELF header, don't exec it.
+ */
+ if (epp->ep_hdrvalid >= sizeof(ELFMAG)-1 &&
+ memcmp(hdrstr, ELFMAG, sizeof(ELFMAG)-1) == 0)
+ return ENOEXEC;
+
shellname = NULL;
shellarg = NULL;
shellarglen = 0;