Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check internal JNI calls for pending exceptions and no-op #1088

Merged
merged 1 commit into from
Jan 25, 2021

Conversation

fractalwrench
Copy link
Contributor

@fractalwrench fractalwrench commented Jan 22, 2021

Goal

Makes safe all invocations of GetMethodId, GetStaticMethodId, and FindClass within the NDK module. This is achieved by calling ExceptionClear to remove any pending JVM exceptions that could lead to app termination. The return value of all these invocations is checked for NULL, and no-ops if this is the case.

Changeset

  • Replaced FindClass with bsg_safe_find_class (and equivalents for GetMethodId/GetStaticMethodId)
  • When loading a class, check if there was an exception in the JVM, and if so clear it and return NULL. The following errors can be thrown. As these are not recoverable, Bugsnag should no-op rather than crashing the process:
    • NoSuchMethodError
    • ExceptionInInitializerError
    • OutOfMemoryError
    • ClassFormatError
    • ClassCircularityError
    • NoClassDefFoundError
  • Alter all invocations to check the return value for NULL and no-op in this case
  • Added inline comments to explain what each JNI call is doing, which should improve readability (this comes from a previous review comment and it seemed an opportune moment)

Testing

Relied on existing test coverage.

Remaining work

The ANR plugin has not been converted to use these safe calls yet as it cannot directly access the methods. There are also several other JNI calls which can throw errors that Bugsnag does not currently handle. Both these will be addressed in separate changesets.

@fractalwrench fractalwrench changed the title fix: check JNI calls for pending exceptions and no-op Check JNI calls for pending exceptions and no-op Jan 22, 2021
@fractalwrench fractalwrench changed the title Check JNI calls for pending exceptions and no-op Check internal JNI calls for pending exceptions and no-op Jan 22, 2021
@fractalwrench fractalwrench marked this pull request as ready for review January 22, 2021 16:36
@bugsnagbot
Copy link
Collaborator

Android notifier sizes

Format Size impact of Bugsnag (kB) Size impact of Bugsnag when Minified (kB)
APK 1461.56 1376.29
arm64_v8a 377.51 291.5
armeabi 357.03 271.01
armeabi_v7a 340.65 250.54
x86 418.45 328.34
x86_64 397.98 311.97

Generated by 🚫 Danger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants