Skip to content

Commit f1d7fde

Browse files
committed
C++: Use localExprFlow in existing queries
This shortens the queries a bit and ensures test coverage of the new predicate.
1 parent 6331173 commit f1d7fde

File tree

5 files changed

+7
-9
lines changed

5 files changed

+7
-9
lines changed

cpp/ql/src/Critical/NewDelete.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ predicate allocExprOrIndirect(Expr alloc, string kind) {
4747
or
4848
exists(Expr e |
4949
allocExprOrIndirect(e, kind) and
50-
DataFlow::localFlow(DataFlow::exprNode(e), DataFlow::exprNode(rtn.getExpr()))
50+
DataFlow::localExprFlow(e, rtn.getExpr())
5151
)
5252
)
5353
)

cpp/ql/src/Critical/OverflowStatic.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class CallWithBufferSize extends FunctionCall {
9595

9696
int statedSizeValue() {
9797
exists(Expr statedSizeSrc |
98-
DataFlow::localFlow(DataFlow::exprNode(statedSizeSrc), DataFlow::exprNode(statedSizeExpr())) and
98+
DataFlow::localExprFlow(statedSizeSrc, statedSizeExpr()) and
9999
result = statedSizeSrc.getValue().toInt()
100100
)
101101
}

cpp/ql/src/Likely Bugs/Conversion/LossyFunctionResultCast.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ predicate whiteListWrapped(FunctionCall fc) {
5555
whitelistPow(fc) or
5656
exists(Expr e, ReturnStmt rs |
5757
whiteListWrapped(e) and
58-
DataFlow::localFlow(DataFlow::exprNode(e), DataFlow::exprNode(rs.getExpr())) and
58+
DataFlow::localExprFlow(e, rs.getExpr()) and
5959
fc.getTarget() = rs.getEnclosingFunction()
6060
)
6161
}

cpp/ql/src/Likely Bugs/Likely Typos/UsingStrcpyAsBoolean.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ predicate isBoolean(Expr e1) {
2323
}
2424

2525
predicate isStringCopyCastedAsBoolean(FunctionCall func, Expr expr1, string msg) {
26-
DataFlow::localFlow(DataFlow::exprNode(func), DataFlow::exprNode(expr1)) and
26+
DataFlow::localExprFlow(func, expr1) and
2727
isBoolean(expr1.getConversion*()) and
2828
func.getTarget() instanceof StrcpyFunction and
2929
msg = "Return value of " + func.getTarget().getName() + " used as a Boolean."

cpp/ql/src/Security/CWE/CWE-131/NoSpaceForZeroTerminator.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,10 @@ class MallocCall extends FunctionCall
3636

3737
predicate terminationProblem(MallocCall malloc, string msg) {
3838
malloc.getAllocatedSize() instanceof StrlenCall and
39-
not exists(DataFlow::Node def, DataFlow::Node use, FunctionCall fc, MemcpyFunction memcpy, int ix |
40-
DataFlow::localFlow(def, use) and
41-
def.asExpr() = malloc and
39+
not exists(FunctionCall fc, MemcpyFunction memcpy, int ix |
40+
DataFlow::localExprFlow(malloc, fc.getArgument(ix)) and
4241
fc.getTarget() = memcpy and
43-
memcpy.hasArrayOutput(ix) and
44-
use.asExpr() = fc.getArgument(ix)
42+
memcpy.hasArrayOutput(ix)
4543
) and
4644
msg = "This allocation does not include space to null-terminate the string."
4745
}

0 commit comments

Comments
 (0)