aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2015-02-15 15:27:43 -0600
committerRob Landley <rob@landley.net>2015-02-15 15:27:43 -0600
commit7c5ed1cedaa881fff52da019da96f9bf6735dc5d (patch)
treea24c083c4d0d82987b1a3d779339e7f6f3327ccd
parentc49b9a97559d2009e9076e063b2e9acbc13fb9ef (diff)
downloadtoybox-7c5ed1cedaa881fff52da019da96f9bf6735dc5d.tar.gz
Only discard optargs in toy_exec() after finding the command to run (otherwise the fallback exevp() segfaults).
-rw-r--r--main.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/main.c b/main.c
index 458d4702..a81cfb92 100644
--- a/main.c
+++ b/main.c
@@ -127,15 +127,15 @@ void toy_exec(char *argv[])
{
struct toy_list *which;
- // don't blank old optargs if our new argc lives in the old optargs.
- if (argv>=toys.optargs && argv<=toys.optargs+toys.optc) toys.optargs = 0;
-
// Return if we can't find it, or need to re-exec to acquire root,
// or if stack depth is getting silly.
if (!(which = toy_find(argv[0]))) return;
if (toys.recursion && (which->flags & TOYFLAG_ROOTONLY) && getuid()) return;
if (toys.recursion++ > 5) return;
+ // don't blank old optargs if our new argc lives in the old optargs.
+ if (argv>=toys.optargs && argv<=toys.optargs+toys.optc) toys.optargs = 0;
+
// Run command
toy_init(which, argv);
if (toys.which) toys.which->toy_main();