aboutsummaryrefslogtreecommitdiff
path: root/coreutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2017-08-03 19:00:01 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-08-03 19:03:32 +0200
commit39194f030918b87eeb3e11e94cfa05f575fb47b4 (patch)
tree97ea35e2c5984c5c6757ff9a540630ada4b234d5 /coreutils
parent663ae52676eae3b0fdc6bb968ff6497279a034a4 (diff)
downloadbusybox-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>
Diffstat (limited to 'coreutils')
-rw-r--r--coreutils/date.c21
-rw-r--r--coreutils/readlink.c7
-rw-r--r--coreutils/realpath.c3
3 files changed, 19 insertions, 12 deletions
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
155static 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
162static const char date_longopts[] ALIGN1 = 156static 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
174static void maybe_set_utc(int opt)
175{
176 if (opt & OPT_UTC)
177 putenv((char*)"TZ=UTC0");
178}
179
173int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 180int date_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
174int date_main(int argc UNUSED_PARAM, char **argv) 181int 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);