Skip to content

Commit e3b46f2

Browse files
authored
Merge branch 'main' into atorralba/fix-local-and-remote-flow-tests
2 parents a8aa8e3 + af6a21f commit e3b46f2

File tree

507 files changed

+21839
-11458
lines changed

Some content is hidden

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

507 files changed

+21839
-11458
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/DataFlowImplCommon.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ class CallContextSpecificCall extends CallContextCall, TSpecificCall {
937937
}
938938

939939
override predicate relevantFor(DataFlowCallable callable) {
940-
recordDataFlowCallSite(getCall(), callable)
940+
recordDataFlowCallSite(this.getCall(), callable)
941941
}
942942

943943
override predicate matchesCall(DataFlowCall call) { call = this.getCall() }
@@ -1257,7 +1257,7 @@ abstract class AccessPathFront extends TAccessPathFront {
12571257

12581258
TypedContent getHead() { this = TFrontHead(result) }
12591259

1260-
predicate isClearedAt(Node n) { clearsContentCached(n, getHead().getContent()) }
1260+
predicate isClearedAt(Node n) { clearsContentCached(n, this.getHead().getContent()) }
12611261
}
12621262

12631263
class AccessPathFrontNil extends AccessPathFront, TFrontNil {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,15 +219,13 @@ class DataFlowExpr = Expr;
219219
class DataFlowType = Type;
220220

221221
/** A function call relevant for data flow. */
222-
class DataFlowCall extends Expr {
223-
DataFlowCall() { this instanceof Call }
224-
222+
class DataFlowCall extends Expr instanceof Call {
225223
/**
226224
* Gets the nth argument for this call.
227225
*
228226
* The range of `n` is from `0` to `getNumberOfArguments() - 1`.
229227
*/
230-
Expr getArgument(int n) { result = this.(Call).getArgument(n) }
228+
Expr getArgument(int n) { result = super.getArgument(n) }
231229

232230
/** Gets the data flow node corresponding to this call. */
233231
ExprNode getNode() { result.getExpr() = this }

0 commit comments

Comments
 (0)