Skip to content

Commit c95b5ce

Browse files
authored
Merge branch 'main' into patch-1
2 parents 6ac0f0e + 14a362d commit c95b5ce

File tree

169 files changed

+5944
-1259
lines changed

Some content is hidden

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

169 files changed

+5944
-1259
lines changed

MODULE.bazel

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ bazel_dep(name = "buildifier_prebuilt", version = "6.4.0", dev_dependency = True
3737
# the versions there are canonical, the versions here are used for CI in github/codeql, as well as for the vendoring of dependencies.
3838
RUST_EDITION = "2024"
3939

40+
# run buildutils-internal/scripts/fill-rust-sha256s.py when updating (internal repo)
4041
RUST_VERSION = "1.86.0"
4142

4243
rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
@@ -47,6 +48,29 @@ rust.toolchain(
4748
"x86_64-apple-darwin",
4849
"aarch64-apple-darwin",
4950
],
51+
# generated by buildutils-internal/scripts/fill-rust-sha256s.py (internal repo)
52+
sha256s = {
53+
"rustc-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "4438b809ce4a083af31ed17aeeedcc8fc60ccffc0625bef1926620751b6989d7",
54+
"rustc-1.86.0-x86_64-apple-darwin.tar.xz": "42b76253626febb7912541a30d3379f463dec89581aad4cb72c6c04fb5a71dc5",
55+
"rustc-1.86.0-aarch64-apple-darwin.tar.xz": "23b8f52102249a47ab5bc859d54c9a3cb588a3259ba3f00f557d50edeca4fde9",
56+
"rustc-1.86.0-x86_64-pc-windows-msvc.tar.xz": "fdde839fea274529a31e51eb85c6df1782cc8479c9d1bc24e2914d66a0de41ab",
57+
"clippy-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "02aaff2c1407d2da8dba19aa4970dd873e311902b120a66cbcdbe51eb8836edf",
58+
"clippy-1.86.0-x86_64-apple-darwin.tar.xz": "bb85efda7bbffaf124867f5ca36d50932b1e8f533c62ee923438afb32ff8fe9a",
59+
"clippy-1.86.0-aarch64-apple-darwin.tar.xz": "239fa3a604b124f0312f2af08537874a1227dba63385484b468cca62e7c4f2f2",
60+
"clippy-1.86.0-x86_64-pc-windows-msvc.tar.xz": "d00498f47d49219f032e2c5eeebdfc3d32317c0dc3d3fd7125327445bc482cb4",
61+
"cargo-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "c5c1590f7e9246ad9f4f97cfe26ffa92707b52a769726596a9ef81565ebd908b",
62+
"cargo-1.86.0-x86_64-apple-darwin.tar.xz": "af163eb02d1a178044d1b4f2375960efd47130f795f6e33d09e345454bb26f4e",
63+
"cargo-1.86.0-aarch64-apple-darwin.tar.xz": "3cb13873d48c3e1e4cc684d42c245226a11fba52af6b047c3346ed654e7a05c0",
64+
"cargo-1.86.0-x86_64-pc-windows-msvc.tar.xz": "e57a9d89619b5604899bac443e68927bdd371e40f2e03e18950b6ceb3eb67966",
65+
"llvm-tools-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "282145ab7a63c98b625856f44b905b4dc726b497246b824632a5790debe95a78",
66+
"llvm-tools-1.86.0-x86_64-apple-darwin.tar.xz": "b55706e92f7da989207c50c13c7add483a9fedd233bc431b106eca2a8f151ec9",
67+
"llvm-tools-1.86.0-aarch64-apple-darwin.tar.xz": "04d3618c686845853585f036e3211eb9e18f2d290f4610a7a78bdc1fcce1ebd9",
68+
"llvm-tools-1.86.0-x86_64-pc-windows-msvc.tar.xz": "721a17cc8dc219177e4277a3592253934ef08daa1e1b12eda669a67d15fad8dd",
69+
"rust-std-1.86.0-x86_64-unknown-linux-gnu.tar.xz": "67be7184ea388d8ce0feaf7fdea46f1775cfc2970930264343b3089898501d37",
70+
"rust-std-1.86.0-x86_64-apple-darwin.tar.xz": "3b1140d54870a080080e84700143f4a342fbd02a410a319b05d9c02e7dcf44cc",
71+
"rust-std-1.86.0-aarch64-apple-darwin.tar.xz": "0fb121fb3b8fa9027d79ff598500a7e5cd086ddbc3557482ed3fdda00832c61b",
72+
"rust-std-1.86.0-x86_64-pc-windows-msvc.tar.xz": "3d5354b7b9cb950b58bff3fce18a652aa374bb30c8f70caebd3bd0b43cb41a33",
73+
},
5074
versions = [RUST_VERSION],
5175
)
5276
use_repo(rust, "rust_toolchains")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added a `isFinalValueOfParameter` predicate to DataFlow::Node which holds when a dataflow node represents the final value of an output parameter of a function.

