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

Map null callback objects to null pointers #77

Merged
merged 1 commit into from
Sep 21, 2016

Conversation

pepijnve
Copy link
Contributor

When passing null as value for a callback parameter to a native function a native closure gets created which wraps a null callable. A non-null pointer then gets passed to the native code. When the java closure gets invoke this triggers a null pointer exception at https://github.com/jnr/jnr-ffi/blob/master/src/main/java/jnr/ffi/provider/jffi/NativeClosureProxy.java#L57
Additionally this can end up changing the semantics of the function call since a non-null parameter is passed where null was intended. This is what's happening in #61.
This PR adds a null check in the 'to native' conversion of delegate types that returns a null Pointer instance.

@headius
Copy link
Member

headius commented Sep 21, 2016

Nice find. You're right, I can name several common C functions that change their behavior if passed a non-null callback.

@headius headius added this to the 2.0.10 milestone Sep 21, 2016
@headius headius merged commit 0601182 into jnr:master Sep 21, 2016
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.

None yet

2 participants