PATCH: replacing exec*p with BB_EXEC*P
Gabriel L. Somlo
somlo at cmu.edu
Sat Feb 3 23:58:43 UTC 2007
Denis & All,
The first part of this patch fixes BB_EXECLP in libbb.h, (it
accidentally calls execvp instead of execlp).
The rest replaces execlp and execvp calls with BB_EXECLP and
BB_EXECVP, respectively (except in the shells, where we use
STANDALONE_SHELL to accomplish this).
Once this is in, we should be able to remove hardcoded paths from
anywhere else they might still be used.
Cheers,
Gabriel
diff -NarU5 busybox-svn-17746.orig/include/libbb.h busybox-svn-17746/include/libbb.h
--- busybox-svn-17746.orig/include/libbb.h 2007-02-03 18:17:57.000000000 -0500
+++ busybox-svn-17746/include/libbb.h 2007-02-03 18:36:09.000000000 -0500
@@ -559,11 +559,11 @@
execvp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd)
#define BB_EXECLP(prog,cmd,...) \
execlp((find_applet_by_name(prog)) ? CONFIG_BUSYBOX_EXEC_PATH : prog, cmd, __VA_ARGS__)
#else
#define BB_EXECVP(prog,cmd) execvp(prog,cmd)
-#define BB_EXECLP(prog,cmd,...) execvp(prog,cmd, __VA_ARGS__)
+#define BB_EXECLP(prog,cmd,...) execlp(prog,cmd, __VA_ARGS__)
#endif
USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
int inflate(int in, int out);
diff -NarU5 busybox-svn-17746.orig/archival/tar.c busybox-svn-17746/archival/tar.c
--- busybox-svn-17746.orig/archival/tar.c 2007-02-03 18:17:52.000000000 -0500
+++ busybox-svn-17746/archival/tar.c 2007-02-03 18:48:50.000000000 -0500
@@ -527,11 +527,11 @@
dup2(tbInfo.tarFd, 1);
close(gzipStatusPipe[0]);
fcntl(gzipStatusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows success */
- execlp(zip_exec, zip_exec, "-f", NULL);
+ BB_EXECLP(zip_exec, zip_exec, "-f", NULL);
vfork_exec_errno = errno;
close(gzipStatusPipe[1]);
exit(-1);
} else if (gzipPid > 0) {
diff -NarU5 busybox-svn-17746.orig/console-tools/openvt.c busybox-svn-17746/console-tools/openvt.c
--- busybox-svn-17746.orig/console-tools/openvt.c 2007-02-03 18:17:52.000000000 -0500
+++ busybox-svn-17746/console-tools/openvt.c 2007-02-03 18:31:02.000000000 -0500
@@ -34,10 +34,10 @@
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
while (fd > 2) close(fd--);
- execvp(argv[2], &argv[2]);
+ BB_EXECVP(argv[2], &argv[2]);
_exit(1);
}
return EXIT_SUCCESS;
}
diff -NarU5 busybox-svn-17746.orig/coreutils/chroot.c busybox-svn-17746/coreutils/chroot.c
--- busybox-svn-17746.orig/coreutils/chroot.c 2007-02-03 18:17:54.000000000 -0500
+++ busybox-svn-17746/coreutils/chroot.c 2007-02-03 18:32:55.000000000 -0500
@@ -31,8 +31,8 @@
*argv = (char *) DEFAULT_SHELL;
}
argv[1] = (char *) "-i";
}
- execvp(*argv, argv);
+ BB_EXECVP(*argv, argv);
bb_perror_msg_and_die("cannot execute %s", *argv);
}
diff -NarU5 busybox-svn-17746.orig/coreutils/env.c busybox-svn-17746/coreutils/env.c
--- busybox-svn-17746.orig/coreutils/env.c 2007-02-03 18:17:54.000000000 -0500
+++ busybox-svn-17746/coreutils/env.c 2007-02-03 18:33:53.000000000 -0500
@@ -79,11 +79,11 @@
}
++argv;
}
if (*argv) {
- execvp(*argv, argv);
+ BB_EXECVP(*argv, argv);
/* SUSv3-mandated exit codes. */
xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
bb_perror_msg_and_die("%s", *argv);
}
diff -NarU5 busybox-svn-17746.orig/coreutils/install.c busybox-svn-17746/coreutils/install.c
--- busybox-svn-17746.orig/coreutils/install.c 2007-02-03 18:17:54.000000000 -0500
+++ busybox-svn-17746/coreutils/install.c 2007-02-03 18:49:11.000000000 -0500
@@ -124,11 +124,11 @@
) {
bb_perror_msg("cannot change ownership of %s", dest);
ret = EXIT_FAILURE;
}
if (flags & OPT_STRIP) {
- if (execlp("strip", "strip", dest, NULL) == -1) {
+ if (BB_EXECLP("strip", "strip", dest, NULL) == -1) {
bb_perror_msg("strip");
ret = EXIT_FAILURE;
}
}
if (ENABLE_FEATURE_CLEAN_UP && isdir) free(dest);
diff -NarU5 busybox-svn-17746.orig/coreutils/nice.c busybox-svn-17746/coreutils/nice.c
--- busybox-svn-17746.orig/coreutils/nice.c 2007-02-03 18:17:54.000000000 -0500
+++ busybox-svn-17746/coreutils/nice.c 2007-02-03 18:34:17.000000000 -0500
@@ -45,11 +45,11 @@
if (setpriority(PRIO_PROCESS, 0, prio) < 0) {
bb_perror_msg_and_die("setpriority(%d)", prio);
}
}
- execvp(*argv, argv); /* Now exec the desired program. */
+ BB_EXECVP(*argv, argv); /* Now exec the desired program. */
/* The exec failed... */
xfunc_error_retval = (errno == ENOENT) ? 127 : 126; /* SUSv3 */
bb_perror_msg_and_die("%s", *argv);
}
diff -NarU5 busybox-svn-17746.orig/coreutils/nohup.c busybox-svn-17746/coreutils/nohup.c
--- busybox-svn-17746.orig/coreutils/nohup.c 2007-02-03 18:17:54.000000000 -0500
+++ busybox-svn-17746/coreutils/nohup.c 2007-02-03 18:34:07.000000000 -0500
@@ -51,10 +51,10 @@
if (nullfd > 2)
close(nullfd);
signal(SIGHUP, SIG_IGN);
- execvp(argv[1], argv+1);
+ BB_EXECVP(argv[1], argv+1);
if (ENABLE_FEATURE_CLEAN_UP && home)
free((char*)nohupout);
bb_perror_msg_and_die("%s", argv[1]);
}
diff -NarU5 busybox-svn-17746.orig/e2fsprogs/fsck.c busybox-svn-17746/e2fsprogs/fsck.c
--- busybox-svn-17746.orig/e2fsprogs/fsck.c 2007-02-03 18:17:56.000000000 -0500
+++ busybox-svn-17746/e2fsprogs/fsck.c 2007-02-03 18:34:40.000000000 -0500
@@ -675,11 +675,11 @@
if (!interactive) {
/* NB: e2fsck will complain because of this!
* Use "fsck -s" to avoid... */
close(0);
}
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("%s", argv[0]);
}
}
for (i = num_args+1; i < argc; i++)
diff -NarU5 busybox-svn-17746.orig/findutils/xargs.c busybox-svn-17746/findutils/xargs.c
--- busybox-svn-17746.orig/findutils/xargs.c 2007-02-03 18:17:58.000000000 -0500
+++ busybox-svn-17746/findutils/xargs.c 2007-02-03 18:35:23.000000000 -0500
@@ -58,11 +58,11 @@
if (p < 0)
bb_perror_msg_and_die("vfork");
if (p == 0) {
/* vfork -- child */
- execvp(args[0], args);
+ BB_EXECVP(args[0], args);
exec_errno = errno; /* set error to shared stack */
_exit(1);
}
/* vfork -- parent */
diff -NarU5 busybox-svn-17746.orig/loginutils/adduser.c busybox-svn-17746/loginutils/adduser.c
--- busybox-svn-17746.orig/loginutils/adduser.c 2007-02-03 18:17:57.000000000 -0500
+++ busybox-svn-17746/loginutils/adduser.c 2007-02-03 18:49:30.000000000 -0500
@@ -78,11 +78,11 @@
static void passwd_wrapper(const char *login) ATTRIBUTE_NORETURN;
static void passwd_wrapper(const char *login)
{
static const char prog[] = "passwd";
- execlp(prog, prog, login, NULL);
+ BB_EXECLP(prog, prog, login, NULL);
bb_error_msg_and_die("failed to execute '%s', you must set the password for '%s' manually", prog, login);
}
/* putpwent(3) remix */
static int adduser(struct passwd *p, unsigned long flags)
diff -NarU5 busybox-svn-17746.orig/loginutils/login.c busybox-svn-17746/loginutils/login.c
--- busybox-svn-17746.orig/loginutils/login.c 2007-02-03 18:17:57.000000000 -0500
+++ busybox-svn-17746/loginutils/login.c 2007-02-03 18:36:35.000000000 -0500
@@ -355,11 +355,11 @@
setenv("LOGIN_TTY", full_tty, 1);
setenv("LOGIN_USER", pw->pw_name, 1);
setenv("LOGIN_UID", utoa(pw->pw_uid), 1);
setenv("LOGIN_GID", utoa(pw->pw_gid), 1);
setenv("LOGIN_SHELL", pw->pw_shell, 1);
- execvp(script, t_argv);
+ BB_EXECVP(script, t_argv);
exit(1);
default: /* parent */
wait(NULL);
}
}
diff -NarU5 busybox-svn-17746.orig/miscutils/devfsd.c busybox-svn-17746/miscutils/devfsd.c
--- busybox-svn-17746.orig/miscutils/devfsd.c 2007-02-03 18:17:56.000000000 -0500
+++ busybox-svn-17746/miscutils/devfsd.c 2007-02-03 18:38:06.000000000 -0500
@@ -376,11 +376,11 @@
exit (EXIT_SUCCESS);
}
/* Child : if arg0 != NULL do execvp */
if(arg0 != NULL )
{
- execvp (arg0, arg);
+ BB_EXECVP(arg0, arg);
msg_logger_and_die(LOG_ERR, "execvp");
}
}
static void safe_memcpy( char *dest, const char *src, int len)
diff -NarU5 busybox-svn-17746.orig/miscutils/setsid.c busybox-svn-17746/miscutils/setsid.c
--- busybox-svn-17746.orig/miscutils/setsid.c 2007-02-03 18:17:56.000000000 -0500
+++ busybox-svn-17746/miscutils/setsid.c 2007-02-03 18:39:23.000000000 -0500
@@ -34,9 +34,9 @@
}
/* child */
setsid(); /* no error possible */
- execvp(argv[1], argv + 1);
+ BB_EXECVP(argv[1], argv + 1);
bb_perror_msg_and_die("%s", argv[1]);
}
diff -NarU5 busybox-svn-17746.orig/miscutils/taskset.c busybox-svn-17746/miscutils/taskset.c
--- busybox-svn-17746.orig/miscutils/taskset.c 2007-02-03 18:17:56.000000000 -0500
+++ busybox-svn-17746/miscutils/taskset.c 2007-02-03 18:39:02.000000000 -0500
@@ -89,11 +89,11 @@
state += 8;
++argv;
goto print_aff;
}
++argv;
- execvp(*argv, argv);
+ BB_EXECVP(*argv, argv);
bb_perror_msg_and_die("%s", *argv);
}
#undef OPT_p
#undef TASKSET_PRINTF_MASK
#undef from_cpuset
diff -NarU5 busybox-svn-17746.orig/miscutils/time.c busybox-svn-17746/miscutils/time.c
--- busybox-svn-17746.orig/miscutils/time.c 2007-02-03 18:17:56.000000000 -0500
+++ busybox-svn-17746/miscutils/time.c 2007-02-03 18:38:33.000000000 -0500
@@ -408,11 +408,11 @@
if (pid < 0)
bb_error_msg_and_die("cannot fork");
else if (pid == 0) { /* If child. */
/* Don't cast execvp arguments; that causes errors on some systems,
versus merely warnings if the cast is left off. */
- execvp(cmd[0], cmd);
+ BB_EXECVP(cmd[0], cmd);
bb_error_msg("cannot run %s", cmd[0]);
_exit(errno == ENOENT ? 127 : 126);
}
/* Have signals kill the child but not self (if possible). */
diff -NarU5 busybox-svn-17746.orig/networking/ifupdown.c busybox-svn-17746/networking/ifupdown.c
--- busybox-svn-17746.orig/networking/ifupdown.c 2007-02-03 18:17:50.000000000 -0500
+++ busybox-svn-17746/networking/ifupdown.c 2007-02-03 18:40:21.000000000 -0500
@@ -1002,11 +1002,11 @@
dup2(outfd[1], 1);
close(infd[0]);
close(infd[1]);
close(outfd[0]);
close(outfd[1]);
- execvp(command, argv);
+ BB_EXECVP(command, argv);
exit(127);
default: /* parent */
*in = fdopen(infd[1], "w");
*out = fdopen(outfd[0], "r");
close(infd[0]);
diff -NarU5 busybox-svn-17746.orig/networking/nc.c busybox-svn-17746/networking/nc.c
--- busybox-svn-17746.orig/networking/nc.c 2007-02-03 18:17:50.000000000 -0500
+++ busybox-svn-17746/networking/nc.c 2007-02-03 18:42:22.000000000 -0500
@@ -147,11 +147,11 @@
dup2(cfd, 0);
close(cfd);
}
dup2(0, 1);
dup2(0, 2);
- USE_NC_EXTRA(execvp(execparam[0], execparam);)
+ USE_NC_EXTRA(BB_EXECVP(execparam[0], execparam);)
/* Don't print stuff or it will go over the wire.... */
_exit(127);
}
// Select loop copying stdin to cfd, and cfd to stdout.
diff -NarU5 busybox-svn-17746.orig/runit/chpst.c busybox-svn-17746/runit/chpst.c
--- busybox-svn-17746.orig/runit/chpst.c 2007-02-03 18:17:58.000000000 -0500
+++ busybox-svn-17746/runit/chpst.c 2007-02-03 18:42:47.000000000 -0500
@@ -308,11 +308,11 @@
if (env_user) euidgid(env_user);
if (set_user) suidgid(set_user);
if (OPT_nostdin) close(0);
if (OPT_nostdout) close(1);
if (OPT_nostderr) close(2);
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
static void setuidgid(int argc, char **argv)
{
@@ -320,11 +320,11 @@
account = *++argv;
if (!account) bb_show_usage();
if (!*++argv) bb_show_usage();
suidgid((char*)account);
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
static void envuidgid(int argc, char **argv)
{
@@ -332,11 +332,11 @@
account = *++argv;
if (!account) bb_show_usage();
if (!*++argv) bb_show_usage();
euidgid((char*)account);
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
static void envdir(int argc, char **argv)
{
@@ -344,11 +344,11 @@
dir = *++argv;
if (!dir) bb_show_usage();
if (!*++argv) bb_show_usage();
edir(dir);
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
static void softlimit(int argc, char **argv)
{
@@ -367,8 +367,8 @@
if (option_mask32 & 0x200) limits = xatoul(s); // -s
if (option_mask32 & 0x400) limitt = xatoul(t); // -t
argv += optind;
if (!argv[0]) bb_show_usage();
slimit();
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
bb_perror_msg_and_die("exec %s", argv[0]);
}
diff -NarU5 busybox-svn-17746.orig/runit/runsvdir.c busybox-svn-17746/runit/runsvdir.c
--- busybox-svn-17746.orig/runit/runsvdir.c 2007-02-03 18:17:58.000000000 -0500
+++ busybox-svn-17746/runit/runsvdir.c 2007-02-03 18:43:10.000000000 -0500
@@ -71,11 +71,11 @@
prog[1] = (char*)name;
prog[2] = NULL;
sig_uncatch(SIGHUP);
sig_uncatch(SIGTERM);
if (pgrp) setsid();
- execvp(prog[0], prog);
+ BB_EXECVP(prog[0], prog);
//pathexec_run(*prog, prog, (char* const*)environ);
fatal2_cannot("start runsv ", name);
}
sv[no].pid = pid;
}
diff -NarU5 busybox-svn-17746.orig/util-linux/setarch.c busybox-svn-17746/util-linux/setarch.c
--- busybox-svn-17746.orig/util-linux/setarch.c 2007-02-03 18:17:59.000000000 -0500
+++ busybox-svn-17746/util-linux/setarch.c 2007-02-03 18:45:38.000000000 -0500
@@ -44,10 +44,10 @@
/* Try to set personality */
if (personality(pers) >= 0) {
/* Try to execute the program */
- execvp(argv[0], argv);
+ BB_EXECVP(argv[0], argv);
}
bb_perror_msg_and_die("%s", argv[0]);
}
More information about the busybox
mailing list