cpp/ql/lib/ext/pthread.model.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: summaryModel
5+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
6+
- ["", "", False, "pthread_create", "", "", "Argument[@3]", "Argument[2].Parameter[@0]", "value", "manual"]

cpp/ql/lib/ext/std.thread.model.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extensions:
2+
- addsTo:
3+
pack: codeql/cpp-all
4+
extensible: summaryModel
5+
data: # namespace, type, subtypes, name, signature, ext, input, output, kind, provenance
6+
- ["std", "thread", True, "thread", "", "", "Argument[*@1]", "Argument[0].Parameter[@0]", "value", "manual"]
7+
- ["std", "thread", True, "thread", "", "", "Argument[*@2]", "Argument[0].Parameter[@1]", "value", "manual"]
8+
- ["std", "thread", True, "thread", "", "", "Argument[*@3]", "Argument[0].Parameter[@2]", "value", "manual"]
9+
- ["std", "thread", True, "thread", "", "", "Argument[*@4]", "Argument[0].Parameter[@3]", "value", "manual"]
10+
- ["std", "thread", True, "thread", "", "", "Argument[*@5]", "Argument[0].Parameter[@4]", "value", "manual"]
11+

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

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,16 +1382,89 @@ predicate neverSkipInPathGraph(Node n) {
13821382
exists(n.asIndirectDefinition())
13831383
}
13841384

1385-
class LambdaCallKind = Unit;
1385+
private newtype TLambdaCallKind =
1386+
TFunctionPointer() or
1387+
TFunctor()
1388+
1389+
class LambdaCallKind extends TLambdaCallKind {
1390+
predicate isFunctionPointer() { this = TFunctionPointer() }
1391+
1392+
predicate isFunctor() { this = TFunctor() }
1393+
1394+
string toString() {
1395+
this.isFunctionPointer() and
1396+
result = "Function pointer kind"
1397+
or
1398+
this.isFunctor() and
1399+
result = "Functor kind"
1400+
}
1401+
}
1402+
1403+
private class ConstructorCallInstruction extends CallInstruction {
1404+
Cpp::Class constructedType;
1405+
1406+
ConstructorCallInstruction() {
1407+
this.getStaticCallTarget().(Cpp::Constructor).getDeclaringType() = constructedType
1408+
}
1409+
1410+
Cpp::Class getConstructedType() { result = constructedType }
1411+
}
1412+
1413+
private class OperatorCall extends Cpp::MemberFunction {
1414+
OperatorCall() { this.hasName("operator()") }
1415+
}
1416+
1417+
private predicate isFunctorCreationWithoutConstructor(Node creation, OperatorCall operator) {
1418+
exists(UninitializedInstruction init, Instruction dest |
1419+
// A construction of an object with no constructor. In this case we use
1420+
// the `UninitializedInstruction` as the creation node.
1421+
init = creation.asInstruction() and
1422+
dest = init.getDestinationAddress() and
1423+
not any(ConstructorCallInstruction constructorCall).getThisArgument() = dest and
1424+
operator.getDeclaringType() = init.getResultType()
1425+
)
1426+
or
1427+
// Workaround for an extractor bug. In this snippet:
1428+
// ```
1429+
// struct S { };
1430+
// void f(S);
1431+
// f(S());
1432+
// ```
1433+
// The expression `S()` is represented as a 0 literal in the database.
1434+
exists(ConstantValueInstruction constant |
1435+
constant.getValue() = "0" and
1436+
creation.asInstruction() = constant and
1437+
constant.getResultType() = operator.getDeclaringType()
1438+
)
1439+
}
1440+
1441+
private predicate isFunctorCreationWithConstructor(Node creation, OperatorCall operator) {
1442+
exists(DataFlowCall constructorCall, IndirectionPosition pos |
1443+
// A construction of an object with a constructor. In this case we use
1444+
// the post-update node of the qualifier
1445+
pos.getArgumentIndex() = -1 and
1446+
isArgumentNode(creation.(PostUpdateNode).getPreUpdateNode(), constructorCall, pos) and
1447+
operator.getDeclaringType() =
1448+
constructorCall.asCallInstruction().(ConstructorCallInstruction).getConstructedType()
1449+
)
1450+
}
13861451

