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

MayPointTo is not subset of ReachableFrom #1175

Open
sim642 opened this issue Sep 19, 2023 · 1 comment
Open

MayPointTo is not subset of ReachableFrom #1175

sim642 opened this issue Sep 19, 2023 · 1 comment

Comments

@sim642
Copy link
Member

sim642 commented Sep 19, 2023

In #1174 I made pthread_join invalidate its second argument with w instead of the default r_deep; w_deep; s_deep. Surprisingly, this caused test failures due to additional unknown pointer accesses if the pthread_join argument happens to be NULL.
This means that the MayPointTo for w accesses returns more addresses than ReachableFrom for w_deep, although I've always thought the former should be a subset of the latter as the latter is a recursive closure of the former. But apparently not?!

First, ReachableFrom for some reason excludes unknown pointers:

analyzer/src/analyses/base.ml

Lines 1288 to 1290 in 851c6b3

let a' = AD.remove Addr.UnknownPtr a in (* run reachable_vars without unknown just to be safe: TODO why? *)
let addrs = reachable_vars (Analyses.ask_of_ctx ctx) [a'] ctx.global ctx.local in
List.fold_left (AD.join) (AD.empty ()) addrs

Second, reachable_from_value for some reason excludes NULL pointers:
| Address adrs -> AD.remove Addr.NullPtr adrs

This explains why ReachableFrom NULL doesn't yield any accesses, but it doesn't explain why those exclusions are there in the first place.

In a4fb621 reachable_from_value was not just moved around but also the AD.remove Addr.NullPtr was introduced without explanation.

@sim642 sim642 added the bug label Sep 19, 2023
@sim642
Copy link
Member Author

sim642 commented Sep 19, 2023

There's also a third difference which affects NULL constants in particular because they evaluate to Int variants in base.
MayPointTo returns the top pointer for them:

| _ -> Queries.Result.top q

But ReachableFrom returns an empty points-to set:
| _ -> AD.empty ()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant