Skip to content

Commit 59098be

Browse files
authored
Merge branch 'main' into change/adjust-extracted-files-diagnostics
2 parents b26fef8 + 1fba345 commit 59098be

File tree

598 files changed

+205821
-23090
lines changed

Some content is hidden

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

598 files changed

+205821
-23090
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ go/extractor/opencsv/CSVReader.java -text
7171
# `javascript/ql/experimental/adaptivethreatmodeling/test/update_endpoint_test_files.py`.
7272
javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated/**/*.js linguist-generated=true -merge
7373
javascript/ql/experimental/adaptivethreatmodeling/test/endpoint_large_scale/autogenerated/**/*.ts linguist-generated=true -merge
74+
75+
# Auto-generated modeling for Python
76+
python/ql/lib/semmle/python/frameworks/data/internal/subclass-capture/*.yml linguist-generated=true

.github/workflows/mad_modelDiff.yml

+7-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ on:
1212
- main
1313
paths:
1414
- "java/ql/src/utils/modelgenerator/**/*.*"
15+
- "misc/scripts/models-as-data/*.*"
1516
- ".github/workflows/mad_modelDiff.yml"
1617

1718
permissions:
@@ -61,8 +62,9 @@ jobs:
6162
DATABASE=$2
6263
cd codeql-$QL_VARIANT
6364
SHORTNAME=`basename $DATABASE`
64-
python java/ql/src/utils/modelgenerator/GenerateFlowModel.py --with-summaries --with-sinks $DATABASE ${SHORTNAME}.temp.model.yml
65-
mv java/ql/lib/ext/generated/${SHORTNAME}.temp.model.yml $MODELS/${SHORTNAME}Generated_${QL_VARIANT}.model.yml
65+
python java/ql/src/utils/modelgenerator/GenerateFlowModel.py --with-summaries --with-sinks $DATABASE $SHORTNAME/$QL_VARIANT
66+
mkdir -p $MODELS/$SHORTNAME
67+
mv java/ql/lib/ext/generated/$SHORTNAME/$QL_VARIANT $MODELS/$SHORTNAME
6668
cd ..
6769
}
6870
@@ -85,16 +87,16 @@ jobs:
8587
set -x
8688
MODELS=`pwd`/tmp-models
8789
ls -1 tmp-models/
88-
for m in $MODELS/*_main.model.yml ; do
90+
for m in $MODELS/*/main/*.model.yml ; do
8991
t="${m/main/"pr"}"
9092
basename=`basename $m`
91-
name="diff_${basename/_main.model.yml/""}"
93+
name="diff_${basename/.model.yml/""}"
9294
(diff -w -u $m $t | diff2html -i stdin -F $MODELS/$name.html) || true
9395
done
9496
- uses: actions/upload-artifact@v3
9597
with:
9698
name: models
97-
path: tmp-models/*.model.yml
99+
path: tmp-models/**/**/*.model.yml
98100
retention-days: 20
99101
- uses: actions/upload-artifact@v3
100102
with:

cpp/downgrades/cf72c8898d19eb1b3374432cf79d8276cb07ad43/upgrade.properties

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
description: Support C++17 if and switch initializers
22
compatibility: partial
3+
constexpr_if_initialization.rel: delete
34
if_initialization.rel: delete
45
switch_initialization.rel: delete
56
exprparents.rel: run exprparents.qlo

cpp/ql/lib/CHANGELOG.md

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
## 0.12.3
2+
3+
### Deprecated APIs
4+
5+
* The `isUserInput`, `userInputArgument`, and `userInputReturned` predicates from `SecurityOptions` have been deprecated. Use `FlowSource` instead.
6+
7+
### New Features
8+
9+
* `UserDefineLiteral` and `DeductionGuide` classes have been added, representing C++11 user defined literals and C++17 deduction guides.
10+
11+
### Minor Analysis Improvements
12+
13+
* Changed the output of `Node.toString` to better reflect how many indirections a given dataflow node has.
14+
* Added a new predicate `Node.asDefinition` on `DataFlow::Node`s for selecting the dataflow node corresponding to a particular definition.
15+
* The deprecated `DefaultTaintTracking` library has been removed.
16+
* The `Guards` library has been replaced with the API-compatible `IRGuards` implementation, which has better precision in some cases.
17+
18+
### Bug Fixes
19+
20+
* Under certain circumstances a function declaration that is not also a definition could be associated with a `Function` that did not have the definition as a `FunctionDeclarationEntry`. This is now fixed when only one definition exists, and a unique `Function` will exist that has both the declaration and the definition as a `FunctionDeclarationEntry`.
21+
122
## 0.12.2
223

324
No user-facing changes.

cpp/ql/lib/change-notes/2022-11-21-ir-guards-replacement.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2023-11-25-default-taint-tracking-removal.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2023-11-30-as-definition.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2023-12-08-ususerinput-deprecation.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2023-12-14-dataflow-tostring.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2023-12-22-unique-function.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2024-01-02-function-types.md

-4
This file was deleted.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## 0.12.3
2+
3+
### Deprecated APIs
4+
5+
* The `isUserInput`, `userInputArgument`, and `userInputReturned` predicates from `SecurityOptions` have been deprecated. Use `FlowSource` instead.
6+
7+
### New Features
8+
9+
* `UserDefineLiteral` and `DeductionGuide` classes have been added, representing C++11 user defined literals and C++17 deduction guides.
10+
11+
### Minor Analysis Improvements
12+
13+
* Changed the output of `Node.toString` to better reflect how many indirections a given dataflow node has.
14+
* Added a new predicate `Node.asDefinition` on `DataFlow::Node`s for selecting the dataflow node corresponding to a particular definition.
15+
* The deprecated `DefaultTaintTracking` library has been removed.
16+
* The `Guards` library has been replaced with the API-compatible `IRGuards` implementation, which has better precision in some cases.
17+
18+
### Bug Fixes
19+
20+
* Under certain circumstances a function declaration that is not also a definition could be associated with a `Function` that did not have the definition as a `FunctionDeclarationEntry`. This is now fixed when only one definition exists, and a unique `Function` will exist that has both the declaration and the definition as a `FunctionDeclarationEntry`.

cpp/ql/lib/codeql-pack.release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 0.12.2
2+
lastReleaseVersion: 0.12.3

cpp/ql/lib/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-all
2-
version: 0.12.3-dev
2+
version: 0.12.4-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import semmle.code.cpp.Location
77
private import semmle.code.cpp.Enclosing
88
private import semmle.code.cpp.internal.ResolveClass
99
private import semmle.code.cpp.internal.ResolveGlobalVariable
10-
private import semmle.code.cpp.internal.ResolveFunction
1110

1211
/**
1312
* Get the `Element` that represents this `@element`.
@@ -31,14 +30,11 @@ pragma[inline]
3130
@element unresolveElement(Element e) {
3231
not result instanceof @usertype and
3332
not result instanceof @variable and
34-
not result instanceof @function and
3533
result = e
3634
or
3735
e = resolveClass(result)
3836
or
3937
e = resolveGlobalVariable(result)
40-
or
41-
e = resolveFunction(result)
4238
}
4339

4440
/**

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

-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import semmle.code.cpp.exprs.Call
99
import semmle.code.cpp.metrics.MetricFunction
1010
import semmle.code.cpp.Linkage
1111
private import semmle.code.cpp.internal.ResolveClass
12-
private import semmle.code.cpp.internal.ResolveFunction
1312

1413
/**
1514
* A C/C++ function [N4140 8.3.5]. Both member functions and non-member
@@ -26,8 +25,6 @@ private import semmle.code.cpp.internal.ResolveFunction
2625
* in more detail in `Declaration.qll`.
2726
*/
2827
class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
29-
Function() { isFunction(underlyingElement(this)) }
30-
3128
override string getName() { functions(underlyingElement(this), result, _) }
3229

