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

Fix ocaml-ssl segfault with multicore #81

Conversation

anmonteiro
Copy link
Collaborator

fixes #76

  • stops returning a C function as an OCaml value.
  • This fix should be backwards compatible, as we keep the exact same interface
  • it wasn't possible to override the verification callback before (just turning it off or on), so this shouldn't break anyone

@anmonteiro anmonteiro changed the title fix ssl segfault Fix ocaml-ssl segfault with multicore Feb 18, 2022
Copy link
Contributor

@dra27 dra27 left a comment

Choose a reason for hiding this comment

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

The problem is the out-of-heap pointer - you could instead choose to box it (cf. Interfacing with C in the manual roughly with the two suggestions. The result would be no change on the OCaml side at all.

@@ -559,11 +559,6 @@ CAMLprim value ocaml_ssl_digest(value vevp, value vcert)
CAMLreturn(vdigest);
}

CAMLprim value ocaml_ssl_get_client_verify_callback_ptr(value unit)
{
return (value)client_verify_callback;
Copy link
Contributor

Choose a reason for hiding this comment

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

  value v = caml_alloc_small(1, Abstract_tag);
  *((int(*) (int, X509_STORE_CTX*)) Data_abstract_val(v)) = client_verify_callback;
  return v;

@@ -610,7 +605,7 @@ CAMLprim value ocaml_ssl_ctx_set_verify(value context, value vmode, value vcallb
}

if (Is_block(vcallback))
callback = (int(*) (int, X509_STORE_CTX*))Field(vcallback, 0);
callback = (int(*) (int, X509_STORE_CTX*)) client_verify_callback;
Copy link
Contributor

Choose a reason for hiding this comment

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

and then:

Suggested change
callback = (int(*) (int, X509_STORE_CTX*)) client_verify_callback;
callback = *(int(*) (int, X509_STORE_CTX*)) Data_abstract_val(Field(vcallback, 0));

@anmonteiro
Copy link
Collaborator Author

anmonteiro commented Jul 6, 2022

Closing this in favor of #83

@anmonteiro anmonteiro closed this Jul 6, 2022
@anmonteiro anmonteiro deleted the anmonteiro/fix-multicore-segfault branch August 14, 2022 17:32
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.

Linking with Ssl causes segfault on multicore OCaml
2 participants