Repository navigation
[pulse] report null arguments dereferenced after a comparison to null - #2169
Open
VladimirMakaev wants to merge 1 commit into
Open
VladimirMakaev wants to merge 1 commit into
VladimirMakaev wants to merge 1 commit into
Conversation
VladimirMakaev
force-pushed
the
pulse-compared-to-null-precondition
branch
4 times, most recently
from
October 5, 2026 09:04
8fbc190 to
10cc4a7
Compare
VladimirMakaev
marked this pull request as ready for review
October 5, 2026 15:27
VladimirMakaev
added a commit
to VladimirMakaev/infer
that referenced
this pull request
Oct 5, 2026
Since e1f88f2 (August 2024), callers passing null to a function that checks `p == NULL` and then dereferences `p` anyway get no NULLPTR_DEREFERENCE: the access fails on `ComparedToNullInThisProcedure` before `MustBeValid` is abduced. That commit deleted the caller tests showing this (`call_test_after_dereference_bad`, `no_early_return_no_zero_manifest_bad`). Java is hit hardest: bytecode spells every null check as `== null`. Upstream-PR: meta#2169 PR-Head: 10cc4a7 PR-Base: 9cc2641
VladimirMakaev
force-pushed
the
pulse-compared-to-null-precondition
branch
from
October 6, 2026 15:41
10cc4a7 to
d3aa036
Compare
Contributor
|
@jvillard is best placed to look at this one. |
This was referenced Oct 7, 2026
VladimirMakaev
force-pushed
the
pulse-compared-to-null-precondition
branch
from
October 7, 2026 15:55
d3aa036 to
931539b
Compare
Contributor
|
I think it makes sense to also report these errors as null pointer dereference if we do see functions that do this being called with |
Since e1f88f2 (August 2024), callers passing null to a function that checks `p == NULL` and then dereferences `p` anyway get no NULLPTR_DEREFERENCE: the access fails on `ComparedToNullInThisProcedure` before `MustBeValid` is abduced. That commit deleted the caller tests showing this (`call_test_after_dereference_bad`, `no_early_return_no_zero_manifest_bad`). Java is hit hardest: bytecode spells every null check as `== null`. ```c #include <stddef.h> struct node { int data; }; void log_message(const char* msg); int get_data(struct node* n) { if (n == NULL) { log_message("null node"); } return n->data; } int caller(void) { return get_data(NULL); // Infer missed: null dereference } ``` When an access fails on `ComparedToNullInThisProcedure` or `ConstantDereference` and the pointer's history shows it was read from a pre-condition cell holding it, abduce `MustBeValid` as successful accesses do. All null values of a path share one canonical value: the check keeps a null local, or the result of an unknown call given a null argument, from blaming the caller. Limitations: with the opt-in COMPARED_TO_NULL_AND_DEREFERENCED, one bug yields two reports (callee and caller). ## Test plan New `c/pulse/compared_to_null.c`, with callers not blamed for a null local or unknown-call result (direct or through a wrapper), and an `FP_` test for an unknown noreturn function in the null branch. Callers restored in `cpp/pulse/nullptr.cpp` and `objc/pulse/null_deref/return_npe_test.m`, added in `java/pulse/NullPointerExceptions.java`. All suites pass; the ObjC line comes from that file alone.
VladimirMakaev
force-pushed
the
pulse-compared-to-null-precondition
branch
from
November 17, 2026 16:32
931539b to
0794fbd
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since e1f88f2 (August 2024), callers passing null to a function that checks
p == NULLandthen dereferences
panyway get no NULLPTR_DEREFERENCE: the access fails onComparedToNullInThisProcedurebeforeMustBeValidis abduced. That commit deleted the callertests showing this (
call_test_after_dereference_bad,no_early_return_no_zero_manifest_bad).Java is hit hardest: bytecode spells every null check as
== null.When an access fails on
ComparedToNullInThisProcedureorConstantDereferenceand thepointer's history shows it was read from a pre-condition cell holding it, abduce
MustBeValidassuccessful accesses do. All null values of a path share one canonical value: the check keeps a
null local, or the result of an unknown call given a null argument, from blaming the caller.
Limitations: with the opt-in COMPARED_TO_NULL_AND_DEREFERENCED, one bug yields two reports (callee
and caller).
Test plan
New
c/pulse/compared_to_null.c, with callers not blamed for a null local or unknown-call result(direct or through a wrapper), and an
FP_test for an unknown noreturn function in the nullbranch. Callers restored in
cpp/pulse/nullptr.cppandobjc/pulse/null_deref/return_npe_test.m,added in
java/pulse/NullPointerExceptions.java. All suites pass; the ObjC line comes from thatfile alone.