13871452
/** Holds if `creation` is an expression that creates a lambda of kind `kind` for `c`. */
13881453
predicate lambdaCreation(Node creation, LambdaCallKind kind, DataFlowCallable c) {
1389-
creation.asInstruction().(FunctionAddressInstruction).getFunctionSymbol() = c.asSourceCallable() and
1390-
exists(kind)
1454+
kind.isFunctionPointer() and
1455+
creation.asInstruction().(FunctionAddressInstruction).getFunctionSymbol() = c.asSourceCallable()
1456+
or
1457+
kind.isFunctor() and
1458+
exists(OperatorCall operator | operator = c.asSourceCallable() |
1459+
isFunctorCreationWithoutConstructor(creation, operator)
1460+
or
1461+
isFunctorCreationWithConstructor(creation, operator)
1462+
)
13911463
}
13921464

13931465
/** Holds if `call` is a lambda call of kind `kind` where `receiver` is the lambda expression. */
13941466
predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
1467+
kind.isFunctionPointer() and
13951468
(
13961469
call.(SummaryCall).getReceiver() = receiver.(FlowSummaryNode).getSummaryNode()
13971470
or
@@ -1400,8 +1473,15 @@ predicate lambdaCall(DataFlowCall call, LambdaCallKind kind, Node receiver) {
14001473
// has a result for `getStaticCallTarget`.
14011474
not exists(call.getStaticCallTarget()) and
14021475
call.asCallInstruction().getCallTargetOperand() = receiver.asOperand()
1403-
) and
1404-
exists(kind)
1476+
)
1477+
or
1478+
kind.isFunctor() and
1479+
(
1480+
call.(SummaryCall).getReceiver() = receiver.(FlowSummaryNode).getSummaryNode()
1481+
or
1482+
not exists(call.getStaticCallTarget()) and
1483+
call.asCallInstruction().getThisArgumentOperand() = receiver.asOperand()
1484+
)
14051485
}
14061486

14071487
/** Extra data-flow steps needed for lambda flow analysis. */

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,23 @@ class Node extends TIRDataFlowNode {
488488
result = this.(IndirectParameterNode).getParameter()
489489
}
490490

