Skip to content

Commit 0576474

Browse files
committed
UnguardedNullReturnDereference: Honor _Analysis_assume_
_Analysis_assume_(Expr) tells the analyzer to treat Expr as true. MSVC compiles __assume() into an empty statement with no AST node, but the EmptyStmt remains in the control flow graph at the macro invocation site. The query was not recognizing this as a null guard: NBL *Nbl = DequeueNbl(&Queue); _Analysis_assume_(Nbl); NET_BUFFER_LIST_STATUS(Nbl) = NDIS_STATUS_FAILURE; // flagged Match the EmptyStmt at the _Analysis_assume_ location as a barrier by correlating it with the macro invocation that names the guarded variable. Also match AssumeExpr directly for compilers that emit it. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 6820d66 commit 0576474

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/microsoft/Likely Bugs/UnguardedNullReturnDereference.ql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,19 @@ class UnguardedNullReturnDereferenceReachability extends StackVariableReachabili
139139
"_checked_pointer_impl", "_fail_on_unexpected_null_pointer", "_fail_on_memory_op"]
140140
and c.getAnArgument().getAChild*() = v.getAnAccess()
141141
and c = node)
142+
or
143+
exists(AssumeExpr ae |
144+
ae = node and
145+
ae.getOperand().getAChild*() = v.getAnAccess()
146+
)
147+
or
148+
exists(MacroInvocation mi |
149+
mi.getMacroName() = "_Analysis_assume_" and
150+
mi.getUnexpandedArgument(0) = v.getName() and
151+
node.getLocation().getFile() = mi.getLocation().getFile() and
152+
node.getLocation().getStartLine() = mi.getLocation().getStartLine() and
153+
node instanceof EmptyStmt
154+
)
142155
}
143156
}
144157

0 commit comments

Comments
 (0)