ash: in tryexec(), ensure we don't try to run embedded scripts as applets
[oweals/busybox.git] / procps / pwdx.c
index dac238950f0f391ec3464d4e422e805e5e97e20a..6009e2aa3783057f35425dc0317868e27dc312c7 100644 (file)
@@ -7,14 +7,13 @@
  *
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
 //config:config PWDX
 //config:      bool "pwdx (3.5 kb)"
 //config:      default y
 //config:      help
 //config:      Report current working directory of a process
 
-//applet:IF_PWDX(APPLET(pwdx, BB_DIR_USR_BIN, BB_SUID_DROP))
+//applet:IF_PWDX(APPLET_NOFORK(pwdx, pwdx, BB_DIR_USR_BIN, BB_SUID_DROP, pwdx))
 
 //kbuild:lib-$(CONFIG_PWDX) += pwdx.o
 
@@ -28,8 +27,7 @@
 int pwdx_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int pwdx_main(int argc UNUSED_PARAM, char **argv)
 {
-       opt_complementary = "-1";
-       getopt32(argv, "");
+       getopt32(argv, "^" "" "\0" "-1");
        argv += optind;
 
        do {
@@ -50,6 +48,7 @@ int pwdx_main(int argc UNUSED_PARAM, char **argv)
 
                sprintf(buf, "/proc/%u/cwd", pid);
 
+               /* NOFORK: only one alloc is allowed; must free */
                s = xmalloc_readlink(buf);
                // "pwdx /proc/1" says "/proc/1: DIR", not "1: DIR"
                printf("%s: %s\n", *argv, s ? s : strerror(errno == ENOENT ? ESRCH : errno));