| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: exec_script.c,v 1.68 2014/02/17 19:29:46 maxv Exp $ */ | | 1 | /* $NetBSD: exec_script.c,v 1.69 2014/02/21 08:11:59 maxv Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou | | 4 | * Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 22 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 23 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 24 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 26 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 30 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.68 2014/02/17 19:29:46 maxv Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: exec_script.c,v 1.69 2014/02/21 08:11:59 maxv Exp $"); |
35 | | | 35 | |
36 | #if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS) | | 36 | #if defined(SETUIDSCRIPTS) && !defined(FDSCRIPTS) |
37 | #define FDSCRIPTS /* Need this for safe set-id scripts. */ | | 37 | #define FDSCRIPTS /* Need this for safe set-id scripts. */ |
38 | #endif | | 38 | #endif |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
42 | #include <sys/proc.h> | | 42 | #include <sys/proc.h> |
43 | #include <sys/kmem.h> | | 43 | #include <sys/kmem.h> |
44 | #include <sys/vnode.h> | | 44 | #include <sys/vnode.h> |
45 | #include <sys/namei.h> | | 45 | #include <sys/namei.h> |
46 | #include <sys/file.h> | | 46 | #include <sys/file.h> |
47 | #ifdef SETUIDSCRIPTS | | 47 | #ifdef SETUIDSCRIPTS |
| @@ -145,33 +145,26 @@ exec_script_makecmds(struct lwp *l, stru | | | @@ -145,33 +145,26 @@ exec_script_makecmds(struct lwp *l, stru |
145 | * for both spaces and tabs later on.) | | 145 | * for both spaces and tabs later on.) |
146 | */ | | 146 | */ |
147 | hdrlinelen = min(epp->ep_hdrvalid, SCRIPT_HDR_SIZE); | | 147 | hdrlinelen = min(epp->ep_hdrvalid, SCRIPT_HDR_SIZE); |
148 | for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; cp < hdrstr + hdrlinelen; | | 148 | for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; cp < hdrstr + hdrlinelen; |
149 | cp++) { | | 149 | cp++) { |
150 | if (*cp == '\n') { | | 150 | if (*cp == '\n') { |
151 | *cp = '\0'; | | 151 | *cp = '\0'; |
152 | break; | | 152 | break; |
153 | } | | 153 | } |
154 | } | | 154 | } |
155 | if (cp >= hdrstr + hdrlinelen) | | 155 | if (cp >= hdrstr + hdrlinelen) |
156 | return ENOEXEC; | | 156 | return ENOEXEC; |
157 | | | 157 | |
158 | /* | | | |
159 | * If the script has an ELF header, don't exec it. | | | |
160 | */ | | | |
161 | if (epp->ep_hdrvalid >= sizeof(ELFMAG)-1 && | | | |
162 | memcmp(hdrstr, ELFMAG, sizeof(ELFMAG)-1) == 0) | | | |
163 | return ENOEXEC; | | | |
164 | | | | |
165 | shellname = NULL; | | 158 | shellname = NULL; |
166 | shellarg = NULL; | | 159 | shellarg = NULL; |
167 | shellarglen = 0; | | 160 | shellarglen = 0; |
168 | | | 161 | |
169 | /* strip spaces before the shell name */ | | 162 | /* strip spaces before the shell name */ |
170 | for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; *cp == ' ' || *cp == '\t'; | | 163 | for (cp = hdrstr + EXEC_SCRIPT_MAGICLEN; *cp == ' ' || *cp == '\t'; |
171 | cp++) | | 164 | cp++) |
172 | ; | | 165 | ; |
173 | | | 166 | |
174 | /* collect the shell name; remember it's length for later */ | | 167 | /* collect the shell name; remember it's length for later */ |
175 | shellname = cp; | | 168 | shellname = cp; |
176 | shellnamelen = 0; | | 169 | shellnamelen = 0; |
177 | if (*cp == '\0') | | 170 | if (*cp == '\0') |