]>
Commit | Line | Data |
---|---|---|
c299c52b | 1 | diff -urpN busybox-1.12.1/coreutils/env.c busybox-1.12.1-standalone/coreutils/env.c |
2 | --- busybox-1.12.1/coreutils/env.c 2008-09-28 20:04:18.000000000 +0200 | |
3 | +++ busybox-1.12.1-standalone/coreutils/env.c 2008-10-20 10:21:54.000000000 +0200 | |
4 | @@ -29,6 +29,8 @@ | |
5 | * - use xfunc_error_retval | |
6 | */ | |
7 | ||
8 | +/* This is a NOEXEC applet. Be very careful! */ | |
9 | + | |
10 | #include "libbb.h" | |
11 | ||
12 | #if ENABLE_FEATURE_ENV_LONG_OPTIONS | |
13 | @@ -119,5 +121,3 @@ int env_main(int argc UNUSED_PARAM, char | |
14 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
15 | * SUCH DAMAGE. | |
16 | */ | |
17 | - | |
18 | - | |
19 | diff -urpN busybox-1.12.1/include/applets.h busybox-1.12.1-standalone/include/applets.h | |
20 | --- busybox-1.12.1/include/applets.h 2008-09-28 20:04:26.000000000 +0200 | |
21 | +++ busybox-1.12.1-standalone/include/applets.h 2008-10-20 10:21:54.000000000 +0200 | |
22 | @@ -136,7 +136,7 @@ USE_ECHO(APPLET_NOFORK(echo, echo, _BB_D | |
23 | USE_ED(APPLET(ed, _BB_DIR_BIN, _BB_SUID_NEVER)) | |
24 | USE_FEATURE_GREP_EGREP_ALIAS(APPLET_ODDNAME(egrep, grep, _BB_DIR_BIN, _BB_SUID_NEVER, egrep)) | |
25 | USE_EJECT(APPLET(eject, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | |
26 | -USE_ENV(APPLET(env, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | |
27 | +USE_ENV(APPLET_NOEXEC(env, env, _BB_DIR_USR_BIN, _BB_SUID_NEVER, env)) | |
28 | USE_ENVDIR(APPLET_ODDNAME(envdir, chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER, envdir)) | |
29 | USE_ENVUIDGID(APPLET_ODDNAME(envuidgid, chpst, _BB_DIR_USR_BIN, _BB_SUID_NEVER, envuidgid)) | |
30 | USE_ETHER_WAKE(APPLET_ODDNAME(ether-wake, ether_wake, _BB_DIR_USR_BIN, _BB_SUID_NEVER, ether_wake)) | |
31 | @@ -171,7 +171,7 @@ USE_GREP(APPLET(grep, _BB_DIR_BIN, _BB_S | |
32 | USE_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_NEVER)) | |
33 | USE_GZIP(APPLET(gzip, _BB_DIR_BIN, _BB_SUID_NEVER)) | |
34 | USE_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_NEVER)) | |
35 | -USE_HD(APPLET_ODDNAME(hd, hexdump, _BB_DIR_USR_BIN, _BB_SUID_NEVER, hd)) | |
36 | +USE_HD(APPLET_NOEXEC(hd, hexdump, _BB_DIR_USR_BIN, _BB_SUID_NEVER, hd)) | |
37 | USE_HDPARM(APPLET(hdparm, _BB_DIR_SBIN, _BB_SUID_NEVER)) | |
38 | USE_HEAD(APPLET(head, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | |
39 | USE_HEXDUMP(APPLET_NOEXEC(hexdump, hexdump, _BB_DIR_USR_BIN, _BB_SUID_NEVER, hexdump)) | |
40 | diff -urpN busybox-1.12.1/libbb/getopt32.c busybox-1.12.1-standalone/libbb/getopt32.c | |
41 | --- busybox-1.12.1/libbb/getopt32.c 2008-09-28 20:04:20.000000000 +0200 | |
42 | +++ busybox-1.12.1-standalone/libbb/getopt32.c 2008-10-20 10:21:34.000000000 +0200 | |
43 | @@ -515,28 +515,6 @@ getopt32(char **argv, const char *applet | |
44 | } | |
45 | } | |
46 | ||
47 | - /* In case getopt32 was already called: | |
48 | - * reset the libc getopt() function, which keeps internal state. | |
49 | - * | |
50 | - * BSD-derived getopt() functions require that optind be set to 1 in | |
51 | - * order to reset getopt() state. This used to be generally accepted | |
52 | - * way of resetting getopt(). However, glibc's getopt() | |
53 | - * has additional getopt() state beyond optind, and requires that | |
54 | - * optind be set to zero to reset its state. So the unfortunate state of | |
55 | - * affairs is that BSD-derived versions of getopt() misbehave if | |
56 | - * optind is set to 0 in order to reset getopt(), and glibc's getopt() | |
57 | - * will core dump if optind is set 1 in order to reset getopt(). | |
58 | - * | |
59 | - * More modern versions of BSD require that optreset be set to 1 in | |
60 | - * order to reset getopt(). Sigh. Standards, anyone? | |
61 | - */ | |
62 | -#ifdef __GLIBC__ | |
63 | - optind = 0; | |
64 | -#else /* BSD style */ | |
65 | - optind = 1; | |
66 | - /* optreset = 1; */ | |
67 | -#endif | |
68 | - /* optarg = NULL; opterr = 0; optopt = 0; - do we need this?? */ | |
69 | pargv = NULL; | |
70 | ||
71 | /* Note: just "getopt() <= 0" will not work well for | |
72 | diff -urpN busybox-1.12.1/libbb/vfork_daemon_rexec.c busybox-1.12.1-standalone/libbb/vfork_daemon_rexec.c | |
73 | --- busybox-1.12.1/libbb/vfork_daemon_rexec.c 2008-09-28 20:04:20.000000000 +0200 | |
74 | +++ busybox-1.12.1-standalone/libbb/vfork_daemon_rexec.c 2008-10-20 10:21:34.000000000 +0200 | |
75 | @@ -125,6 +125,7 @@ int FAST_FUNC run_nofork_applet_prime(st | |
76 | int rc, argc; | |
77 | ||
78 | applet_name = APPLET_NAME(applet_no); | |
79 | + | |
80 | xfunc_error_retval = EXIT_FAILURE; | |
81 | ||
82 | /* Special flag for xfunc_die(). If xfunc will "die" | |
83 | @@ -132,7 +133,30 @@ int FAST_FUNC run_nofork_applet_prime(st | |
84 | * die_sleep and longjmp here instead. */ | |
85 | die_sleep = -1; | |
86 | ||
87 | - /* option_mask32 = 0; - not needed */ | |
88 | + /* In case getopt() or getopt32() was already called: | |
89 | + * reset the libc getopt() function, which keeps internal state. | |
90 | + * | |
91 | + * BSD-derived getopt() functions require that optind be set to 1 in | |
92 | + * order to reset getopt() state. This used to be generally accepted | |
93 | + * way of resetting getopt(). However, glibc's getopt() | |
94 | + * has additional getopt() state beyond optind, and requires that | |
95 | + * optind be set to zero to reset its state. So the unfortunate state of | |
96 | + * affairs is that BSD-derived versions of getopt() misbehave if | |
97 | + * optind is set to 0 in order to reset getopt(), and glibc's getopt() | |
98 | + * will core dump if optind is set 1 in order to reset getopt(). | |
99 | + * | |
100 | + * More modern versions of BSD require that optreset be set to 1 in | |
101 | + * order to reset getopt(). Sigh. Standards, anyone? | |
102 | + */ | |
103 | +#ifdef __GLIBC__ | |
104 | + optind = 0; | |
105 | +#else /* BSD style */ | |
106 | + optind = 1; | |
107 | + /* optreset = 1; */ | |
108 | +#endif | |
109 | + /* optarg = NULL; opterr = 1; optopt = 63; - do we need this too? */ | |
110 | + /* (values above are what they initialized to in glibc and uclibc) */ | |
111 | + /* option_mask32 = 0; - not needed, no applet depends on it being 0 */ | |
112 | ||
113 | argc = 1; | |
114 | while (argv[argc]) | |
115 | @@ -161,8 +185,16 @@ int FAST_FUNC run_nofork_applet_prime(st | |
116 | rc = 0; | |
117 | } | |
118 | ||
119 | - /* Restoring globals */ | |
120 | + /* Restoring some globals */ | |
121 | restore_nofork_data(old); | |
122 | + | |
123 | + /* Other globals can be simply reset to defaults */ | |
124 | +#ifdef __GLIBC__ | |
125 | + optind = 0; | |
126 | +#else /* BSD style */ | |
127 | + optind = 1; | |
128 | +#endif | |
129 | + | |
130 | return rc & 0xff; /* don't confuse people with "exitcodes" >255 */ | |
131 | } | |
132 | ||
133 | diff -urpN busybox-1.12.1/shell/ash.c busybox-1.12.1-standalone/shell/ash.c | |
134 | --- busybox-1.12.1/shell/ash.c 2008-09-28 20:04:18.000000000 +0200 | |
135 | +++ busybox-1.12.1-standalone/shell/ash.c 2008-10-20 10:21:54.000000000 +0200 | |
136 | @@ -6964,8 +6964,11 @@ tryexec(USE_FEATURE_SH_STANDALONE(int ap | |
137 | ||
138 | #if ENABLE_FEATURE_SH_STANDALONE | |
139 | if (applet_no >= 0) { | |
140 | - if (APPLET_IS_NOEXEC(applet_no)) | |
141 | + if (APPLET_IS_NOEXEC(applet_no)) { | |
142 | + while (*envp) | |
143 | + putenv(*envp++); | |
144 | run_applet_no_and_exit(applet_no, argv); | |
145 | + } | |
146 | /* re-exec ourselves with the new arguments */ | |
147 | execve(bb_busybox_exec_path, argv, envp); | |
148 | /* If they called chroot or otherwise made the binary no longer | |
149 | @@ -12014,7 +12017,7 @@ exportcmd(int argc UNUSED_PARAM, char ** | |
150 | char *name; | |
151 | const char *p; | |
152 | char **aptr; | |
153 | - int flag = argv[0][0] == 'r'? VREADONLY : VEXPORT; | |
154 | + int flag = argv[0][0] == 'r' ? VREADONLY : VEXPORT; | |
155 | ||
156 | if (nextopt("p") != 'p') { | |
157 | aptr = argptr; | |
158 | diff -urpN busybox-1.12.1/util-linux/getopt.c busybox-1.12.1-standalone/util-linux/getopt.c | |
159 | --- busybox-1.12.1/util-linux/getopt.c 2008-09-28 20:04:30.000000000 +0200 | |
160 | +++ busybox-1.12.1-standalone/util-linux/getopt.c 2008-10-20 10:21:34.000000000 +0200 | |
161 | @@ -142,7 +142,8 @@ static const char *normalize(const char | |
162 | * Other settings are found in global variables. | |
163 | */ | |
164 | #if !ENABLE_GETOPT_LONG | |
165 | -#define generate_output(argv,argc,optstr,longopts) generate_output(argv,argc,optstr) | |
166 | +#define generate_output(argv,argc,optstr,longopts) \ | |
167 | + generate_output(argv,argc,optstr) | |
168 | #endif | |
169 | static int generate_output(char **argv, int argc, const char *optstr, const struct option *longopts) | |
170 | { | |
171 | @@ -156,14 +157,6 @@ static int generate_output(char **argv, | |
172 | if (quiet_errors) /* No error reporting from getopt(3) */ | |
173 | opterr = 0; | |
174 | ||
175 | - /* Reset getopt(3) (see libbb/getopt32.c for long rant) */ | |
176 | -#ifdef __GLIBC__ | |
177 | - optind = 0; | |
178 | -#else /* BSD style */ | |
179 | - optind = 1; | |
180 | - /* optreset = 1; */ | |
181 | -#endif | |
182 | - | |
183 | while (1) { | |
184 | opt = | |
185 | #if ENABLE_GETOPT_LONG |