mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-05 03:20:46 -05:00
Avoid hardcoding max fd size
Android changed max fd limit to 32768 since Android 9: https://github.com/aosp-mirror/platform_system_core/commit/cb5fccc83c6c757f25436884e96c318f72743ffd Co-authored-by: LoveSy <shana@zju.edu.cn>
This commit is contained in:
@@ -226,7 +226,7 @@ void ZygiskContext::sanitize_fds() {
|
||||
env->SetIntArrayRegion(
|
||||
array, old_len, static_cast<int>(exempted_fds.size()), exempted_fds.data());
|
||||
for (int fd : exempted_fds) {
|
||||
if (fd >= 0 && fd < MAX_FD_SIZE) {
|
||||
if (fd >= 0 && fd < allowed_fds.size()) {
|
||||
allowed_fds[fd] = true;
|
||||
}
|
||||
}
|
||||
@@ -239,7 +239,7 @@ void ZygiskContext::sanitize_fds() {
|
||||
int len = env->GetArrayLength(fdsToIgnore);
|
||||
for (int i = 0; i < len; ++i) {
|
||||
int fd = arr[i];
|
||||
if (fd >= 0 && fd < MAX_FD_SIZE) {
|
||||
if (fd >= 0 && fd < allowed_fds.size()) {
|
||||
allowed_fds[fd] = true;
|
||||
}
|
||||
}
|
||||
@@ -257,7 +257,7 @@ void ZygiskContext::sanitize_fds() {
|
||||
int dfd = dirfd(dir.get());
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
int fd = parse_int(entry->d_name);
|
||||
if ((fd < 0 || fd >= MAX_FD_SIZE || !allowed_fds[fd]) && fd != dfd) {
|
||||
if ((fd < 0 || fd >= allowed_fds.size() || !allowed_fds[fd]) && fd != dfd) {
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
@@ -296,7 +296,7 @@ void ZygiskContext::fork_pre() {
|
||||
auto dir = xopen_dir("/proc/self/fd");
|
||||
for (dirent *entry; (entry = xreaddir(dir.get()));) {
|
||||
int fd = parse_int(entry->d_name);
|
||||
if (fd < 0 || fd >= MAX_FD_SIZE) {
|
||||
if (fd < 0 || fd >= allowed_fds.size()) {
|
||||
close(fd);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user