setpriv: do not process remaining args

By default, the 'getopt32' call will continue parsing the command line
even after hitting a non-option string. But in setpriv, this should be
avoided, as all parameters following the initial non-option argument are
in fact arguments to the binary that is to be executed by setpriv.
Otherwise, calling e.g. 'busybox setpriv ls -l' would result in an error
due to the unknown parameter "-l".

Fix the issue by passing "+" as the first character in the options
string. This will cause 'getopt32' to stop processing after hitting the
first non-option.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Patrick Steinhardt 2017-07-02 15:42:50 +02:00 committed by Denys Vlasenko
parent 8965e5089e
commit ee67c9a60a
1 changed files with 2 additions and 1 deletions

View File

@ -62,7 +62,8 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv)
opt_complementary = "-1";
applet_long_options = setpriv_longopts;
opts = getopt32(argv, "");
opts = getopt32(argv, "+");
if (opts) {
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0))
bb_simple_perror_msg_and_die("prctl: NO_NEW_PRIVS");