Skip to content

Commit 18fd3b4

Browse files
committed
su: add legacy cmd compatibility check
1 parent b4486f6 commit 18fd3b4

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

native/src/core/su/su.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ int su_client_main(int argc, char *argv[]) {
225225
interactive |= !has_command;
226226
// Determine which one of our streams are attached to a TTY
227227
int atty = 0;
228-
if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN;
228+
if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN;
229229
if (isatty(STDOUT_FILENO) && interactive) atty |= ATTY_OUT;
230230
if (isatty(STDERR_FILENO) && interactive) atty |= ATTY_ERR;
231231

@@ -411,8 +411,25 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) {
411411
}
412412

413413
vector<const char *> argv;
414-
for (auto &str: req.command) {
415-
argv.push_back(str.c_str());
414+
string cmd;
415+
if (req.command.size() >= 4 &&
416+
string_view(req.command[1].c_str()) == "-c" &&
417+
string_view(req.command[2].c_str()).find(' ') == string::npos) {
418+
cmd = req.command[2].c_str();
419+
for (size_t i = 3; i < req.command.size(); ++i) {
420+
cmd += ' ';
421+
cmd += req.command[i].c_str();
422+
}
423+
424+
argv.reserve(4);
425+
argv.push_back(req.command[0].c_str());
426+
argv.push_back(req.command[1].c_str());
427+
argv.push_back(cmd.c_str());
428+
} else {
429+
argv.reserve(req.command.size() + 1);
430+
for (auto &arg: req.command) {
431+
argv.push_back(arg.c_str());
432+
}
416433
}
417434
argv.push_back(nullptr);
418435

0 commit comments

Comments
 (0)