Skip to content

Commit bfebad8

Browse files
authored
Merge branch 'main' into dependabot/bazel/bazel_worker_api-0.0.10
2 parents 0c7314a + 8e19b05 commit bfebad8

File tree

51 files changed

+2125
-2552
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+2125
-2552
lines changed

config/identical-files.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,6 @@
172172
"cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/internal/reachability/PrintDominance.qll",
173173
"cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/internal/reachability/PrintDominance.qll"
174174
],
175-
"C# ControlFlowReachability": [
176-
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/ControlFlowReachability.qll",
177-
"csharp/ql/lib/semmle/code/csharp/dataflow/internal/rangeanalysis/ControlFlowReachability.qll"
178-
],
179175
"C++ ExternalAPIs": [
180176
"cpp/ql/src/Security/CWE/CWE-020/ExternalAPIs.qll",
181177
"cpp/ql/src/Security/CWE/CWE-020/ir/ExternalAPIs.qll"

cpp/ql/lib/semmle/code/cpp/Function.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,12 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
524524
not exists(NewOrNewArrayExpr new | e = new.getAllocatorCall().getArgument(0))
525525
)
526526
}
527+
528+
/**
529+
* Holds if this function has an ambiguous return type, meaning that zero or multiple return
530+
* types for this function are present in the database (this can occur in `build-mode: none`).
531+
*/
532+
predicate hasAmbiguousReturnType() { count(this.getType()) != 1 }
527533
}
528534

529535
pragma[noinline]

cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ where
218218
// only report if we cannot prove that the result of the
219219
// multiplication will be less (resp. greater) than the
220220
// maximum (resp. minimum) number we can compute.
221-
overflows(me, t1)
221+
overflows(me, t1) and
222+
// exclude cases where the expression type may not have been extracted accurately
223+
not me.getParent().(Call).getTarget().hasAmbiguousReturnType()
222224
select me,
223225
"Multiplication result may overflow '" + me.getType().toString() + "' before it is converted to '"
224226
+ me.getFullyConverted().getType().toString() + "'."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed an issue with the "Multiplication result converted to larger type" (`cpp/integer-multiplication-cast-to-long`) query causing false positive results in `build-mode: none` databases.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// semmle-extractor-options: --expect_errors
2+
3+
void test_float_double1(float f, double d) {
4+
float r1 = f * f; // GOOD
5+
float r2 = f * d; // GOOD
6+
double r3 = f * f; // BAD
7+
double r4 = f * d; // GOOD
8+
9+
float f1 = fabsf(f * f); // GOOD
10+
float f2 = fabsf(f * d); // GOOD
11+
double f3 = fabs(f * f); // BAD [NOT DETECTED]
12+
double f4 = fabs(f * d); // GOOD
13+
}
14+
15+
double fabs(double f);
16+
float fabsf(float f);
17+
18+
void test_float_double2(float f, double d) {
19+
float r1 = f * f; // GOOD
20+
float r2 = f * d; // GOOD
21+
double r3 = f * f; // BAD
22+
double r4 = f * d; // GOOD
23+
24+
float f1 = fabsf(f * f); // GOOD
25+
float f2 = fabsf(f * d); // GOOD
26+
double f3 = fabs(f * f); // BAD [NOT DETECTED]
27+
double f4 = fabs(f * d); // GOOD
28+
}

cpp/ql/test/query-tests/Likely Bugs/Arithmetic/IntMultToLong/IntMultToLong.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
| Buildless.c:6:17:6:21 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
2+
| Buildless.c:21:17:21:21 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |
13
| IntMultToLong.c:4:10:4:14 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
24
| IntMultToLong.c:7:16:7:20 | ... * ... | Multiplication result may overflow 'int' before it is converted to 'long long'. |
35
| IntMultToLong.c:18:19:18:23 | ... * ... | Multiplication result may overflow 'float' before it is converted to 'double'. |

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,7 @@ private module Input implements InputSig<Location, CsharpDataFlow> {
3535
or
3636
n.asExpr().(ObjectCreation).hasInitializer()
3737
or
38-
exists(
39-
n.(PostUpdateNode).getPreUpdateNode().asExprAtNode(LocalFlow::getPostUpdateReverseStep(_))
40-
)
38+
n.(PostUpdateNode).getPreUpdateNode().asExpr() = LocalFlow::getPostUpdateReverseStep(_)
4139
}
4240

4341
predicate argHasPostUpdateExclude(ArgumentNode n) {

csharp/ql/lib/semmle/code/csharp/dataflow/internal/ControlFlowReachability.qll

Lines changed: 0 additions & 246 deletions
This file was deleted.

0 commit comments

Comments
 (0)