Sanitize magiskhide targets

Fix #1785
This commit is contained in:
topjohnwu 2019-09-01 14:16:12 +08:00
parent dd35224f92
commit cfad7dd317
3 changed files with 27 additions and 3 deletions

View File

@ -57,10 +57,32 @@ static void kill_process(const char *name, bool multi = false) {
});
}
static bool validate(const char *s) {
bool dot = false;
for (char c; (c = *s); ++s) {
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') ||
(c >= '0' && c <= '9') || c == '_') {
dot = false;
continue;
}
if (c == '.') {
if (dot) // No consecutive dots
return false;
dot = true;
continue;
}
return false;
}
return true;
}
static int add_list(const char *pkg, const char *proc = "") {
if (proc[0] == '\0')
proc = pkg;
if (!validate(pkg) || !validate(proc))
return HIDE_INVALID_PKG;
for (auto &hide : hide_set)
if (hide.first == pkg && hide.second == proc)
return HIDE_ITEM_EXIST;

View File

@ -147,8 +147,9 @@ int magiskhide_main(int argc, char *argv[]) {
case HIDE_NO_NS:
fprintf(stderr, "Your kernel doesn't support mount namespace\n");
break;
/* Errors */
case HIDE_INVALID_PKG:
fprintf(stderr, "Invalid package / process name\n");
break;
case ROOT_REQUIRED:
fprintf(stderr, "Root is required for this operation\n");
break;

View File

@ -58,5 +58,6 @@ enum {
HIDE_NOT_ENABLED,
HIDE_ITEM_EXIST,
HIDE_ITEM_NOT_EXIST,
HIDE_NO_NS
HIDE_NO_NS,
HIDE_INVALID_PKG
};