Check null before dereferencing fds_to_ignore

This commit is contained in:
topjohnwu 2022-03-03 21:34:53 -08:00
parent 13ef3058c6
commit 0c681cdab4

View File

@ -394,15 +394,17 @@ void HookContext::run_modules_pre(const vector<int> &fds) {
// Add all ignored fd onto whitelist // Add all ignored fd onto whitelist
if (state[APP_SPECIALIZE] && args->fds_to_ignore) { if (state[APP_SPECIALIZE] && args->fds_to_ignore) {
int len = env->GetArrayLength(*args->fds_to_ignore); if (jintArray fdsToIgnore = *args->fds_to_ignore) {
int *arr = env->GetIntArrayElements(*args->fds_to_ignore, nullptr); int len = env->GetArrayLength(fdsToIgnore);
for (int i = 0; i < len; ++i) { int *arr = env->GetIntArrayElements(fdsToIgnore, nullptr);
int fd = arr[i]; for (int i = 0; i < len; ++i) {
if (fd >= 0 && fd < 1024) { int fd = arr[i];
open_fds[fd] = true; if (fd >= 0 && fd < 1024) {
open_fds[fd] = true;
}
} }
env->ReleaseIntArrayElements(fdsToIgnore, arr, JNI_ABORT);
} }
env->ReleaseIntArrayElements(*args->fds_to_ignore, arr, 0);
} }
// Close all unrecorded fds // Close all unrecorded fds