491+
/**
492+
* Holds if this node represents the `indirectionIndex`'th indirection of
493+
* the value of an output parameter `p` just before reaching the end of a function.
494+
*/
495+
predicate isFinalValueOfParameter(Parameter p, int indirectionIndex) {
496+
exists(FinalParameterNode n | n = this |
497+
p = n.getParameter() and
498+
indirectionIndex = n.getIndirectionIndex()
499+
)
500+
}
501+
502+
/**
503+
* Holds if this node represents the value of an output parameter `p`
504+
* just before reaching the end of a function.
505+
*/
506+
predicate isFinalValueOfParameter(Parameter p) { this.isFinalValueOfParameter(p, _) }
507+
491508
/**
492509
* Gets the variable corresponding to this node, if any. This can be used for
493510
* modeling flow in and out of global variables.
@@ -1225,7 +1242,7 @@ import RawIndirectNodes
12251242
/**
12261243
* INTERNAL: do not use.
12271244
*
1228-
* A node representing the value of an update parameter
1245+
* A node representing the value of an output parameter
12291246
* just before reaching the end of a function.
12301247
*/
12311248
class FinalParameterNode extends Node, TFinalParameterNode {

cpp/ql/lib/semmle/code/cpp/ir/implementation/aliased_ssa/Instruction.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,20 @@ class UninitializedInstruction extends VariableInstruction {
725725
* Gets the variable that is uninitialized.
726726
*/
727727
final Language::Variable getLocalVariable() { result = var.(IRUserVariable).getVariable() }
728+
729+
/**
730+
* Gets the operand that provides the address of the location to which the
731+
* uninitialized value will be stored.
732+
*/
733+
final AddressOperand getDestinationAddressOperand() { result = this.getAnOperand() }
734+
735+
/**
736+
* Gets the instruction whose result provides the address of the location to
737+
* which the value will be stored, if an exact definition is available.
738+
*/
739+
final Instruction getDestinationAddress() {
740+
result = this.getDestinationAddressOperand().getDef()
741+
}
728742
}
729743

730744
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/Instruction.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,20 @@ class UninitializedInstruction extends VariableInstruction {
725725
* Gets the variable that is uninitialized.
726726
*/
727727
final Language::Variable getLocalVariable() { result = var.(IRUserVariable).getVariable() }
728+
729+
/**
730+
* Gets the operand that provides the address of the location to which the
731+
* uninitialized value will be stored.
732+
*/
733+
final AddressOperand getDestinationAddressOperand() { result = this.getAnOperand() }
734+
735+
/**
736+
* Gets the instruction whose result provides the address of the location to
737+
* which the value will be stored, if an exact definition is available.
738+
*/
739+
final Instruction getDestinationAddress() {
740+
result = this.getDestinationAddressOperand().getDef()
741+
}
728742
}
729743

730744
/**

cpp/ql/lib/semmle/code/cpp/ir/implementation/unaliased_ssa/Instruction.qll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,20 @@ class UninitializedInstruction extends VariableInstruction {
725725
* Gets the variable that is uninitialized.
726726
*/
727727
final Language::Variable getLocalVariable() { result = var.(IRUserVariable).getVariable() }
728+
729+
/**
730+
* Gets the operand that provides the address of the location to which the
731+
* uninitialized value will be stored.
732+
*/
733+
final AddressOperand getDestinationAddressOperand() { result = this.getAnOperand() }
734+
735+
/**
736+
* Gets the instruction whose result provides the address of the location to
737+
* which the value will be stored, if an exact definition is available.
738+
*/
739+
final Instruction getDestinationAddress() {
740+
result = this.getDestinationAddressOperand().getDef()
741+
}
728742
}
729743

730744
/**

cpp/ql/src/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
### Minor Analysis Improvements
1313

14-
* Added flow model for the following libraries: `madler/zlib`, `google/brotli`, `libidn/libidn2`, `libssh2/libssh2/`, `nghttp2/nghttp2`, `libuv/libuv/`, and `curl/curl`. This may result in more alerts when running queries on codebases that use these libraries.
14+
* Added flow models for the following libraries: `madler/zlib`, `google/brotli`, `libidn/libidn2`, `libssh2/libssh2`, `nghttp2/nghttp2`, `libuv/libuv`, and `curl/curl`. This may result in more alerts when running queries on codebases that use these libraries.
1515

1616
## 1.4.2
1717

@@ -21,7 +21,7 @@ No user-facing changes.
2121

2222
### Minor Analysis Improvements
2323

24-
* Added flow model for the `SQLite` and `OpenSSL` libraries. This may result in more alerts when running queries on codebases that use these libraries.
24+
* Added flow models for the `SQLite` and `OpenSSL` libraries. This may result in more alerts when running queries on codebases that use these libraries.
2525

2626
## 1.4.0
2727

0 commit comments

Comments
 (0)