3330
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* A library for detecting general string concatenations.
3+
*/
4+
5+
import cpp
6+
import semmle.code.cpp.models.implementations.Strcat
7+
import semmle.code.cpp.models.interfaces.FormattingFunction
8+
private import semmle.code.cpp.dataflow.new.DataFlow
9+
10+
/**
11+
* A call that performs a string concatenation. A string can be either a C
12+
* string (i.e., a value of type `char*`), or a C++ string (i.e., a value of
13+
* type `std::string`).
14+
*/
15+
class StringConcatenation extends Call {
16+
StringConcatenation() {
17+
// sprintf-like functions, i.e., concat through formatting
18+
this instanceof FormattingFunctionCall
19+
or
20+
this.getTarget() instanceof StrcatFunction
21+
or
22+
this.getTarget() instanceof StrlcatFunction
23+
or
24+
// operator+ and ostream (<<) concat
25+
exists(Call call, Operator op |
26+
call.getTarget() = op and
27+
op.hasQualifiedName(["std", "bsl"], ["operator+", "operator<<"]) and
28+
op.getType()
29+
.stripType()
30+
.(UserType)
31+
.hasQualifiedName(["std", "bsl"], ["basic_string", "basic_ostream"]) and
32+
this = call
33+
)
34+
}
35+
36+
/**
37+
* Gets an operand of this concatenation (one of the string operands being
38+
* concatenated).
39+
* Will not return out param for sprintf-like functions, but will consider the format string
40+
* to be part of the operands.
41+
*/
42+
Expr getAnOperand() {
43+
// The result is an argument of 'this' (a call)
44+
result = this.getAnArgument() and
45+
// addresses odd behavior with overloaded operators
46+
// i.e., "call to operator+" appearing as an operand
47+
// occurs in cases like `string s = s1 + s2 + s3`, which is represented as
48+
// `string s = (s1.operator+(s2)).operator+(s3);`
49+
// By limiting to non-calls we get the leaf operands (the variables or raw strings)
50+
// also, by not enumerating allowed types (variables and strings) we avoid issues
51+
// with missed corner cases or extensions/changes to CodeQL in the future which might
52+
// invalidate that approach.
53+
not result instanceof Call and
54+
// Limit the result type to string
55+
(
56+
result.getUnderlyingType().stripType().getName() = "char"
57+
or
58+
result
59+
.getType()
60+
.getUnspecifiedType()
61+
.(UserType)
62+
.hasQualifiedName(["std", "bsl"], "basic_string")
63+
) and
64+
// when 'this' is a `FormattingFunctionCall` the result must be the format string argument
65+
// or one of the formatting arguments
66+
(
67+
this instanceof FormattingFunctionCall
68+
implies
69+
(
70+
result = this.(FormattingFunctionCall).getFormat()
71+
or
72+
exists(int n |
73+
result = this.getArgument(n) and
74+
n >= this.(FormattingFunctionCall).getTarget().getFirstFormatArgumentIndex()
75+
)
76+
)
77+
)
78+
}
79+
80+
/**
81+
* Gets the data flow node representing the concatenation result.
82+
*/
83+
DataFlow::Node getResultNode() {
84+
if this.getTarget() instanceof StrcatFunction
85+
then
86+
result.asDefiningArgument() =
87+
this.getArgument(this.getTarget().(StrcatFunction).getParamDest())
88+
or
89+
// Hardcoding it is also the return
90+
result.asExpr() = this.(Call)
91+
else
92+
if this.getTarget() instanceof StrlcatFunction
93+
then (
94+
result.asDefiningArgument() =
95+
this.getArgument(this.getTarget().(StrlcatFunction).getParamDest())
96+
) else
97+
if this instanceof FormattingFunctionCall
98+
then result.asDefiningArgument() = this.(FormattingFunctionCall).getOutputArgument(_)
99+
else result.asExpr() = this.(Call)
100+
}
101+
}

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

