Skip to content

Commit 7d774f1

Browse files
authored
Merge branch 'main' into LoadClassNoSignatureCheck
2 parents 532f6a5 + c14d404 commit 7d774f1

File tree

157 files changed

+14599
-810
lines changed

Some content is hidden

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

157 files changed

+14599
-810
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/SemanticSSA.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ class SemSsaExplicitUpdate extends SemSsaVariable {
2222

2323
SemSsaExplicitUpdate() { Specific::explicitUpdate(this, sourceExpr) }
2424

25-
final SemExpr getSourceExpr() { result = sourceExpr }
26-
2725
final SemExpr getDefiningExpr() { result = sourceExpr }
2826
}
2927

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/ConstantAnalysis.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private predicate constantIntegerExpr(SemExpr e, int val) {
1414
// Copy of another constant
1515
exists(SemSsaExplicitUpdate v, SemExpr src |
1616
e = v.getAUse() and
17-
src = v.getSourceExpr() and
17+
src = v.getDefiningExpr() and
1818
constantIntegerExpr(src, val)
1919
)
2020
or

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisConstantSpecific.qll

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,7 @@ module CppLangImplConstant implements LangSig<Sem, FloatDelta> {
2222
predicate hasConstantBound(SemExpr e, float bound, boolean upper) { none() }
2323

2424
/**
25-
* Holds if `e >= bound + delta` (if `upper = false`) or `e <= bound + delta` (if `upper = true`).
25+
* Holds if `e2 >= e1 + delta` (if `upper = false`) or `e2 <= e1 + delta` (if `upper = true`).
2626
*/
27-
predicate hasBound(SemExpr e, SemExpr bound, float delta, boolean upper) { none() }
28-
29-
/**
30-
* Holds if the value of `dest` is known to be `src + delta`.
31-
*/
32-
predicate additionalValueFlowStep(SemExpr dest, SemExpr src, float delta) { none() }
33-
34-
/**
35-
* Gets the type that range analysis should use to track the result of the specified expression,
36-
* if a type other than the original type of the expression is to be used.
37-
*
38-
* This predicate is commonly used in languages that support immutable "boxed" types that are
39-
* actually references but whose values can be tracked as the type contained in the box.
40-
*/
41-
SemType getAlternateType(SemExpr e) { none() }
42-
43-
/**
44-
* Gets the type that range analysis should use to track the result of the specified source
45-
* variable, if a type other than the original type of the expression is to be used.
46-
*
47-
* This predicate is commonly used in languages that support immutable "boxed" types that are
48-
* actually references but whose values can be tracked as the type contained in the box.
49-
*/
50-
SemType getAlternateTypeForSsaVariable(SemSsaVariable var) { none() }
27+
predicate additionalBoundFlowStep(SemExpr e2, SemExpr e1, float delta, boolean upper) { none() }
5128
}

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisImpl.qll

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
private import RangeAnalysisConstantSpecific
22
private import RangeAnalysisRelativeSpecific
33
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
4-
private import RangeUtils
54
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticExpr
65
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticCFG
76
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticGuard
@@ -88,20 +87,26 @@ module Sem implements Semantic {
8887

8988
class AddressType = SemAddressType;
9089

90+
SemType getExprType(SemExpr e) { result = e.getSemType() }
91+
92+
SemType getSsaType(SemSsaVariable var) { result = var.getType() }
93+
9194
class SsaVariable = SemSsaVariable;
9295

9396
class SsaPhiNode = SemSsaPhiNode;
9497

9598
class SsaExplicitUpdate = SemSsaExplicitUpdate;
9699

100+
predicate additionalValueFlowStep(SemExpr dest, SemExpr src, int delta) { none() }
101+
97102
predicate conversionCannotOverflow(Type fromType, Type toType) {
98103
SemanticType::conversionCannotOverflow(fromType, toType)
99104
}
100105
}
101106

102107
module SignAnalysis implements SignAnalysisSig<Sem> {
103108
private import SignAnalysisCommon as SA
104-
import SA::SignAnalysis<FloatDelta, Util>
109+
import SA::SignAnalysis<FloatDelta>
105110
}
106111

107112
module ConstantBounds implements BoundSig<SemLocation, Sem, FloatDelta> {
@@ -164,18 +169,16 @@ private module ModulusAnalysisInstantiated implements ModulusAnalysisSig<Sem> {
164169
class ModBound = AllBounds::SemBound;
165170

166171
private import codeql.rangeanalysis.ModulusAnalysis as MA
167-
import MA::ModulusAnalysis<SemLocation, Sem, FloatDelta, AllBounds, Util>
172+
import MA::ModulusAnalysis<SemLocation, Sem, FloatDelta, AllBounds>
168173
}
169174

170-
module Util = RangeUtil<FloatDelta, CppLangImplConstant>;
171-
172175
module ConstantStage =
173176
RangeStage<SemLocation, Sem, FloatDelta, ConstantBounds, FloatOverflow, CppLangImplConstant,
174-
SignAnalysis, ModulusAnalysisInstantiated, Util>;
177+
SignAnalysis, ModulusAnalysisInstantiated>;
175178

176179
module RelativeStage =
177180
RangeStage<SemLocation, Sem, FloatDelta, RelativeBounds, FloatOverflow, CppLangImplRelative,
178-
SignAnalysis, ModulusAnalysisInstantiated, Util>;
181+
SignAnalysis, ModulusAnalysisInstantiated>;
179182

180183
private newtype TSemReason =
181184
TSemNoReason() or

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeAnalysisRelativeSpecific.qll

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,7 @@ module CppLangImplRelative implements LangSig<Sem, FloatDelta> {
5454
predicate hasConstantBound(SemExpr e, float bound, boolean upper) { none() }
5555

5656
/**
57-
* Holds if `e >= bound + delta` (if `upper = false`) or `e <= bound + delta` (if `upper = true`).
57+
* Holds if `e2 >= e1 + delta` (if `upper = false`) or `e2 <= e1 + delta` (if `upper = true`).
5858
*/
59-
predicate hasBound(SemExpr e, SemExpr bound, float delta, boolean upper) { none() }
60-
61-
/**
62-
* Holds if the value of `dest` is known to be `src + delta`.
63-
*/
64-
predicate additionalValueFlowStep(SemExpr dest, SemExpr src, float delta) { none() }
65-
66-
/**
67-
* Gets the type that range analysis should use to track the result of the specified expression,
68-
* if a type other than the original type of the expression is to be used.
69-
*
70-
* This predicate is commonly used in languages that support immutable "boxed" types that are
71-
* actually references but whose values can be tracked as the type contained in the box.
72-
*/
73-
SemType getAlternateType(SemExpr e) { none() }
74-
75-
/**
76-
* Gets the type that range analysis should use to track the result of the specified source
77-
* variable, if a type other than the original type of the expression is to be used.
78-
*
79-
* This predicate is commonly used in languages that support immutable "boxed" types that are
80-
* actually references but whose values can be tracked as the type contained in the box.
81-
*/
82-
SemType getAlternateTypeForSsaVariable(SemSsaVariable var) { none() }
59+
predicate additionalBoundFlowStep(SemExpr e2, SemExpr e1, float delta, boolean upper) { none() }
8360
}

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/RangeUtils.qll

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

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/SignAnalysisCommon.qll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ private import RangeAnalysisImpl
1111
private import SignAnalysisSpecific as Specific
1212
private import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
1313
private import ConstantAnalysis
14-
private import RangeUtils
1514
private import Sign
1615

17-
module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
16+
module SignAnalysis<DeltaSig D> {
1817
private import codeql.rangeanalysis.internal.RangeUtils::MakeUtils<Sem, D>
1918

2019
/**
@@ -39,7 +38,7 @@ module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
3938

4039
/** An SSA definition whose sign is determined by the sign of that definitions source expression. */
4140
private class ExplicitSignDef extends FlowSignDef instanceof SemSsaExplicitUpdate {
42-
final override Sign getSign() { result = semExprSign(super.getSourceExpr()) }
41+
final override Sign getSign() { result = semExprSign(super.getDefiningExpr()) }
4342
}
4443

4544
/** An SSA Phi definition, whose sign is the union of the signs of its inputs. */
@@ -148,7 +147,7 @@ module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
148147
not this instanceof ConstantSignExpr and
149148
(
150149
// Only track numeric types.
151-
Utils::getTrackedType(this) instanceof SemNumericType
150+
Sem::getExprType(this) instanceof SemNumericType
152151
or
153152
// Unless the language says to track this expression anyway.
154153
Specific::trackUnknownNonNumericExpr(this)
@@ -203,7 +202,7 @@ module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
203202

204203
/** An expression of an unsigned type. */
205204
private class UnsignedExpr extends FlowSignExpr {
206-
UnsignedExpr() { Utils::getTrackedType(this) instanceof SemUnsignedIntegerType }
205+
UnsignedExpr() { Sem::getExprType(this) instanceof SemUnsignedIntegerType }
207206

208207
override Sign getSignRestriction() {
209208
result = TPos() or
@@ -276,7 +275,7 @@ module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
276275
override SemUnboxExpr cast;
277276

278277
UnboxSignExpr() {
279-
exists(SemType fromType | fromType = Utils::getTrackedType(cast.getOperand()) |
278+
exists(SemType fromType | fromType = Sem::getExprType(cast.getOperand()) |
280279
// Only numeric source types are handled here.
281280
fromType instanceof SemNumericType
282281
)
@@ -471,7 +470,7 @@ module SignAnalysis<DeltaSig D, UtilSig<Sem, D> Utils> {
471470
Sign semExprSign(SemExpr e) {
472471
exists(Sign s | s = e.(SignExpr).getSign() |
473472
if
474-
Utils::getTrackedType(e) instanceof SemUnsignedIntegerType and
473+
Sem::getExprType(e) instanceof SemUnsignedIntegerType and
475474
s = TNeg() and
476475
not Specific::ignoreTypeRestrictions(e)
477476
then result = TPos()

cpp/ql/test/library-tests/ir/modulus-analysis/ModulusAnalysis.ql

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@ import cpp
22
import codeql.rangeanalysis.ModulusAnalysis
33
import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
44
import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticLocation
5-
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeUtils
65
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
76
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeAnalysisRelativeSpecific
87
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeAnalysisImpl
98
import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticExprSpecific
109
import semmle.code.cpp.ir.IR as IR
1110
import TestUtilities.InlineExpectationsTest
1211

13-
module ModulusAnalysisInstantiated =
14-
ModulusAnalysis<SemLocation, Sem, FloatDelta, ConstantBounds,
15-
RangeUtil<FloatDelta, CppLangImplRelative>>;
12+
module ModulusAnalysisInstantiated = ModulusAnalysis<SemLocation, Sem, FloatDelta, ConstantBounds>;
1613

1714
module ModulusAnalysisTest implements TestSig {
1815
string getARelevantTag() { result = "mod" }

cpp/ql/test/library-tests/ir/sign-analysis/SignAnalysis.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import cpp
22
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.SignAnalysisCommon
33
import semmle.code.cpp.rangeanalysis.new.internal.semantic.Semantic
4-
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeUtils
54
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.FloatDelta
65
import semmle.code.cpp.rangeanalysis.new.internal.semantic.analysis.RangeAnalysisRelativeSpecific
76
import semmle.code.cpp.rangeanalysis.new.internal.semantic.SemanticExprSpecific
87
import semmle.code.cpp.ir.IR as IR
98
import TestUtilities.InlineExpectationsTest
109

11-
module SignAnalysisInstantiated =
12-
SignAnalysis<FloatDelta, RangeUtil<FloatDelta, CppLangImplRelative>>;
10+
module SignAnalysisInstantiated = SignAnalysis<FloatDelta>;
1311

1412
module SignAnalysisTest implements TestSig {
1513
string getARelevantTag() { result = "sign" }
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
edges
2-
subpaths
2+
| main.cpp:6:27:6:30 | argv indirection | main.cpp:10:20:10:23 | argv indirection |
3+
| main.cpp:10:20:10:23 | argv indirection | tests.cpp:618:32:618:35 | argv indirection |
4+
| tests.cpp:613:19:613:24 | source indirection | tests.cpp:615:17:615:22 | source indirection |
5+
| tests.cpp:618:32:618:35 | argv indirection | tests.cpp:643:9:643:15 | access to array indirection |
6+
| tests.cpp:643:9:643:15 | access to array indirection | tests.cpp:613:19:613:24 | source indirection |
37
nodes
8+
| main.cpp:6:27:6:30 | argv indirection | semmle.label | argv indirection |
9+
| main.cpp:10:20:10:23 | argv indirection | semmle.label | argv indirection |
10+
| tests.cpp:613:19:613:24 | source indirection | semmle.label | source indirection |
11+
| tests.cpp:615:17:615:22 | source indirection | semmle.label | source indirection |
12+
| tests.cpp:618:32:618:35 | argv indirection | semmle.label | argv indirection |
13+
| tests.cpp:643:9:643:15 | access to array indirection | semmle.label | access to array indirection |
14+
subpaths
415
#select
16+
| tests.cpp:615:2:615:7 | call to strcpy | main.cpp:6:27:6:30 | argv indirection | tests.cpp:615:17:615:22 | source indirection | This 'call to strcpy' with input from $@ may overflow the destination. | main.cpp:6:27:6:30 | argv indirection | a command-line argument |

0 commit comments

Comments
 (0)