Guard the JNI fragment registration against the null detach view.

Gio's GioView.onDestroyView signals detach with ViewEvent{View: 0};
handleEvent already filters these, but add defense in depth so any
caller forwarding the event unfiltered cannot drive the JNI path
(GetObjectClass on a null ref aborts the process, the recents-wipe
SIGABRT). Completes the intent of PR #1, whose handleEvent guard is
already in master from the migration commit.

Fixes: recents-wipe crash defense (PR #1 superseded).
This commit is contained in:
Greg Pomerantz 2026-08-21 15:29:24 -04:00
parent dc7661e226
commit 4c337ff06d
2 changed files with 15 additions and 0 deletions

View File

@ -51,6 +51,9 @@ func Java_st_wow_git_passgo_PgpConnect_installComplete(env *C.JNIEnv, class C.jc
func InitPgp(view uintptr) {
log.Printf("InitPgp()")
if view == 0 {
return // detach signal; nothing to register
}
jvm = app.JavaVM()
SetJVM(jvm) // why?
RunInJVM(func(env *JNIEnv) {
@ -63,6 +66,9 @@ func InitPgp(view uintptr) {
// screen on Android 11+) so the app can read the store in shared storage.
func InitPermissions(view uintptr) {
log.Printf("InitPermissions()")
if view == 0 {
return // detach signal; nothing to register
}
RunInJVM(func(env *JNIEnv) {
C.registerPermissionsFragment(env, (C.jobject)(unsafe.Pointer(view)))
})

View File

@ -7,6 +7,12 @@
void
registerFragment(JNIEnv *env, jobject view) {
if (view == NULL) {
// Detach signal (Gio sends ViewEvent{View: 0} when the view is
// destroyed, e.g. on a recents-wipe); the Go side already
// filters these, but GetObjectClass(null) aborts the process.
return;
}
jclass cls = (*env)->GetObjectClass(env, view);
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jobject ctx = (*env)->CallObjectMethod(env, view, mid);
@ -23,6 +29,9 @@ registerFragment(JNIEnv *env, jobject view) {
void
registerPermissionsFragment(JNIEnv *env, jobject view) {
if (view == NULL) {
return; // detach signal; see registerFragment
}
jclass cls = (*env)->GetObjectClass(env, view);
jmethodID mid = (*env)->GetMethodID(env, cls, "getContext", "()Landroid/content/Context;");
jobject ctx = (*env)->CallObjectMethod(env, view, mid);