Skip to content

Commit 5deb996

Browse files
authored
Merge branch 'main' into atorralba/android_slice_models
2 parents 91efb61 + af6a21f commit 5deb996

File tree

535 files changed

+22236
-12202
lines changed

Some content is hidden

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

535 files changed

+22236
-12202
lines changed

config/identical-files.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@
367367
],
368368
"Inline Test Expectations": [
369369
"cpp/ql/test/TestUtilities/InlineExpectationsTest.qll",
370+
"csharp/ql/test/TestUtilities/InlineExpectationsTest.qll",
370371
"java/ql/test/TestUtilities/InlineExpectationsTest.qll",
371372
"python/ql/test/TestUtilities/InlineExpectationsTest.qll"
372373
],
@@ -461,5 +462,12 @@
461462
"ReDoS Polynomial Python/JS": [
462463
"javascript/ql/lib/semmle/javascript/security/performance/SuperlinearBackTracking.qll",
463464
"python/ql/lib/semmle/python/security/performance/SuperlinearBackTracking.qll"
465+
],
466+
"CodeQL Tutorial": [
467+
"cpp/ql/lib/tutorial.qll",
468+
"csharp/ql/lib/tutorial.qll",
469+
"java/ql/lib/tutorial.qll",
470+
"javascript/ql/lib/tutorial.qll",
471+
"python/ql/lib/tutorial.qll"
464472
]
465473
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Several improvements made to the `NullTermination.qll` library and the 'Potential improper null termination' (cpp/improper-null-termination). These changes reduce the number of false positive results for this query and related query 'User-controlled data may not be null terminated' (cpp/user-controlled-null-termination-tainted).
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
codescanning
2+
* Problems with extraction that in most cases won't break the analysis in a significant way are now reported as warnings rather than errors.
3+
* The failed extractor invocations query now has severity `error`.

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,8 @@ class Declaration extends Locatable, @declaration {
275275
* `getTemplateArgumentKind(0)`.
276276
*/
277277
final Locatable getTemplateArgumentKind(int index) {
278-
if exists(getTemplateArgumentValue(index))
279-
then result = getTemplateArgumentType(index)
280-
else none()
278+
exists(getTemplateArgumentValue(index)) and
279+
result = getTemplateArgumentType(index)
281280
}
282281

283282
/** Gets the number of template arguments for this declaration. */

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,6 @@ class RoutineType extends Type, @routinetype {
16501650
i = 0 and result = "" and not exists(this.getAParameterType())
16511651
or
16521652
(
1653-
exists(this.getParameterType(i)) and
16541653
if i < max(int j | exists(this.getParameterType(j)))
16551654
then
16561655
// Not the last one

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class XMLParent extends @xmlparent {
108108
}
109109

110110
/** Gets the text value contained in this XML parent. */
111-
string getTextValue() { result = allCharactersString() }
111+
string getTextValue() { result = this.allCharactersString() }
112112

113113
/** Gets a printable representation of this XML parent. */
114114
string toString() { result = this.getName() }
@@ -119,7 +119,7 @@ class XMLFile extends XMLParent, File {
119119
XMLFile() { xmlEncoding(this, _) }
120120

121121
/** Gets a printable representation of this XML file. */
122-
override string toString() { result = getName() }
122+
override string toString() { result = this.getName() }
123123

124124
/** Gets the name of this XML file. */
125125
override string getName() { result = File.super.getAbsolutePath() }
@@ -129,14 +129,14 @@ class XMLFile extends XMLParent, File {
129129
*
130130
* Gets the path of this XML file.
131131
*/
132-
deprecated string getPath() { result = getAbsolutePath() }
132+
deprecated string getPath() { result = this.getAbsolutePath() }
133133

134134
/**
135135
* DEPRECATED: Use `getParentContainer().getAbsolutePath()` instead.
136136
*
137137
* Gets the path of the folder that contains this XML file.
138138
*/
139-
deprecated string getFolder() { result = getParentContainer().getAbsolutePath() }
139+
deprecated string getFolder() { result = this.getParentContainer().getAbsolutePath() }
140140

141141
/** Gets the encoding of this XML file. */
142142
string getEncoding() { xmlEncoding(this, result) }
@@ -200,7 +200,7 @@ class XMLDTD extends XMLLocatable, @xmldtd {
200200
*/
201201
class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
202202
/** Holds if this XML element has the given `name`. */
203-
predicate hasName(string name) { name = getName() }
203+
predicate hasName(string name) { name = this.getName() }
204204

205205
/** Gets the name of this XML element. */
206206
override string getName() { xmlElements(this, result, _, _, _) }
@@ -239,7 +239,7 @@ class XMLElement extends @xmlelement, XMLParent, XMLLocatable {
239239
string getAttributeValue(string name) { result = this.getAttribute(name).getValue() }
240240

241241
/** Gets a printable representation of this XML element. */
242-
override string toString() { result = getName() }
242+
override string toString() { result = this.getName() }
243243
}
244244

245245
/**

cpp/ql/lib/semmle/code/cpp/commons/NullTermination.qll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import cpp
22
private import semmle.code.cpp.models.interfaces.ArrayFunction
33
private import semmle.code.cpp.models.implementations.Strcat
4+
import semmle.code.cpp.dataflow.DataFlow
45

56
private predicate mayAddNullTerminatorHelper(Expr e, VariableAccess va, Expr e0) {
67
exists(StackVariable v0, Expr val |
@@ -45,22 +46,28 @@ predicate mayAddNullTerminator(Expr e, VariableAccess va) {
4546
ae.getRValue().getAChild*() = va
4647
)
4748
or
48-
// Function call: library function, varargs function, function
49-
// containing assembler code, or function where the relevant
50-
// parameter is potentially added a null terminator.
49+
// Function calls...
5150
exists(Call c, Function f, int i |
5251
e = c and
5352
f = c.getTarget() and
5453
not functionArgumentMustBeNullTerminated(f, i) and
5554
c.getAnArgumentSubExpr(i) = va
5655
|
57-
not f.hasEntryPoint() and not functionArgumentMustBeNullTerminated(f, i)
56+
// library function
57+
not f.hasEntryPoint()
5858
or
59+
// function where the relevant parameter is potentially added a null terminator
5960
mayAddNullTerminator(_, f.getParameter(i).getAnAccess())
6061
or
62+
// varargs function
6163
f.isVarargs() and i >= f.getNumberOfParameters()
6264
or
65+
// function containing assembler code
6366
exists(AsmStmt s | s.getEnclosingFunction() = f)
67+
or
68+
// function where the relevant parameter is returned (leaking it to be potentially null terminated elsewhere)
69+
DataFlow::localFlow(DataFlow::parameterNode(f.getParameter(i)),
70+
DataFlow::exprNode(any(ReturnStmt rs).getExpr()))
6471
)
6572
or
6673
// Call without target (e.g., function pointer call)

cpp/ql/lib/semmle/code/cpp/controlflow/internal/ConstantExprs.qll

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -344,14 +344,13 @@ private int convertIntToType(int val, IntegralType t) {
344344
then if val = 0 then result = 0 else result = 1
345345
else
346346
if t.isUnsigned()
347-
then if val >= 0 and val.bitShiftRight(t.getSize() * 8) = 0 then result = val else none()
347+
then val >= 0 and val.bitShiftRight(t.getSize() * 8) = 0 and result = val
348348
else
349349
if val >= 0 and val.bitShiftRight(t.getSize() * 8 - 1) = 0
350350
then result = val
351-
else
352-
if (-(val + 1)).bitShiftRight(t.getSize() * 8 - 1) = 0
353-
then result = val
354-
else none()
351+
else (
352+
(-(val + 1)).bitShiftRight(t.getSize() * 8 - 1) = 0 and result = val
353+
)
355354
}
356355

357356
/**

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

cpp/ql/lib/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,7 +2139,8 @@ private predicate expensiveLen2unfolding(TypedContent tc, Configuration config)
21392139
) and
21402140
accessPathApproxCostLimits(apLimit, tupleLimit) and
21412141
apLimit < tails and
2142-
tupleLimit < (tails - 1) * nodes
2142+
tupleLimit < (tails - 1) * nodes and
2143+
not tc.forceHighPrecision()
21432144
)
21442145
}
21452146

@@ -2973,12 +2974,15 @@ private AccessPathApprox getATail(AccessPathApprox apa, Configuration config) {
29732974
* expected to be expensive. Holds with `unfold = true` otherwise.
29742975
*/
29752976
private predicate evalUnfold(AccessPathApprox apa, boolean unfold, Configuration config) {
2976-
exists(int aps, int nodes, int apLimit, int tupleLimit |
2977-
aps = countPotentialAps(apa, config) and
2978-
nodes = countNodesUsingAccessPath(apa, config) and
2979-
accessPathCostLimits(apLimit, tupleLimit) and
2980-
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2981-
)
2977+
if apa.getHead().forceHighPrecision()
2978+
then unfold = true
2979+
else
2980+
exists(int aps, int nodes, int apLimit, int tupleLimit |
2981+
aps = countPotentialAps(apa, config) and
2982+
nodes = countNodesUsingAccessPath(apa, config) and
2983+
accessPathCostLimits(apLimit, tupleLimit) and
2984+
if apLimit < aps and tupleLimit < (aps - 1) * nodes then unfold = false else unfold = true
2985+
)
29822986
}
29832987

29842988
/**

0 commit comments

Comments
 (0)