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

Avoid trying to throw an exception if one is pending #44

Merged
merged 1 commit into from
Jan 13, 2017

Conversation

kruton
Copy link
Contributor

@kruton kruton commented Jan 13, 2017

A call to to_SSL or fromContextObject will throw a NullPointerException
if the SSL object reference is null. Avoid trying to throw our own
exception if that's the case. Also rearrange calls that might potentially
throw to be serially checked.

A call to to_SSL will throw a NullPointerException if the SSL object
reference is null. Avoid trying to throw our own exception if that's the
case. Also rearrange calls that might potentially throw to be serially
checked.
if (x509 == nullptr) {
Errors::jniThrowNullPointerException(env, "x509 == null");
JNI_TRACE("X509_verify(%p, %p) => x509 == null", x509, pkey);
if (pkey == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I totally follow why you've switched the order of these checks ... can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fromContextObject call gets a nullptr for pkey it will push a NullPointerException and at that point the JNI exception will be pending. If x509 is also nullptr the previous line 3902 will try to throw another exception when one is already pending which is a JNI error.

Normally this won't be a problem on production builds, but it aborts in debug Android builds or when checkJni is enabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see ... sgtm. Thanks for the explanation.

@kruton kruton merged commit 5fe3c56 into google:master Jan 13, 2017
@kruton kruton deleted the pending-exception-avoidance branch January 13, 2017 03:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants