-
Notifications
You must be signed in to change notification settings - Fork 542
8315074: Possible null pointer access in native glass #1223
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
Conversation
|
👋 Welcome back jdv! A progress list of the required criteria for merging this PR into |
Webrevs
|
|
/reviewers 2 |
|
@kevinrushforth |
| gdk_threads_add_idle_full(G_PRIORITY_HIGH_IDLE + 30, call_runnable, context, NULL); | ||
| // we release this context in call_runnable | ||
| } else { | ||
| fprintf(stderr, "malloc failed in GtkApplication__1submitForLaterInvocatio\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the malloc above failed, I would think there might be very serious errors hence maybe this should be propagated to the Java layer, or throw the relevant memory exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good question. Since this is a void method (thus there is no way to signal an error), the ideal thing would be to throw an OutOfMemoryError before returning, but if a malloc of this small size were to fail, we might not even be able to create the OOME. Not sure it's worth it in this case. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a crash due to a null pointer is not desired, as that gives very little info to the developer.
If that malloc fails, it is an indication that there is a major chance that we are in serious trouble. In that case, simply printing something (which could fail as well if there is that limited memory) and not informing the caller will most likely just postpone the crash.
Unless we can free some memory immediately, I think it might be good if we can try to exit gracefully. The drawback of this is that if there is a trivial way to free memory and the native code was just about to invoke free() on a big memory chunk, we are exiting without a good reason (although I think this scenario is unlikely).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to avoid the crash entirely. If we actually hit this case, it is very likely that other calls will also run out of memory. Returning to Java as quickly as possible will let any pending OOME be thrown. A library should not exit, so really we have two choices here:
- Throw OOM and then return
- Just return
While option 1 might be the better choice, it would be a more intrusive fix. Most of the native code just returns to Java, although we do have a few places where we throw. OOME. It might be better to keep this fix simple (and more in line with what other functions in glass do), and address this with a follow-up issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against that, especially since it's in line with what we do in other functions in glass.
However, I am worried about the consequences. In case we just return, the caller has no idea that there is a major problem. A Runnable is supplied to e.g. _invokeAndWait, but it will never get executed while the caller (and the application logic) assumes it is scheduled. This can have serious consequences and unexpected behavior in the application.
But maybe I'm missing something and it is less severe than I'm picturing it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see what you are saying, but worth noting in this specific case is that if the malloc of RunnableContext (a 12-byte struct) fails, we're not going to be able to allocate an OOME anyway.
My preference would be to leave this fix as is, and file a follow-up issue to change the return type of GtkApplication::submitForLaterInvocation (and the equivalent methods in the other glass pipelines) to boolean so we can return an error code and throw an exception (which would very likely provoke an OOME, but in any case would never silently fail).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed the following two follow-on umbrella tasks:
JDK-8316020: ☂ Check memory allocation for null return value (P3)
JDK-8316022: ☂ Memory allocation failure should throw OOME (P4)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first of these already has two linked blocking bugs (this one, and the previously integrated JDK-8313900 / PR #1204)
modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp
Outdated
Show resolved
Hide resolved
johanvos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ios changes are fine.
In general, I'm still worried about the consequences of silently ignoring a fatal error (although there is a printf, but that doesn't propagate to the caller), but this can indeed be fixed in a follow-up issue.
kevinrushforth
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
|
@johanvos Can you re-review? |
|
@jayathirthrao This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be: You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 13 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@johanvos, @kevinrushforth) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
/integrate |
|
@jayathirthrao |
|
/sponsor |
|
Going to push as commit f7b21e5.
Your commit was automatically rebased without conflicts. |
|
@kevinrushforth @jayathirthrao Pushed as commit f7b21e5. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
At multiple places in native glass code we don't have appropriate NULL checks which might result in null pointer access.
Added appropriate checks and all test run is green.
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jfx.git pull/1223/head:pull/1223$ git checkout pull/1223Update a local copy of the PR:
$ git checkout pull/1223$ git pull https://git.openjdk.org/jfx.git pull/1223/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 1223View PR using the GUI difftool:
$ git pr show -t 1223Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jfx/pull/1223.diff
Webrev
Link to Webrev Comment