Skip to content

Commit 375dd02

Browse files
Merge pull request #11 from anaarmas/reorder
reorder query lines in libssh2_eating_error_codes
2 parents bc151f9 + 840a0fa commit 375dd02

4 files changed

Lines changed: 14 additions & 17 deletions

File tree

ql_demos/cpp/libssh2_eating_error_codes/01_error_codes_call.ql

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import cpp
66

77
// Extend the previous query to also find calls to functions that sometimes
88
// return a negative integer constant.
9-
from Function f, FunctionCall call, ReturnStmt ret
9+
from FunctionCall call, ReturnStmt ret
1010
where
11-
call.getTarget() = f and
12-
ret.getEnclosingFunction() = f and
13-
ret.getExpr().getValue().toInt() < 0
11+
ret.getExpr().getValue().toInt() < 0 and
12+
call.getTarget() = ret.getEnclosingFunction()
1413
select ret, call

ql_demos/cpp/libssh2_eating_error_codes/02_eating_error_codes.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ import cpp
66

77
// Look for calls that are cast to unsigned, which means that the error
88
// code might be accidentally ignored.
9-
from Function f, FunctionCall call, ReturnStmt ret
9+
from FunctionCall call, ReturnStmt ret
1010
where
11-
call.getTarget() = f and
12-
ret.getEnclosingFunction() = f and
1311
ret.getExpr().getValue().toInt() < 0 and
12+
call.getTarget() = ret.getEnclosingFunction() and
1413
call.getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned()
1514
select call, ret

ql_demos/cpp/libssh2_eating_error_codes/03_eating_error_codes_localflow.ql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import semmle.code.cpp.dataflow.DataFlow
1414
//
1515
// In this query, we add local dataflow so that we can also handle such
1616
// cases.
17-
from Function f, FunctionCall call, ReturnStmt ret, DataFlow::Node source, DataFlow::Node sink
18-
where call.getTarget() = f
19-
and ret.getEnclosingFunction() = f
20-
and ret.getExpr().getValue().toInt() < 0
21-
and source.asExpr() = call
22-
and DataFlow::localFlow(source, sink)
23-
and sink.asExpr().getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned()
17+
from FunctionCall call, ReturnStmt ret, DataFlow::Node source, DataFlow::Node sink
18+
where
19+
ret.getExpr().getValue().toInt() < 0 and
20+
call.getTarget() = ret.getEnclosingFunction() and
21+
source.asExpr() = call and
22+
DataFlow::localFlow(source, sink) and
23+
sink.asExpr().getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned()
2424
select source, sink

ql_demos/cpp/libssh2_eating_error_codes/04_eating_error_codes_localflow_rangeanalysis.ql

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@ import semmle.code.cpp.rangeanalysis.SimpleRangeAnalysis
1818
// int r = f();
1919
// if (r < 0) return -1;
2020
// unsigned int x = r;
21-
from Function f, FunctionCall call, ReturnStmt ret, DataFlow::Node source, DataFlow::Node sink
21+
from FunctionCall call, ReturnStmt ret, DataFlow::Node source, DataFlow::Node sink
2222
where
23-
call.getTarget() = f and
24-
ret.getEnclosingFunction() = f and
2523
ret.getExpr().getValue().toInt() < 0 and
24+
call.getTarget() = ret.getEnclosingFunction() and
2625
source.asExpr() = call and
2726
DataFlow::localFlow(source, sink) and
2827
sink.asExpr().getFullyConverted().getType().getUnderlyingType().(IntegralType).isUnsigned() and

0 commit comments

Comments
 (0)