From d040b01c2eab4e13efe20cf916e6bc80e7927a0d Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Fri, 1 Apr 2022 14:19:28 -0500 Subject: [PATCH] Fix "toybox command --help" for NEEDROOT commands. --- main.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 010efc01..9d9d7061 100644 --- a/main.c +++ b/main.c @@ -165,7 +165,6 @@ void toy_init(struct toy_list *which, char *argv[]) void *oldwhich = toys.which; // Drop permissions for non-suid commands. - if (CFG_TOYBOX_SUID) { if (!toys.which) toys.which = toy_list; @@ -181,6 +180,7 @@ void toy_init(struct toy_list *which, char *argv[]) error_msg("Not installed suid root"); if ((which->flags & TOYFLAG_NEEDROOT) && euid) { + toys.which = which; check_help(argv+1); help_exit("Not root"); } @@ -237,12 +237,13 @@ void toybox_main(void) // fast path: try to exec immediately. // (Leave toys.which null to disable suid return logic.) - // Try dereferencing one layer of symlink + // Try dereferencing symlinks until we hit a recognized name while (s) { - struct toy_list *tl = toy_find(basename(s)); + char *ss = basename(s); + struct toy_list *tl = toy_find(ss); - if (tl==toy_list && s!=toys.argv[1]) unknown(basename(s)); - toy_exec_which(toy_find(basename(s)), toys.argv+1); + if (tl==toy_list && s!=toys.argv[1]) unknown(ss); + toy_exec_which(tl, toys.argv+1); s = (0