-12
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@ private predicate functionSignature(Function f, string qualifiedName, int nparam
5454
not f.isStatic()
5555
}
5656

57-
/**
58-
* Holds if the set of viable implementations that can be called by `call`
59-
* might be improved by knowing the call context.
60-
*/
61-
predicate mayBenefitFromCallContext(DataFlowCall call, Function f) { none() }
62-
63-
/**
64-
* Gets a viable dispatch target of `call` in the context `ctx`. This is
65-
* restricted to those `call`s for which a context might make a difference.
66-
*/
67-
Function viableImplInCallContext(DataFlowCall call, DataFlowCall ctx) { none() }
68-
6957
/** A parameter position represented by an integer. */
7058
class ParameterPosition extends int {
7159
ParameterPosition() { any(ParameterNode p).isParameterOf(_, this) }

cpp/ql/lib/semmle/code/cpp/internal/ResolveFunction.qll

-57
This file was deleted.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowDispatch.qll

+1-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ private predicate functionSignature(Function f, string qualifiedName, int nparam
249249
* Holds if the set of viable implementations that can be called by `call`
250250
* might be improved by knowing the call context.
251251
*/
252-
predicate mayBenefitFromCallContext(DataFlowCall call, DataFlowCallable f) {
253-
mayBenefitFromCallContext(call, f, _)
254-
}
252+
predicate mayBenefitFromCallContext(DataFlowCall call) { mayBenefitFromCallContext(call, _, _) }
255253

256254
/**
257255
* Holds if `call` is a call through a function pointer, and the pointer

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplSpecific.qll

+4
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ module CppDataFlow implements InputSig {
2222
predicate getAdditionalFlowIntoCallNodeTerm = Private::getAdditionalFlowIntoCallNodeTerm/2;
2323

2424
predicate validParameterAliasStep = Private::validParameterAliasStep/2;
25+
26+
predicate mayBenefitFromCallContext = Private::mayBenefitFromCallContext/1;
27+
28+
predicate viableImplInCallContext = Private::viableImplInCallContext/2;
2529
}

0 commit comments

Comments
 (0)