Skip to content

Always check Java pointers for null before deref #737

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

Merged
merged 3 commits into from
Apr 4, 2017

Conversation

smowton
Copy link
Contributor

@smowton smowton commented Mar 30, 2017

This also improves goto-check's resolution for finding symbol modes by finding the function in the symbol table and parameterising from above.

I wrote this because the test generator was producing strange results due to missing null checks. Before the test generator became a separate module it twiddled the command-line options to add pointer-check; however I think doing it this way is better, as it is never semantically sane to analyse Java-but-null-pointers-are-wild.

goto_check.goto_check(it->second);
const symbolt *sym;
irep_idt mode;
if(!ns.lookup(it->first, sym))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't it be an invariant that the symbol exists? I think it should be safe to use

irep_idt mode=ns.lookup(it->first).mode;

?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unsure, hence being careful.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd go all-in and wait for bug reports (or failing regression tests).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok will change this shortly

{
if(!enable_pointer_check)
if(mode!=ID_java && !enable_pointer_check)
Copy link
Collaborator

Choose a reason for hiding this comment

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

So we would always be doing this for mode==ID_java, whether it's enabled or not!?

Copy link
Contributor Author

@smowton smowton Mar 30, 2017

Choose a reason for hiding this comment

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

Yes. Check-deref'd-pointer-not-null is mandatory for Java. Explicit enable is only then meaningful for C/C++/etc.

Copy link
Collaborator

Choose a reason for hiding this comment

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

But we should then be generating an exception, not an assertion, shouldn't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally yes. However this matches current Java front-end behaviour for out of bounds array access and similar. I think we should support this simple model and then perhaps in the future add support for a "full fidelity" model where we support catching NPE, AOOBE and so on.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok; I'd thus suggestion that the help output for --pointer-check be amended to say "C/C++ only".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This also improves goto-check's resolution for finding symbol modes
by finding the function in the symbol table and parameterising from
above.
smowton added 2 commits March 31, 2017 13:27
They required "1 of N successful" reports, where N is changed by the
addition of new assertions.
This is effectively always enabled for Java programs now. For others
this is still optional.
Copy link
Collaborator

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

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

Thanks for all the updates!

@kroening kroening merged commit f55e413 into diffblue:master Apr 4, 2017
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.

3 participants