su: add legacy cmd compatibility check

This commit is contained in:
vvb2060
2026-10-05 20:03:11 -07:00
committed by John Wu
parent 160fb3e40b
commit c155d9f0d1
6 changed files with 51 additions and 17 deletions
+14 -2
View File
@@ -109,7 +109,15 @@ impl MagiskD {
}
fn app_notify(&self, cred: &UCred, info: &SuInfo, request: &SuRequest) {
let command = &request.command.join(" ");
let mut command = request.command.join(" ");
let mut legacy_cmd = false;
if request.command.len() >= 4
&& request.command[1] == "-c"
&& !request.command[2].contains(b" ")
{
command = format!("(Syntax Error) {}", command);
legacy_cmd = true;
}
let extras = [
Extra {
key: "from.uid",
@@ -141,7 +149,11 @@ impl MagiskD {
},
Extra {
key: "command",
value: Str(command),
value: Str(&command),
},
Extra {
key: "legacy_cmd",
value: Bool(legacy_cmd),
},
Extra {
key: "notify",
+20 -3
View File
@@ -224,7 +224,7 @@ end:
interactive |= !has_command;
// Determine which one of our streams are attached to a TTY
int atty = 0;
if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN;
if (isatty(STDIN_FILENO) && interactive) atty |= ATTY_IN;
if (isatty(STDOUT_FILENO) && interactive) atty |= ATTY_OUT;
if (isatty(STDERR_FILENO) && interactive) atty |= ATTY_ERR;
@@ -410,8 +410,25 @@ void exec_root_shell(int client, int pid, SuRequest &req, MntNsMode mode) {
}
vector<const char *> argv;
for (auto &str: req.command) {
argv.push_back(str.c_str());
string cmd;
if (req.command.size() >= 4 &&
string_view(req.command[1].c_str()) == "-c" &&
string_view(req.command[2].c_str()).find(' ') == string::npos) {
cmd = req.command[2].c_str();
for (size_t i = 3; i < req.command.size(); ++i) {
cmd += ' ';
cmd += req.command[i].c_str();
}
argv.reserve(4);
argv.push_back(req.command[0].c_str());
argv.push_back(req.command[1].c_str());
argv.push_back(cmd.c_str());
} else {
argv.reserve(req.command.size() + 1);
for (auto &arg: req.command) {
argv.push_back(arg.c_str());
}
}
argv.push_back(nullptr);