Skip to content

Commit 13f1f8f

Browse files
authored
Merge branch 'main' into redsun82/env-dump-integration-test
2 parents cf430da + e096bdb commit 13f1f8f

File tree

23 files changed

+1468
-1284
lines changed

23 files changed

+1468
-1284
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ private module Cached {
981981
or
982982
exists(CompareValueNumber cmp, Operand left, Operand right, AbstractValue v |
983983
test = cmp and
984-
cmp.hasOperands(left, right) and
984+
pragma[only_bind_into](cmp)
985+
.hasOperands(pragma[only_bind_into](left), pragma[only_bind_into](right)) and
985986
isConvertedBool(left.getDef()) and
986987
int_value(right.getDef()) = 0 and
987988
unary_compares_eq(valueNumberOfOperand(left), op, k, areEqual, v)

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ public static void Sink<T>(T t) { }
1313

1414
public static void SinkElem<T>(T[] ts) => Sink(ts[0]);
1515

16+
public static void SinkLastElem<T>(T[] ts) => Sink(ts[^1]);
17+
1618
public static void SinkListElem<T>(IList<T> list) => Sink(list[0]);
1719

1820
public static void SinkDictValue<T>(IDictionary<int, T> dict) => Sink(dict[0]);
@@ -21,6 +23,8 @@ public static void Sink<T>(T t) { }
2123

2224
public static T First<T>(T[] ts) => ts[0];
2325

26+
public static T Last<T>(T[] ts) => ts[^1];
27+
2428
public static T ListFirst<T>(IList<T> list) => list[0];
2529

2630
public static T DictIndexZero<T>(IDictionary<int, T> dict) => dict[0];
@@ -73,6 +77,15 @@ public void ArrayInitializerCSharp6NoFlow(A other)
7377
Sink(First(c.As)); // no flow
7478
}
7579

80+
public void ArrayInitializerImplicitIndexFlow()
81+
{
82+
var a = new A();
83+
var c = new CollectionFlow() { As = { [^1] = a } };
84+
Sink(c.As[^1]); // flow
85+
SinkLastElem(c.As); // flow
86+
Sink(Last(c.As)); // flow
87+
}
88+
7689
public void ArrayAssignmentFlow()
7790
{
7891
var a = new A();
@@ -93,6 +106,16 @@ public void ArrayAssignmentNoFlow(A other)
93106
Sink(First(@as)); // no flow
94107
}
95108

109+
public void ArrayAssignmentImplicitIndexFlow()
110+
{
111+
var a = new A();
112+
var @as = new A[1];
113+
@as[^1] = a;
114+
Sink(@as[^1]); // flow
115+
SinkLastElem(@as); // flow
116+
Sink(Last(@as)); // flow
117+
}
118+
96119
public void ListAssignmentFlow()
97120
{
98121
var a = new A();

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.expected

Lines changed: 797 additions & 731 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
3+
public class Container
4+
{
5+
public object[] Buffer { get; } = new object[10];
6+
}
7+
8+
public class TestIndex
9+
{
10+
public void M()
11+
{
12+
var c = new Container()
13+
{
14+
Buffer =
15+
{
16+
[0] = new object(),
17+
[1] = new object(),
18+
[^1] = new object()
19+
}
20+
};
21+
c.Buffer[4] = new object();
22+
c.Buffer[^3] = new object();
23+
}
24+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| Index.cs:18:18:18:19 | ^... | Index.cs:18:19:18:19 | 1 |
2+
| Index.cs:22:18:22:19 | ^... | Index.cs:22:19:22:19 | 3 |
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import csharp
2+
3+
from IndexExpr e
4+
select e, e.getExpr()

rust/README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ If you don't have the `semmle-code` repo you may need to install Bazel manually,
1111

1212
### Building the Rust Extractor
1313

14-
This approach uses a released `codeql` version and is simpler to use for QL development. From your `semmle-code` directory run:
14+
This approach uses a released `codeql` version and is simpler to use for QL development. From anywhere under your `semmle-code` or `codeql` directory you can run:
1515
```bash
1616
bazel run @codeql//rust:install
1717
```
18+
19+
You can use shorter versions of the above command:
20+
```bash
21+
bazel run //rust:install # if under the `codeql` checkout
22+
bazel run rust:install # if at the root of the `codeql` checkout
23+
bazel run :install # if at the `rust` directory of the `codeql` checkout
24+
```
25+
1826
You now need to create a [per-user CodeQL configuration file](https://docs.github.com/en/code-security/codeql-cli/using-the-advanced-functionality-of-the-codeql-cli/specifying-command-options-in-a-codeql-configuration-file#using-a-codeql-configuration-file) and specify the option:
1927
```
2028
--search-path PATH/TO/semmle-code/ql
@@ -40,4 +48,17 @@ TODO
4048

4149
### Code Generation
4250

43-
TODO
51+
If you make changes to either
52+
* `ast-generator/`, or
53+
* `schema/*.py`
54+
55+
you'll need to regenerate code. You can do so running
56+
```sh
57+
bazel run @codeql//rust/codegen
58+
```
59+
60+
Sometimes, especially if resolving conflicts on generated files, you might need to run
61+
```sh
62+
bazel run @codeql//rust/codegen -- --force
63+
```
64+
for code generation to succeed.

rust/ql/lib/codeql/rust/Concepts.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
private import codeql.rust.dataflow.DataFlow
88
private import codeql.threatmodels.ThreatModels
99
private import codeql.rust.Frameworks
10+
private import codeql.rust.dataflow.FlowSource
1011

1112
/**
1213
* A data flow source for a specific threat-model.
@@ -66,6 +67,13 @@ module CommandLineArgsSource {
6667
}
6768
}
6869

70+
/**
71+
* An externally modeled source for command line arguments.
72+
*/
73+
class ModeledCommandLineArgsSource extends CommandLineArgsSource::Range {
74+
ModeledCommandLineArgsSource() { sourceNode(this, "command-line-source") }
75+
}
76+
6977
/**
7078
* A data flow source corresponding to the program's environment.
7179
*/
@@ -85,6 +93,13 @@ module EnvironmentSource {
8593
}
8694
}
8795

96+
/**
97+
* An externally modeled source for data from the program's environment.
98+
*/
99+
class ModeledEnvironmentSource extends EnvironmentSource::Range {
100+
ModeledEnvironmentSource() { sourceNode(this, "environment-source") }
101+
}
102+
88103
/**
89104
* A data flow source for remote (network) data.
90105
*/
@@ -104,6 +119,13 @@ module RemoteSource {
104119
}
105120
}
106121

122+
/**
123+
* An externally modeled source for remote (network) data.
124+
*/
125+
class ModeledRemoteSource extends RemoteSource::Range {
126+
ModeledRemoteSource() { sourceNode(this, "remote") }
127+
}
128+
107129
/**
108130
* A data flow node that constructs a SQL statement (for later execution).
109131
*

rust/ql/lib/codeql/rust/Frameworks.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22
* This file imports all models of frameworks and libraries.
33
*/
44

5-
private import codeql.rust.frameworks.Reqwest
65
private import codeql.rust.frameworks.rustcrypto.RustCrypto
7-
private import codeql.rust.frameworks.stdlib.Env
86
private import codeql.rust.frameworks.Sqlx

rust/ql/lib/codeql/rust/frameworks/Reqwest.qll

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)