diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-03 19:00:01 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-03 19:03:32 +0200 |
commit | 39194f030918b87eeb3e11e94cfa05f575fb47b4 (patch) | |
tree | 97ea35e2c5984c5c6757ff9a540630ada4b234d5 | |
parent | 663ae52676eae3b0fdc6bb968ff6497279a034a4 (diff) | |
download | busybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.tar.gz busybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.tar.bz2 busybox-w32-39194f030918b87eeb3e11e94cfa05f575fb47b4.zip |
new NOFORKs: pwdx,kill[all5],ttysize,realpath,readlink NOEXECs: date,resize
function old new delta
run_nofork_applet 258 280 +22
readlink_main 112 123 +11
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 33/0) Total: 33 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | NOFORK_NOEXEC.lst | 140 | ||||
-rw-r--r-- | console-tools/resize.c | 2 | ||||
-rw-r--r-- | coreutils/date.c | 21 | ||||
-rw-r--r-- | coreutils/readlink.c | 7 | ||||
-rw-r--r-- | coreutils/realpath.c | 3 | ||||
-rw-r--r-- | docs/nofork_noexec.txt | 2 | ||||
-rw-r--r-- | libbb/bb_pwd.c | 3 | ||||
-rw-r--r-- | libbb/vfork_daemon_rexec.c | 6 | ||||
-rw-r--r-- | miscutils/ttysize.c | 2 | ||||
-rw-r--r-- | procps/kill.c | 10 | ||||
-rw-r--r-- | procps/pwdx.c | 3 |
11 files changed, 106 insertions, 93 deletions
diff --git a/NOFORK_NOEXEC.lst b/NOFORK_NOEXEC.lst index 02eba46e8..7073611a4 100644 --- a/NOFORK_NOEXEC.lst +++ b/NOFORK_NOEXEC.lst | |||
@@ -1,11 +1,10 @@ | |||
1 | Why an applet can't be NOFORK or NOEXEC? | 1 | Why an applet can't be NOFORK or NOEXEC? |
2 | 2 | ||
3 | Why can't be NOFORK: | 3 | Why can't be NOFORK: |
4 | daemon: runs indefinitely | ||
5 | interactive: may wait for user input, ^C has to work | 4 | interactive: may wait for user input, ^C has to work |
6 | spawner: "tool PROG ARGS" which changes program's environment - must fork | 5 | spawner: "tool PROG ARGS" which changes program's environment - must fork |
7 | changes state: e.g. environment, signal handlers | 6 | changes state: e.g. environment, signal handlers |
8 | runner: sometimes may run for long time, and/or works with network: | 7 | runner: sometimes may run for long(ish) time, and/or works with network: |
9 | ^C has to work (cat BIGFILE, chmod -R, ftpget, nc) | 8 | ^C has to work (cat BIGFILE, chmod -R, ftpget, nc) |
10 | 9 | ||
11 | "runners" can become eligible after hush is taught ^C to interrupt NOFORKs! | 10 | "runners" can become eligible after hush is taught ^C to interrupt NOFORKs! |
@@ -15,9 +14,12 @@ suid: runs under different uid - must fork+exec | |||
15 | 14 | ||
16 | Why shouldn't be NOFORK/NOEXEC: | 15 | Why shouldn't be NOFORK/NOEXEC: |
17 | complex: no immediately obvious reason why NOFORK wouldn't work, | 16 | complex: no immediately obvious reason why NOFORK wouldn't work, |
18 | but does some non-obvoius operations (example: fuser, lsof, losetup). | 17 | but does some non-obvoius operations (example: fuser, lsof, losetup); |
19 | for NOFORK, nested xmallocs (typical in complex code) is a problem. | 18 | nested xmallocs (typical in complex code) is a problem for NOFORK |
20 | rare: not used often enough to bother optimizing (example: poweroff) | 19 | rare: not used often enough to bother optimizing (example: poweroff) |
20 | longterm: often runs for a long time (many seconds), execing would make | ||
21 | memory footprint smaller | ||
22 | daemon: runs indefinitely | ||
21 | 23 | ||
22 | [ - NOFORK | 24 | [ - NOFORK |
23 | [[ - NOFORK | 25 | [[ - NOFORK |
@@ -31,7 +33,7 @@ arch - NOFORK | |||
31 | arp | 33 | arp |
32 | arping - runner | 34 | arping - runner |
33 | ash - interactive | 35 | ash - interactive |
34 | awk - noexec, runner | 36 | awk - noexec. runner |
35 | base64 - runner | 37 | base64 - runner |
36 | basename - NOFORK | 38 | basename - NOFORK |
37 | beep | 39 | beep |
@@ -44,63 +46,63 @@ bunzip2 - runner | |||
44 | busybox | 46 | busybox |
45 | bzcat - runner | 47 | bzcat - runner |
46 | bzip2 - runner | 48 | bzip2 - runner |
47 | cal | 49 | cal - runner: cal -n9999 |
48 | cat - runner | 50 | cat - runner |
49 | chat | 51 | chat |
50 | chattr - runner | 52 | chattr - runner |
51 | chgrp - noexec, runner | 53 | chgrp - noexec. runner |
52 | chmod - noexec, runner | 54 | chmod - noexec. runner |
53 | chown - noexec, runner | 55 | chown - noexec. runner |
54 | chpasswd - runner (list of "user:password"s from stdin) | 56 | chpasswd - runner (list of "user:password"s from stdin) |
55 | chpst - spawner | 57 | chpst - spawner |
56 | chroot - spawner | 58 | chroot - spawner |
57 | chrt - spawner | 59 | chrt - spawner |
58 | chvt | 60 | chvt |
59 | cksum - noexec, runner | 61 | cksum - noexec. runner |
60 | clear - NOFORK | 62 | clear - NOFORK |
61 | cmp - runner | 63 | cmp - runner |
62 | comm - runner | 64 | comm - runner |
63 | conspy - interactive | 65 | conspy - interactive |
64 | cp - noexec, runner | 66 | cp - noexec. runner |
65 | cpio - runner | 67 | cpio - runner |
66 | crond - daemon | 68 | crond - daemon |
67 | crontab | 69 | crontab |
68 | cryptpw | 70 | cryptpw |
69 | cttyhack - spawner | 71 | cttyhack - spawner |
70 | cut - noexec, runner | 72 | cut - noexec. runner |
71 | date | 73 | date - noexec. nofork candidate(needs to stop messing up env, free xasprintf result, not use xfuncs after xasprintf) |
72 | dc - runner (eats stdin if no params) | 74 | dc - runner (eats stdin if no params) |
73 | dd - noexec, runner | 75 | dd - noexec. runner |
74 | deallocvt | 76 | deallocvt |
75 | delgroup | 77 | delgroup |
76 | deluser | 78 | deluser |
77 | depmod | 79 | depmod |
78 | devmem | 80 | devmem - runner, complex (access to device memory may hang) |
79 | df | 81 | df - complex (nested allocs) |
80 | dhcprelay - daemon | 82 | dhcprelay - daemon |
81 | diff - runner | 83 | diff - runner |
82 | dirname - NOFORK | 84 | dirname - NOFORK |
83 | dmesg | 85 | dmesg - runner |
84 | dnsd - daemon | 86 | dnsd - daemon |
85 | dnsdomainname | 87 | dnsdomainname - DNS resolution may trigger, need ^C |
86 | dos2unix - noexec, runner | 88 | dos2unix - noexec. runner |
87 | dpkg - runner | 89 | dpkg - runner |
88 | du | 90 | du - runner |
89 | dumpkmap | 91 | dumpkmap |
90 | dumpleases | 92 | dumpleases |
91 | echo - NOFORK | 93 | echo - NOFORK |
92 | ed - interactive | 94 | ed - interactive |
93 | egrep - runner | 95 | egrep - runner |
94 | eject | 96 | eject |
95 | env - noexec, changes state (env) | 97 | env - noexec. changes state (env) |
96 | envdir - spawner | 98 | envdir - spawner |
97 | envuidgid - spawner | 99 | envuidgid - spawner |
98 | expand - runner | 100 | expand - runner |
99 | expr | 101 | expr - complex (nested allocs) |
100 | factor - runner (eats stdin if no params) | 102 | factor - runner (eats stdin if no params) |
101 | fakeidentd - daemon | 103 | fakeidentd - daemon |
102 | false - NOFORK | 104 | false - NOFORK |
103 | fatattr | 105 | fatattr - complex (xopen+xioctl can leak fd) |
104 | fbset | 106 | fbset |
105 | fbsplash - runner, interactive | 107 | fbsplash - runner, interactive |
106 | fdflush | 108 | fdflush |
@@ -108,15 +110,15 @@ fdformat - runner | |||
108 | fdisk - interactive | 110 | fdisk - interactive |
109 | fgconsole | 111 | fgconsole |
110 | fgrep - runner | 112 | fgrep - runner |
111 | find - noexec, runner | 113 | find - noexec. runner |
112 | findfs - suid | 114 | findfs - suid |
113 | flash_eraseall | 115 | flash_eraseall |
114 | flash_lock | 116 | flash_lock |
115 | flash_unlock | 117 | flash_unlock |
116 | flashcp | 118 | flashcp |
117 | flock | 119 | flock |
118 | fold - noexec, runner | 120 | fold - noexec. runner |
119 | free | 121 | free - nofork candidate(struct globals, needs to close /proc/meminfo fd) |
120 | freeramdisk | 122 | freeramdisk |
121 | fsck - interactive | 123 | fsck - interactive |
122 | fsck.minix | 124 | fsck.minix |
@@ -134,12 +136,12 @@ groups - noexec | |||
134 | gunzip - runner | 136 | gunzip - runner |
135 | gzip - runner | 137 | gzip - runner |
136 | halt - rare | 138 | halt - rare |
137 | hd - noexec, runner | 139 | hd - noexec. runner |
138 | hdparm - complex, rare | 140 | hdparm - complex, rare |
139 | head - noexec, runner | 141 | head - noexec. runner |
140 | hexdump - noexec, runner | 142 | hexdump - noexec. runner |
141 | hostid - NOFORK | 143 | hostid - NOFORK |
142 | hostname | 144 | hostname - DNS resolution may trigger, need ^C |
143 | httpd - daemon | 145 | httpd - daemon |
144 | hush - interactive | 146 | hush - interactive |
145 | hwclock | 147 | hwclock |
@@ -169,11 +171,11 @@ iproute | |||
169 | iprule | 171 | iprule |
170 | iptunnel | 172 | iptunnel |
171 | kbd_mode | 173 | kbd_mode |
172 | kill | 174 | kill - NOFORK |
173 | killall | 175 | killall - NOFORK |
174 | killall5 | 176 | killall5 - NOFORK |
175 | klogd - daemon | 177 | klogd - daemon |
176 | last | 178 | last - runner (I've got 1300 lines of output when tried it) |
177 | less - interactive | 179 | less - interactive |
178 | link - NOFORK | 180 | link - NOFORK |
179 | linux32 - spawner | 181 | linux32 - spawner |
@@ -189,7 +191,7 @@ losetup - complex | |||
189 | lpd - daemon | 191 | lpd - daemon |
190 | lpq - runner | 192 | lpq - runner |
191 | lpr - runner | 193 | lpr - runner |
192 | ls - noexec, runner | 194 | ls - noexec. runner |
193 | lsattr | 195 | lsattr |
194 | lsmod | 196 | lsmod |
195 | lsof - complex | 197 | lsof - complex |
@@ -203,7 +205,7 @@ lzopcat - runner | |||
203 | makedevs | 205 | makedevs |
204 | makemime - runner | 206 | makemime - runner |
205 | man - spawner, interactive | 207 | man - spawner, interactive |
206 | md5sum - noexec, runner | 208 | md5sum - noexec. runner |
207 | mdev - daemon | 209 | mdev - daemon |
208 | mesg | 210 | mesg |
209 | microcom - interactive, complex | 211 | microcom - interactive, complex |
@@ -225,11 +227,11 @@ mount - suid | |||
225 | mountpoint | 227 | mountpoint |
226 | mpstat | 228 | mpstat |
227 | mt | 229 | mt |
228 | mv | 230 | mv - runner (can be noexec?) |
229 | nameif | 231 | nameif |
230 | nbd-client | 232 | nbd-client |
231 | nc - runner | 233 | nc - runner |
232 | netstat | 234 | netstat - runner with -c |
233 | nice - spawner | 235 | nice - spawner |
234 | nl - runner | 236 | nl - runner |
235 | nmeter - runner | 237 | nmeter - runner |
@@ -240,40 +242,40 @@ od - runner | |||
240 | openvt - spawner | 242 | openvt - spawner |
241 | partprobe | 243 | partprobe |
242 | passwd - suid | 244 | passwd - suid |
243 | paste - noexec, runner | 245 | paste - noexec. runner |
244 | patch | 246 | patch |
245 | pgrep | 247 | pgrep - nofork candidate(xregcomp, procps_scan - are they ok?) |
246 | pidof | 248 | pidof - nofork candidate(uses find_pid_by_name, is that ok?) |
247 | ping - suid, runner | 249 | ping - suid, runner |
248 | ping6 - suid, runner | 250 | ping6 - suid, runner |
249 | pipe_progress | 251 | pipe_progress |
250 | pivot_root | 252 | pivot_root |
251 | pkill | 253 | pkill - nofork candidate(xregcomp, procps_scan - are they ok?) |
252 | pmap | 254 | pmap |
253 | popmaildir - runner | 255 | popmaildir - runner |
254 | poweroff - rare | 256 | poweroff - rare |
255 | powertop - interactive | 257 | powertop - interactive, longterm |
256 | printenv - NOFORK | 258 | printenv - NOFORK |
257 | printf - NOFORK | 259 | printf - NOFORK |
258 | ps | 260 | ps |
259 | pscan | 261 | pscan |
260 | pstree | 262 | pstree |
261 | pwd - NOFORK | 263 | pwd - NOFORK |
262 | pwdx | 264 | pwdx - NOFORK |
263 | raidautorun | 265 | raidautorun |
264 | rdate | 266 | rdate |
265 | rdev | 267 | rdev |
266 | readlink | 268 | readlink - NOFORK |
267 | readprofile | 269 | readprofile |
268 | realpath | 270 | realpath - NOFORK |
269 | reboot - rare | 271 | reboot - rare |
270 | reformime - runner | 272 | reformime - runner |
271 | remove-shell | 273 | remove-shell |
272 | renice | 274 | renice - nofork candidate(uses getpwnam, is that ok?) |
273 | reset - spawner (execs "stty") | 275 | reset - spawner (execs "stty") |
274 | resize | 276 | resize - noexec. changes state (signal handlers) |
275 | rev - runner | 277 | rev - runner |
276 | rm - noexec, rm -i interactive | 278 | rm - noexec. rm -i interactive |
277 | rmdir - NOFORK | 279 | rmdir - NOFORK |
278 | rmmod | 280 | rmmod |
279 | route | 281 | route |
@@ -289,7 +291,7 @@ script | |||
289 | scriptreplay | 291 | scriptreplay |
290 | sed - runner | 292 | sed - runner |
291 | sendmail - runner | 293 | sendmail - runner |
292 | seq - noexec, runner | 294 | seq - noexec. runner |
293 | setarch - spawner | 295 | setarch - spawner |
294 | setconsole | 296 | setconsole |
295 | setfont | 297 | setfont |
@@ -300,22 +302,22 @@ setserial | |||
300 | setsid - spawner | 302 | setsid - spawner |
301 | setuidgid | 303 | setuidgid |
302 | sh - interactive | 304 | sh - interactive |
303 | sha1sum - noexec, runner | 305 | sha1sum - noexec. runner |
304 | sha256sum - noexec, runner | 306 | sha256sum - noexec. runner |
305 | sha3sum - noexec, runner | 307 | sha3sum - noexec. runner |
306 | sha512sum - noexec, runner | 308 | sha512sum - noexec. runner |
307 | showkey - interactive | 309 | showkey - interactive |
308 | shred - runner | 310 | shred - runner |
309 | shuf - noexec, runner | 311 | shuf - noexec. runner |
310 | slattach | 312 | slattach |
311 | sleep - runner | 313 | sleep - runner |
312 | smemcap - runner | 314 | smemcap - runner |
313 | softlimit - spawner | 315 | softlimit - spawner |
314 | sort - noexec, runner | 316 | sort - noexec. runner |
315 | split - runner | 317 | split - runner |
316 | ssl_client - network | 318 | ssl_client - network |
317 | start-stop-daemon | 319 | start-stop-daemon |
318 | stat | 320 | stat - nofork candidate(needs fewer allocs) |
319 | strings - runner | 321 | strings - runner |
320 | stty | 322 | stty |
321 | su - suid, spawner | 323 | su - suid, spawner |
@@ -326,11 +328,11 @@ svc | |||
326 | svlogd - daemon | 328 | svlogd - daemon |
327 | swapoff - rare | 329 | swapoff - rare |
328 | swapon - rare | 330 | swapon - rare |
329 | switch_root - spawner, rare, change state | 331 | switch_root - spawner, rare, changes state |
330 | sync - NOFORK | 332 | sync - NOFORK |
331 | sysctl | 333 | sysctl |
332 | syslogd - daemon | 334 | syslogd - daemon |
333 | tac - noexec, runner | 335 | tac - noexec. runner |
334 | tail - runner | 336 | tail - runner |
335 | tar - runner | 337 | tar - runner |
336 | taskset - spawner | 338 | taskset - spawner |
@@ -341,9 +343,9 @@ telnetd - daemon | |||
341 | test - NOFORK | 343 | test - NOFORK |
342 | tftp - runner | 344 | tftp - runner |
343 | tftpd - daemon | 345 | tftpd - daemon |
344 | time - spawner, change state (signals) | 346 | time - spawner, changes state (signals) |
345 | timeout - spawner, change state (signals) | 347 | timeout - spawner, changes state (signals) |
346 | top - interactive | 348 | top - interactive, longterm |
347 | touch - NOFORK | 349 | touch - NOFORK |
348 | tr - runner | 350 | tr - runner |
349 | traceroute - suid, runner | 351 | traceroute - suid, runner |
@@ -351,7 +353,7 @@ traceroute6 - suid, runner | |||
351 | true - NOFORK | 353 | true - NOFORK |
352 | truncate - NOFORK | 354 | truncate - NOFORK |
353 | tty - NOFORK | 355 | tty - NOFORK |
354 | ttysize | 356 | ttysize - NOFORK |
355 | tunctl | 357 | tunctl |
356 | tune2fs | 358 | tune2fs |
357 | ubiattach | 359 | ubiattach |
@@ -370,14 +372,14 @@ uname - NOFORK | |||
370 | uncompress - runner | 372 | uncompress - runner |
371 | unexpand - runner | 373 | unexpand - runner |
372 | uniq - runner | 374 | uniq - runner |
373 | unix2dos - noexec, runner | 375 | unix2dos - noexec. runner |
374 | unlink - NOFORK | 376 | unlink - NOFORK |
375 | unlzma - runner | 377 | unlzma - runner |
376 | unlzop - runner | 378 | unlzop - runner |
377 | unxz - runner | 379 | unxz - runner |
378 | unzip - runner | 380 | unzip - runner |
379 | uptime | 381 | uptime - nofork candidate(is getutxent ok?) |
380 | users | 382 | users - nofork candidate(is getutxent ok?) |
381 | usleep - NOFORK | 383 | usleep - NOFORK |
382 | uudecode - runner | 384 | uudecode - runner |
383 | uuencode - runner | 385 | uuencode - runner |
@@ -395,10 +397,10 @@ which - NOFORK | |||
395 | who | 397 | who |
396 | whoami - NOFORK | 398 | whoami - NOFORK |
397 | whois | 399 | whois |
398 | xargs - noexec, spawner | 400 | xargs - noexec. spawner |
399 | xxd - noexec, runner | 401 | xxd - noexec. runner |
400 | xz - runner | 402 | xz - runner |
401 | xzcat - runner | 403 | xzcat - runner |
402 | yes - noexec, runner | 404 | yes - noexec. runner |
403 | zcat - runner | 405 | zcat - runner |
404 | zcip - daemon | 406 | zcip - daemon |
diff --git a/console-tools/resize.c b/console-tools/resize.c index 62928a01e..97866673a 100644 --- a/console-tools/resize.c +++ b/console-tools/resize.c | |||
@@ -23,7 +23,7 @@ | |||
23 | //config: E.g.: | 23 | //config: E.g.: |
24 | //config: COLUMNS=80;LINES=44;export COLUMNS LINES; | 24 | //config: COLUMNS=80;LINES=44;export COLUMNS LINES; |
25 | 25 | ||
26 | //applet:IF_RESIZE(APPLET(resize, BB_DIR_USR_BIN, BB_SUID_DROP)) | 26 | //applet:IF_RESIZE(APPLET_NOEXEC(resize, resize, BB_DIR_USR_BIN, BB_SUID_DROP, resize)) |
27 | 27 | ||
28 | //kbuild:lib-$(CONFIG_RESIZE) += resize.o | 28 | //kbuild:lib-$(CONFIG_RESIZE) += resize.o |
29 | 29 | ||
diff --git a/coreutils/date.c b/coreutils/date.c index 2c6e1d4df..89b281646 100644 --- a/coreutils/date.c +++ b/coreutils/date.c | |||
@@ -58,7 +58,7 @@ | |||
58 | //config: the same format. With it on, 'date DATE' additionally supports | 58 | //config: the same format. With it on, 'date DATE' additionally supports |
59 | //config: MMDDhhmm[[YY]YY][.ss] format. | 59 | //config: MMDDhhmm[[YY]YY][.ss] format. |
60 | 60 | ||
61 | //applet:IF_DATE(APPLET(date, BB_DIR_BIN, BB_SUID_DROP)) | 61 | //applet:IF_DATE(APPLET_NOEXEC(date, date, BB_DIR_BIN, BB_SUID_DROP, date)) |
62 | 62 | ||
63 | //kbuild:lib-$(CONFIG_DATE) += date.o | 63 | //kbuild:lib-$(CONFIG_DATE) += date.o |
64 | 64 | ||
@@ -152,12 +152,6 @@ enum { | |||
152 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ | 152 | OPT_HINT = (1 << 6) * ENABLE_FEATURE_DATE_ISOFMT, /* D */ |
153 | }; | 153 | }; |
154 | 154 | ||
155 | static void maybe_set_utc(int opt) | ||
156 | { | ||
157 | if (opt & OPT_UTC) | ||
158 | putenv((char*)"TZ=UTC0"); | ||
159 | } | ||
160 | |||
161 | #if ENABLE_LONG_OPTS | 155 | #if ENABLE_LONG_OPTS |
162 | static const char date_longopts[] ALIGN1 = | 156 | static const char date_longopts[] ALIGN1 = |
163 | "rfc-822\0" No_argument "R" | 157 | "rfc-822\0" No_argument "R" |
@@ -170,6 +164,19 @@ static const char date_longopts[] ALIGN1 = | |||
170 | ; | 164 | ; |
171 | #endif | 165 | #endif |
172 | 166 | ||
167 | /* We are a NOEXEC applet. | ||
168 | * Obstacles to NOFORK: | ||
169 | * - we change env | ||
170 | * - xasprintf result not freed | ||
171 | * - after xasprintf we use other xfuncs | ||
172 | */ | ||
173 | |||
174 | static void maybe_set_utc(int opt) | ||
175 | { | ||
176 | if (opt & OPT_UTC) | ||
177 | putenv((char*)"TZ=UTC0"); | ||
178 | } | ||
179 | |||
173 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 180 | int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
174 | int date_main(int argc UNUSED_PARAM, char **argv) | 181 | int date_main(int argc UNUSED_PARAM, char **argv) |
175 | { | 182 | { |
diff --git a/coreutils/readlink.c b/coreutils/readlink.c index 9690290e3..7f8d6b239 100644 --- a/coreutils/readlink.c +++ b/coreutils/readlink.c | |||
@@ -20,7 +20,7 @@ | |||
20 | //config: help | 20 | //config: help |
21 | //config: Enable the readlink option (-f). | 21 | //config: Enable the readlink option (-f). |
22 | 22 | ||
23 | //applet:IF_READLINK(APPLET(readlink, BB_DIR_USR_BIN, BB_SUID_DROP)) | 23 | //applet:IF_READLINK(APPLET_NOFORK(readlink, readlink, BB_DIR_USR_BIN, BB_SUID_DROP, readlink)) |
24 | 24 | ||
25 | //kbuild:lib-$(CONFIG_READLINK) += readlink.o | 25 | //kbuild:lib-$(CONFIG_READLINK) += readlink.o |
26 | 26 | ||
@@ -85,6 +85,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
85 | if (!(opt & 4)) /* not -v */ | 85 | if (!(opt & 4)) /* not -v */ |
86 | logmode = LOGMODE_NONE; | 86 | logmode = LOGMODE_NONE; |
87 | 87 | ||
88 | /* NOFORK: only one alloc is allowed; must free */ | ||
88 | if (opt & 1) { /* -f */ | 89 | if (opt & 1) { /* -f */ |
89 | buf = xmalloc_realpath(fname); | 90 | buf = xmalloc_realpath(fname); |
90 | } else { | 91 | } else { |
@@ -94,9 +95,7 @@ int readlink_main(int argc UNUSED_PARAM, char **argv) | |||
94 | if (!buf) | 95 | if (!buf) |
95 | return EXIT_FAILURE; | 96 | return EXIT_FAILURE; |
96 | printf((opt & 2) ? "%s" : "%s\n", buf); | 97 | printf((opt & 2) ? "%s" : "%s\n", buf); |
97 | 98 | free(buf); | |
98 | if (ENABLE_FEATURE_CLEAN_UP) | ||
99 | free(buf); | ||
100 | 99 | ||
101 | fflush_stdout_and_exit(EXIT_SUCCESS); | 100 | fflush_stdout_and_exit(EXIT_SUCCESS); |
102 | } | 101 | } |
diff --git a/coreutils/realpath.c b/coreutils/realpath.c index 6a61c3dc8..f9c630135 100644 --- a/coreutils/realpath.c +++ b/coreutils/realpath.c | |||
@@ -13,7 +13,7 @@ | |||
13 | //config: Return the canonicalized absolute pathname. | 13 | //config: Return the canonicalized absolute pathname. |
14 | //config: This isn't provided by GNU shellutils, but where else does it belong. | 14 | //config: This isn't provided by GNU shellutils, but where else does it belong. |
15 | 15 | ||
16 | //applet:IF_REALPATH(APPLET(realpath, BB_DIR_USR_BIN, BB_SUID_DROP)) | 16 | //applet:IF_REALPATH(APPLET_NOFORK(realpath, realpath, BB_DIR_USR_BIN, BB_SUID_DROP, realpath)) |
17 | 17 | ||
18 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o | 18 | //kbuild:lib-$(CONFIG_REALPATH) += realpath.o |
19 | 19 | ||
@@ -36,6 +36,7 @@ int realpath_main(int argc UNUSED_PARAM, char **argv) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | do { | 38 | do { |
39 | /* NOFORK: only one alloc is allowed; must free */ | ||
39 | char *resolved_path = xmalloc_realpath(*argv); | 40 | char *resolved_path = xmalloc_realpath(*argv); |
40 | if (resolved_path != NULL) { | 41 | if (resolved_path != NULL) { |
41 | puts(resolved_path); | 42 | puts(resolved_path); |
diff --git a/docs/nofork_noexec.txt b/docs/nofork_noexec.txt index 0ad4e6e60..cfb02145a 100644 --- a/docs/nofork_noexec.txt +++ b/docs/nofork_noexec.txt | |||
@@ -98,7 +98,7 @@ It itself calls run_nofork_applet(), if argv[0] turned out to be a name | |||
98 | of a NOFORK applet. | 98 | of a NOFORK applet. |
99 | 99 | ||
100 | run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, | 100 | run_nofork_applet() saves/inits/restores option parsing, xfunc_error_retval, |
101 | applet_name. Thus, for example, caller does not need to worry about | 101 | logmode, applet_name. Thus, for example, caller does not need to worry about |
102 | option_mask32 getting trashed. | 102 | option_mask32 getting trashed. |
103 | 103 | ||
104 | 104 | ||
diff --git a/libbb/bb_pwd.c b/libbb/bb_pwd.c index 4829b723a..dca0a150b 100644 --- a/libbb/bb_pwd.c +++ b/libbb/bb_pwd.c | |||
@@ -31,9 +31,9 @@ struct group* FAST_FUNC xgetgrnam(const char *name) | |||
31 | return gr; | 31 | return gr; |
32 | } | 32 | } |
33 | 33 | ||
34 | |||
35 | struct passwd* FAST_FUNC xgetpwuid(uid_t uid) | 34 | struct passwd* FAST_FUNC xgetpwuid(uid_t uid) |
36 | { | 35 | { |
36 | /* Note: used in nofork applets (whoami), be careful not to leak anything */ | ||
37 | struct passwd *pw = getpwuid(uid); | 37 | struct passwd *pw = getpwuid(uid); |
38 | if (!pw) | 38 | if (!pw) |
39 | bb_error_msg_and_die("unknown uid %u", (unsigned)uid); | 39 | bb_error_msg_and_die("unknown uid %u", (unsigned)uid); |
@@ -50,6 +50,7 @@ struct group* FAST_FUNC xgetgrgid(gid_t gid) | |||
50 | 50 | ||
51 | char* FAST_FUNC xuid2uname(uid_t uid) | 51 | char* FAST_FUNC xuid2uname(uid_t uid) |
52 | { | 52 | { |
53 | /* Note: used in nofork applets (whoami), be careful not to leak anything */ | ||
53 | struct passwd *pw = xgetpwuid(uid); | 54 | struct passwd *pw = xgetpwuid(uid); |
54 | return pw->pw_name; | 55 | return pw->pw_name; |
55 | } | 56 | } |
diff --git a/libbb/vfork_daemon_rexec.c b/libbb/vfork_daemon_rexec.c index 576534ee5..487ecb0e4 100644 --- a/libbb/vfork_daemon_rexec.c +++ b/libbb/vfork_daemon_rexec.c | |||
@@ -92,6 +92,7 @@ struct nofork_save_area { | |||
92 | void (*die_func)(void); | 92 | void (*die_func)(void); |
93 | const char *applet_name; | 93 | const char *applet_name; |
94 | uint32_t option_mask32; | 94 | uint32_t option_mask32; |
95 | smallint logmode; | ||
95 | uint8_t xfunc_error_retval; | 96 | uint8_t xfunc_error_retval; |
96 | }; | 97 | }; |
97 | static void save_nofork_data(struct nofork_save_area *save) | 98 | static void save_nofork_data(struct nofork_save_area *save) |
@@ -100,6 +101,7 @@ static void save_nofork_data(struct nofork_save_area *save) | |||
100 | save->die_func = die_func; | 101 | save->die_func = die_func; |
101 | save->applet_name = applet_name; | 102 | save->applet_name = applet_name; |
102 | save->option_mask32 = option_mask32; | 103 | save->option_mask32 = option_mask32; |
104 | save->logmode = logmode; | ||
103 | save->xfunc_error_retval = xfunc_error_retval; | 105 | save->xfunc_error_retval = xfunc_error_retval; |
104 | } | 106 | } |
105 | static void restore_nofork_data(struct nofork_save_area *save) | 107 | static void restore_nofork_data(struct nofork_save_area *save) |
@@ -108,6 +110,7 @@ static void restore_nofork_data(struct nofork_save_area *save) | |||
108 | die_func = save->die_func; | 110 | die_func = save->die_func; |
109 | applet_name = save->applet_name; | 111 | applet_name = save->applet_name; |
110 | option_mask32 = save->option_mask32; | 112 | option_mask32 = save->option_mask32; |
113 | logmode = save->logmode; | ||
111 | xfunc_error_retval = save->xfunc_error_retval; | 114 | xfunc_error_retval = save->xfunc_error_retval; |
112 | } | 115 | } |
113 | 116 | ||
@@ -118,8 +121,8 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) | |||
118 | 121 | ||
119 | save_nofork_data(&old); | 122 | save_nofork_data(&old); |
120 | 123 | ||
124 | logmode = LOGMODE_STDIO; | ||
121 | xfunc_error_retval = EXIT_FAILURE; | 125 | xfunc_error_retval = EXIT_FAILURE; |
122 | |||
123 | /* In case getopt() or getopt32() was already called: | 126 | /* In case getopt() or getopt32() was already called: |
124 | * reset the libc getopt() function, which keeps internal state. | 127 | * reset the libc getopt() function, which keeps internal state. |
125 | */ | 128 | */ |
@@ -146,7 +149,6 @@ int FAST_FUNC run_nofork_applet(int applet_no, char **argv) | |||
146 | 149 | ||
147 | /* Restoring some globals */ | 150 | /* Restoring some globals */ |
148 | restore_nofork_data(&old); | 151 | restore_nofork_data(&old); |
149 | |||
150 | /* Other globals can be simply reset to defaults */ | 152 | /* Other globals can be simply reset to defaults */ |
151 | GETOPT_RESET(); | 153 | GETOPT_RESET(); |
152 | 154 | ||
diff --git a/miscutils/ttysize.c b/miscutils/ttysize.c index 7f6a84308..2c2d4ec33 100644 --- a/miscutils/ttysize.c +++ b/miscutils/ttysize.c | |||
@@ -18,7 +18,7 @@ | |||
18 | //config: error, but returns default 80x24. | 18 | //config: error, but returns default 80x24. |
19 | //config: Usage in shell scripts: width=`ttysize w`. | 19 | //config: Usage in shell scripts: width=`ttysize w`. |
20 | 20 | ||
21 | //applet:IF_TTYSIZE(APPLET(ttysize, BB_DIR_USR_BIN, BB_SUID_DROP)) | 21 | //applet:IF_TTYSIZE(APPLET_NOFORK(ttysize, ttysize, BB_DIR_USR_BIN, BB_SUID_DROP, ttysize)) |
22 | 22 | ||
23 | //kbuild:lib-$(CONFIG_TTYSIZE) += ttysize.o | 23 | //kbuild:lib-$(CONFIG_TTYSIZE) += ttysize.o |
24 | 24 | ||
diff --git a/procps/kill.c b/procps/kill.c index 09beefb2d..0ddae2f70 100644 --- a/procps/kill.c +++ b/procps/kill.c | |||
@@ -32,10 +32,10 @@ | |||
32 | //config: in its own session, so it won't kill the shell that is running | 32 | //config: in its own session, so it won't kill the shell that is running |
33 | //config: the script it was called from. | 33 | //config: the script it was called from. |
34 | 34 | ||
35 | //applet:IF_KILL(APPLET(kill, BB_DIR_BIN, BB_SUID_DROP)) | 35 | //applet:IF_KILL( APPLET_NOFORK(kill, kill, BB_DIR_BIN, BB_SUID_DROP, kill)) |
36 | // APPLET_ODDNAME:name main location suid_type help | 36 | // APPLET_NOFORK:name main location suid_type help |
37 | //applet:IF_KILLALL( APPLET_ODDNAME(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) | 37 | //applet:IF_KILLALL( APPLET_NOFORK(killall, kill, BB_DIR_USR_BIN, BB_SUID_DROP, killall)) |
38 | //applet:IF_KILLALL5(APPLET_ODDNAME(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) | 38 | //applet:IF_KILLALL5(APPLET_NOFORK(killall5, kill, BB_DIR_USR_SBIN, BB_SUID_DROP, killall5)) |
39 | 39 | ||
40 | //kbuild:lib-$(CONFIG_KILL) += kill.o | 40 | //kbuild:lib-$(CONFIG_KILL) += kill.o |
41 | //kbuild:lib-$(CONFIG_KILLALL) += kill.o | 41 | //kbuild:lib-$(CONFIG_KILLALL) += kill.o |
@@ -87,7 +87,7 @@ | |||
87 | * + we can't use xfunc here | 87 | * + we can't use xfunc here |
88 | * + we can't use applet_name | 88 | * + we can't use applet_name |
89 | * + we can't use bb_show_usage | 89 | * + we can't use bb_show_usage |
90 | * (Above doesn't apply for killall[5] cases) | 90 | * (doesn't apply for killall[5], still should be careful b/c NOFORK) |
91 | * | 91 | * |
92 | * kill %n gets translated into kill ' -<process group>' by shell (note space!) | 92 | * kill %n gets translated into kill ' -<process group>' by shell (note space!) |
93 | * This is needed to avoid collision with kill -9 ... syntax | 93 | * This is needed to avoid collision with kill -9 ... syntax |
diff --git a/procps/pwdx.c b/procps/pwdx.c index dac238950..84802bbcd 100644 --- a/procps/pwdx.c +++ b/procps/pwdx.c | |||
@@ -14,7 +14,7 @@ | |||
14 | //config: help | 14 | //config: help |
15 | //config: Report current working directory of a process | 15 | //config: Report current working directory of a process |
16 | 16 | ||
17 | //applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP)) | 17 | //applet:IF_PWDX(APPLET_NOFORK(pwdx, pwdx, BB_DIR_USR_BIN, BB_SUID_DROP, pwdx)) |
18 | 18 | ||
19 | //kbuild:lib-$(CONFIG_PWDX) += pwdx.o | 19 | //kbuild:lib-$(CONFIG_PWDX) += pwdx.o |
20 | 20 | ||
@@ -50,6 +50,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv) | |||
50 | 50 | ||
51 | sprintf(buf, "/proc/%u/cwd", pid); | 51 | sprintf(buf, "/proc/%u/cwd", pid); |
52 | 52 | ||
53 | /* NOFORK: only one alloc is allowed; must free */ | ||
53 | s = xmalloc_readlink(buf); | 54 | s = xmalloc_readlink(buf); |
54 | // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR" | 55 | // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR" |
55 | printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno)); | 56 | printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno)); |