Skip to content

Commit 0ffb80e

Browse files
committed
Merge branch 'main' into rdmarsh/cpp/use-taint-configuration-dtt
2 parents 5667901 + e37ba75 commit 0ffb80e

File tree

36 files changed

+823
-39
lines changed

36 files changed

+823
-39
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you have an idea for a query that you would like to share with other CodeQL u
3838

3939
- The queries and libraries must be autoformatted, for example using the "Format Document" command in [CodeQL for Visual Studio Code](https://help.semmle.com/codeql/codeql-for-vscode/procedures/about-codeql-for-vscode.html).
4040

41-
If you prefer, you can use this [pre-commit hook](misc/scripts/pre-commit) that automatically checks whether your files are correctly formatted. See the [pre-commit hook installation guide](docs/install-pre-commit-hook.md) for instructions on how to install the hook.
41+
If you prefer, you can use this [pre-commit hook](misc/scripts/pre-commit) that automatically checks whether your files are correctly formatted. See the [pre-commit hook installation guide](docs/pre-commit-hook-setup.md) for instructions on how to install the hook.
4242

4343
4. **Compilation**
4444

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
codescanning
2+
* Added cpp/diagnostics/failed-extractions. This query gives information about which extractions did not run to completion.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name Failed extractions
3+
* @description Gives the command-line of compilations for which extraction did not run to completion.
4+
* @kind diagnostic
5+
* @id cpp/diagnostics/failed-extractions
6+
*/
7+
8+
import cpp
9+
10+
class AnonymousCompilation extends Compilation {
11+
override string toString() { result = "<compilation>" }
12+
}
13+
14+
string describe(Compilation c) {
15+
if c.getArgument(1) = "--mimic"
16+
then result = "compiler invocation " + concat(int i | i > 1 | c.getArgument(i), " " order by i)
17+
else result = "extractor invocation " + concat(int i | | c.getArgument(i), " " order by i)
18+
}
19+
20+
from Compilation c
21+
where not c.normalTermination()
22+
select c, "Extraction failed for " + describe(c), 2

cpp/ql/src/semmle/code/cpp/File.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ class File extends Container, @file {
276276
c.getAFileCompiled() = this and
277277
(
278278
c.getAnArgument() = "--microsoft" or
279-
c.getAnArgument().toLowerCase().replaceAll("\\", "/").matches("%/cl.exe")
279+
c.getAnArgument()
280+
.toLowerCase()
281+
.replaceAll("\\", "/")
282+
.matches(["%/cl.exe", "%/clang-cl.exe"])
280283
)
281284
)
282285
or

docs/codeql/writing-codeql-queries/troubleshooting-query-performance.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This topic offers some simple tips on how to avoid common problems that can affe
1212
Before reading the tips below, it is worth reiterating a few important points about CodeQL and the QL language:
1313

1414
- CodeQL :ref:`predicates <predicates>` and :ref:`classes <classes>` are evaluated to database `tables <https://en.wikipedia.org/wiki/Table_(database)>`__. Large predicates generate large tables with many rows, and are therefore expensive to compute.
15-
- The QL language is implemented using standard database operations and `relational algebra <https://en.wikipedia.org/wiki/Relational_algebra>`__ (such as join, projection, and union). For more information about query languages and databases, see ":ref:`About the QL language <about-the-ql-language>`.
15+
- The QL language is implemented using standard database operations and `relational algebra <https://en.wikipedia.org/wiki/Relational_algebra>`__ (such as join, projection, and union). For more information about query languages and databases, see ":ref:`About the QL language <about-the-ql-language>`."
1616
- Queries are evaluated *bottom-up*, which means that a predicate is not evaluated until *all* of the predicates that it depends on are evaluated. For more information on query evaluation, see ":ref:`Evaluation of QL programs <evaluation-of-ql-programs>`."
1717

1818
Performance tips
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* Added models for `ObjectUtils` methods in the Apache Commons Lang library. This may lead to more results from any dataflow query where traversal of `ObjectUtils` methods means we can now complete a path from a source of tainted data to a corresponding sink.

java/ql/src/semmle/code/java/Modules.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class OpensDirective extends Directive, @opens {
144144

145145
/**
146146
* Gets a module specified in the `to` clause of this
147-
* `exports` directive, if any.
147+
* `opens` directive, if any.
148148
*/
149149
Module getATargetModule() { opensTo(this, result) }
150150

java/ql/src/semmle/code/java/dataflow/internal/TaintTrackingUtil.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ predicate localAdditionalTaintStep(DataFlow::Node src, DataFlow::Node sink) {
4646
localAdditionalTaintUpdateStep(src.asExpr(),
4747
sink.(DataFlow::PostUpdateNode).getPreUpdateNode().asExpr())
4848
or
49-
summaryStep(src, sink, "taint")
49+
summaryStep(src, sink, "taint") and
50+
not summaryStep(src, sink, "value")
5051
or
5152
exists(Argument arg |
5253
src.asExpr() = arg and

java/ql/src/semmle/code/java/frameworks/apache/Lang.qll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,3 +396,30 @@ private class ApacheRegExUtilsModel extends SummaryModelCsv {
396396
]
397397
}
398398
}
399+
400+
/**
401+
* Taint-propagating models for `ObjectUtils`.
402+
*/
403+
private class ApacheObjectUtilsModel extends SummaryModelCsv {
404+
override predicate row(string row) {
405+
row =
406+
[
407+
// Note all the functions annotated with `taint` flow really should have `value` flow,
408+
// but we don't support value-preserving varargs functions at the moment.
409+
"org.apache.commons.lang3;ObjectUtils;false;clone;;;Argument;ReturnValue;value",
410+
"org.apache.commons.lang3;ObjectUtils;false;cloneIfPossible;;;Argument;ReturnValue;value",
411+
"org.apache.commons.lang3;ObjectUtils;false;CONST;;;Argument;ReturnValue;value",
412+
"org.apache.commons.lang3;ObjectUtils;false;CONST_BYTE;;;Argument;ReturnValue;value",
413+
"org.apache.commons.lang3;ObjectUtils;false;CONST_SHORT;;;Argument;ReturnValue;value",
414+
"org.apache.commons.lang3;ObjectUtils;false;defaultIfNull;;;Argument;ReturnValue;value",
415+
"org.apache.commons.lang3;ObjectUtils;false;firstNonNull;;;Argument;ReturnValue;taint",
416+
"org.apache.commons.lang3;ObjectUtils;false;getIfNull;;;Argument[0];ReturnValue;value",
417+
"org.apache.commons.lang3;ObjectUtils;false;max;;;Argument;ReturnValue;taint",
418+
"org.apache.commons.lang3;ObjectUtils;false;median;;;Argument;ReturnValue;taint",
419+
"org.apache.commons.lang3;ObjectUtils;false;min;;;Argument;ReturnValue;taint",
420+
"org.apache.commons.lang3;ObjectUtils;false;mode;;;Argument;ReturnValue;taint",
421+
"org.apache.commons.lang3;ObjectUtils;false;requireNonEmpty;;;Argument[0];ReturnValue;value",
422+
"org.apache.commons.lang3;ObjectUtils;false;toString;(Object,String);;Argument[1];ReturnValue;value"
423+
]
424+
}
425+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import org.apache.commons.lang3.ObjectUtils;
2+
3+
public class ObjectUtilsTest {
4+
String taint() { return "tainted"; }
5+
6+
private static class IntSource {
7+
static int taint() { return 0; }
8+
}
9+
10+
void sink(Object o) {}
11+
12+
void test() throws Exception {
13+
sink(ObjectUtils.clone(taint())); // $hasValueFlow
14+
sink(ObjectUtils.cloneIfPossible(taint())); // $hasValueFlow
15+
sink(ObjectUtils.CONST(taint())); // $hasValueFlow
16+
sink(ObjectUtils.CONST_SHORT(IntSource.taint())); // $hasValueFlow
17+
sink(ObjectUtils.CONST_BYTE(IntSource.taint())); // $hasValueFlow
18+
sink(ObjectUtils.defaultIfNull(taint(), null)); // $hasValueFlow
19+
sink(ObjectUtils.defaultIfNull(null, taint())); // $hasValueFlow
20+
sink(ObjectUtils.firstNonNull(taint(), null, null)); // $hasTaintFlow $MISSING:hasValueFlow
21+
sink(ObjectUtils.firstNonNull(null, taint(), null)); // $hasTaintFlow $MISSING:hasValueFlow
22+
sink(ObjectUtils.firstNonNull(null, null, taint())); // $hasTaintFlow $MISSING:hasValueFlow
23+
sink(ObjectUtils.getIfNull(taint(), null)); // $hasValueFlow
24+
sink(ObjectUtils.max(taint(), null, null)); // $hasTaintFlow $MISSING:hasValueFlow
25+
sink(ObjectUtils.max(null, taint(), null)); // $hasTaintFlow $MISSING:hasValueFlow
26+
sink(ObjectUtils.max(null, null, taint())); // $hasTaintFlow $MISSING:hasValueFlow
27+
sink(ObjectUtils.median(taint(), null, null)); // $hasTaintFlow $MISSING:hasValueFlow
28+
sink(ObjectUtils.median((String)null, taint(), null)); // $hasTaintFlow $MISSING:hasValueFlow
29+
sink(ObjectUtils.median((String)null, null, taint())); // $hasTaintFlow $MISSING:hasValueFlow
30+
sink(ObjectUtils.min(taint(), null, null)); // $hasTaintFlow $MISSING:hasValueFlow
31+
sink(ObjectUtils.min(null, taint(), null)); // $hasTaintFlow $MISSING:hasValueFlow
32+
sink(ObjectUtils.min(null, null, taint())); // $hasTaintFlow $MISSING:hasValueFlow
33+
sink(ObjectUtils.mode(taint(), null, null)); // $hasTaintFlow $MISSING:hasValueFlow
34+
sink(ObjectUtils.mode(null, taint(), null)); // $hasTaintFlow $MISSING:hasValueFlow
35+
sink(ObjectUtils.mode(null, null, taint())); // $hasTaintFlow $MISSING:hasValueFlow
36+
sink(ObjectUtils.requireNonEmpty(taint(), "message")); // $hasValueFlow
37+
sink(ObjectUtils.requireNonEmpty("not null", taint())); // GOOD (message doesn't propagate to the return)
38+
sink(ObjectUtils.toString(taint(), "default string")); // GOOD (first argument is stringified)
39+
sink(ObjectUtils.toString(null, taint())); // $hasValueFlow
40+
}
41+
}

0 commit comments

Comments
 (0)