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);
int *arr = env->GetIntArrayElements(fdsToIgnore, nullptr);
for (int i = 0; i < len; ++i) { for (int i = 0; i < len; ++i) {
int fd = arr[i]; int fd = arr[i];
if (fd >= 0 && fd < 1024) { if (fd >= 0 && fd < 1024) {
open_fds[fd] = true; open_fds[fd] = true;
} }
} }
env->ReleaseIntArrayElements(*args->fds_to_ignore, arr, 0); env->ReleaseIntArrayElements(fdsToIgnore, arr, JNI_ABORT);
}
} }
// Close all unrecorded fds // Close all unrecorded fds