-
Notifications
You must be signed in to change notification settings - Fork 1.1k
get_extern_state potential NULL dereference #12037
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
Comments
The
I may be wrong, but I believe that the current code will never fail with In the short term, we should thus introduce NULL-checks on calls to In the medium term, it would be nice to have two different functions for (1) and (2), an initialization function that fails on OOM for (1), and an re-access function for (2) that assumes (and possibly asserts) that the initialization function has already been called. |
cc @xavierleroy : does that sound right to you? |
For @edwintorok (and: thanks!): the reason why we don't want to fail with exceptions from within the extern logic is that the extern logic is not reentrant for performance reasons, there is explicit state-cleanup logic to call before we return to OCaml code (which could catch the exception and then try to serialize things again). This being said, we are talking here about the specific case where we failed to allocate the extern state, so maybe there is nothing to cleanup and we could fail with an exception at this point. (Before the 'extern state' was a bunch of global variables, now it is in domain-local state for obvious multicore-safety reasons.) |
@gasche's explanation sounds about right. It might be clearer to go even further and have two functions: 1-
2- |
I think I'll give it a shot! |
@gasche I've drafted a PR at #12171, but I have a few questions before I undraft it and fill it out for review. First and foremost, I can't find what guarantees the aforementioned invariant that
This is my first time working on the OCaml compiler runtime (or any compiler or runtime for that matter), so maybe I'm missing something obvious, but I can't find why Secondly, regarding tests, I re-ran the |
@askvortsov1 that's a good question. The My current understanding is as follows:
Summary:
|
This has been solved by merging #12171. Thanks everyone! |
Found by GCC '-fanalyzer':
output.txt
The code at
ocaml/runtime/extern.c
Lines 127 to 131 in d71ea3d
However in 'extern.c' the callers do not check for NULL and would crash on a NULL pointer dereference as pointed out by GCC above. There was probably a reason why the code wanted to return NULL here (is it not safe to raise out of memory exception?), but I cannot find the reason in git history (I got as far as 868265f). It would seem to me that the code should either raise out of memory here or handle the NULL return value in some way (e.g. by returning early with an error).
The text was updated successfully, but these errors were encountered: