Skip to content

Commit 296093d

Browse files
committed
Merge branch 'main' into nsstring
2 parents 343dded + 7f607fb commit 296093d

File tree

656 files changed

+11998
-4272
lines changed

Some content is hidden

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

656 files changed

+11998
-4272
lines changed

.github/actions/cache-query-compilation/action.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inputs:
99
outputs:
1010
cache-dir:
1111
description: "The directory where the cache was stored"
12-
value: ${{ steps.fill-compilation-dir.outputs.compdir }}
12+
value: ${{ steps.output-compilation-dir.outputs.compdir }}
1313

1414
runs:
1515
using: composite
@@ -27,7 +27,9 @@ runs:
2727
if: ${{ github.event_name == 'pull_request' }}
2828
uses: actions/cache/restore@v3
2929
with:
30-
path: '**/.cache'
30+
path: |
31+
**/.cache
32+
~/.codeql/compile-cache
3133
key: codeql-compile-${{ inputs.key }}-pr-${{ github.sha }}
3234
restore-keys: |
3335
codeql-compile-${{ inputs.key }}-${{ github.base_ref }}-${{ env.merge_base }}
@@ -37,12 +39,22 @@ runs:
3739
if: ${{ github.event_name != 'pull_request' }}
3840
uses: actions/cache@v3
3941
with:
40-
path: '**/.cache'
42+
path: |
43+
**/.cache
44+
~/.codeql/compile-cache
4145
key: codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-${{ github.sha }} # just fill on main
4246
restore-keys: | # restore the latest cache if the exact cache is unavailable, to speed up compilation.
4347
codeql-compile-${{ inputs.key }}-${{ github.ref_name }}-
4448
codeql-compile-${{ inputs.key }}-main-
49+
- name: Output-compilationdir
50+
id: output-compilation-dir
51+
shell: bash
52+
run: |
53+
echo "compdir=${COMBINED_CACHE_DIR}" >> $GITHUB_OUTPUT
54+
env:
55+
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
4556
- name: Fill compilation cache directory
57+
id: fill-compilation-dir
4658
uses: actions/github-script@v6
4759
env:
4860
COMBINED_CACHE_DIR: ${{ runner.temp }}/compilation-dir
@@ -58,6 +70,7 @@ runs:
5870
5971
const fs = require("fs");
6072
const path = require("path");
73+
const os = require("os");
6174
6275
// the first argv is the cache folder to create.
6376
const COMBINED_CACHE_DIR = process.env.COMBINED_CACHE_DIR;
@@ -97,6 +110,17 @@ runs:
97110
console.log(`Found .cache dir at ${dir}`);
98111
}
99112
113+
const globalCacheDir = path.join(os.homedir(), ".codeql", "compile-cache");
114+
if (fs.existsSync(globalCacheDir)) {
115+
console.log("Found global home dir: " + globalCacheDir);
116+
cacheDirs.push(globalCacheDir);
117+
}
118+
119+
if (cacheDirs.length === 0) {
120+
console.log("No cache dirs found");
121+
return;
122+
}
123+
100124
// mkdir -p ${COMBINED_CACHE_DIR}
101125
fs.mkdirSync(COMBINED_CACHE_DIR, { recursive: true });
102126

.github/workflows/swift.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ on:
55
paths:
66
- "swift/**"
77
- "misc/bazel/**"
8+
- "misc/codegen/**"
89
- "*.bazel*"
910
- .github/workflows/swift.yml
1011
- .github/actions/**
@@ -19,6 +20,7 @@ on:
1920
paths:
2021
- "swift/**"
2122
- "misc/bazel/**"
23+
- "misc/codegen/**"
2224
- "*.bazel*"
2325
- .github/workflows/swift.yml
2426
- .github/actions/**

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ repos:
5353
name: Run Swift code generation unit tests
5454
files: ^swift/codegen/.*\.py$
5555
language: system
56-
entry: bazel test //swift/codegen/test
56+
entry: bazel test //misc/codegen/test
5757
pass_filenames: false

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
/python/ @github/codeql-dynamic
77
/ruby/ @github/codeql-dynamic
88
/swift/ @github/codeql-swift
9+
/misc/codegen/ @github/codeql-swift
910
/java/kotlin-extractor/ @github/codeql-kotlin
1011
/java/kotlin-explorer/ @github/codeql-kotlin
1112

csharp/extractor/Semmle.Extraction.CSharp/SymbolExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,8 @@ private static IEnumerable<SyntaxToken> GetModifiers<T>(this ISymbol symbol, Fun
7777
/// <summary>
7878
/// Gets the source-level modifiers belonging to this symbol, if any.
7979
/// </summary>
80-
public static IEnumerable<string> GetSourceLevelModifiers(this ISymbol symbol)
81-
{
82-
var methodModifiers = symbol.GetModifiers<Microsoft.CodeAnalysis.CSharp.Syntax.BaseMethodDeclarationSyntax>(md => md.Modifiers);
83-
var typeModifiers = symbol.GetModifiers<Microsoft.CodeAnalysis.CSharp.Syntax.TypeDeclarationSyntax>(cd => cd.Modifiers);
84-
return methodModifiers.Concat(typeModifiers).Select(m => m.Text);
85-
}
80+
public static IEnumerable<string> GetSourceLevelModifiers(this ISymbol symbol) =>
81+
symbol.GetModifiers<Microsoft.CodeAnalysis.CSharp.Syntax.MemberDeclarationSyntax>(md => md.Modifiers).Select(m => m.Text);
8682

8783
/// <summary>
8884
/// Holds if the ID generated for `dependant` will contain a reference to
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The extraction of member modifiers has been generalised, which could lead to the extraction of more modifiers.

csharp/ql/lib/qlpack.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ upgrades: upgrades
88
dependencies:
99
codeql/ssa: ${workspace}
1010
codeql/tutorial: ${workspace}
11+
codeql/util: ${workspace}
1112
dataExtensions:
1213
- ext/*.model.yml
1314
- ext/generated/*.model.yml

csharp/ql/lib/semmle/code/csharp/File.qll

Lines changed: 16 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -3,184 +3,34 @@
33
*/
44

55
private import Comments
6+
private import codeql.util.FileSystem
67

7-
/** A file or folder. */
8-
class Container extends @container {
9-
/**
10-
* Gets the absolute, canonical path of this container, using forward slashes
11-
* as path separator.
12-
*
13-
* The path starts with a _root prefix_ followed by zero or more _path
14-
* segments_ separated by forward slashes.
15-
*
16-
* The root prefix is of one of the following forms:
17-
*
18-
* 1. A single forward slash `/` (Unix-style)
19-
* 2. An upper-case drive letter followed by a colon and a forward slash,
20-
* such as `C:/` (Windows-style)
21-
* 3. Two forward slashes, a computer name, and then another forward slash,
22-
* such as `//FileServer/` (UNC-style)
23-
*
24-
* Path segments are never empty (that is, absolute paths never contain two
25-
* contiguous slashes, except as part of a UNC-style root prefix). Also, path
26-
* segments never contain forward slashes, and no path segment is of the
27-
* form `.` (one dot) or `..` (two dots).
28-
*
29-
* Note that an absolute path never ends with a forward slash, except if it is
30-
* a bare root prefix, that is, the path has no path segments. A container
31-
* whose absolute path has no segments is always a `Folder`, not a `File`.
32-
*/
33-
string getAbsolutePath() { none() }
34-
35-
/**
36-
* Gets a URL representing the location of this container.
37-
*
38-
* For more information see [Providing URLs](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/#providing-urls).
39-
*/
40-
string getURL() { none() }
41-
42-
/**
43-
* Gets the relative path of this file or folder from the root folder of the
44-
* analyzed source location. The relative path of the root folder itself is
45-
* the empty string.
46-
*
47-
* This has no result if the container is outside the source root, that is,
48-
* if the root folder is not a reflexive, transitive parent of this container.
49-
*/
50-
string getRelativePath() {
51-
exists(string absPath, string pref |
52-
absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
53-
|
54-
absPath = pref and result = ""
55-
or
56-
absPath = pref.regexpReplaceAll("/$", "") + "/" + result and
57-
not result.matches("/%")
58-
)
59-
}
60-
61-
/**
62-
* Gets the base name of this container including extension, that is, the last
63-
* segment of its absolute path, or the empty string if it has no segments.
64-
*
65-
* Here are some examples of absolute paths and the corresponding base names
66-
* (surrounded with quotes to avoid ambiguity):
67-
*
68-
* <table border="1">
69-
* <tr><th>Absolute path</th><th>Base name</th></tr>
70-
* <tr><td>"/tmp/tst.cs"</td><td>"tst.cs"</td></tr>
71-
* <tr><td>"C:/Program Files (x86)"</td><td>"Program Files (x86)"</td></tr>
72-
* <tr><td>"/"</td><td>""</td></tr>
73-
* <tr><td>"C:/"</td><td>""</td></tr>
74-
* <tr><td>"D:/"</td><td>""</td></tr>
75-
* <tr><td>"//FileServer/"</td><td>""</td></tr>
76-
* </table>
77-
*/
78-
string getBaseName() {
79-
result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
80-
}
81-
82-
/**
83-
* Gets the extension of this container, that is, the suffix of its base name
84-
* after the last dot character, if any.
85-
*
86-
* In particular,
87-
*
88-
* - if the name does not include a dot, there is no extension, so this
89-
* predicate has no result;
90-
* - if the name ends in a dot, the extension is the empty string;
91-
* - if the name contains multiple dots, the extension follows the last dot.
92-
*
93-
* Here are some examples of absolute paths and the corresponding extensions
94-
* (surrounded with quotes to avoid ambiguity):
95-
*
96-
* <table border="1">
97-
* <tr><th>Absolute path</th><th>Extension</th></tr>
98-
* <tr><td>"/tmp/tst.cs"</td><td>"cs"</td></tr>
99-
* <tr><td>"/tmp/.classpath"</td><td>"classpath"</td></tr>
100-
* <tr><td>"/bin/bash"</td><td>not defined</td></tr>
101-
* <tr><td>"/tmp/tst2."</td><td>""</td></tr>
102-
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
103-
* </table>
104-
*/
105-
string getExtension() {
106-
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
107-
}
108-
109-
/**
110-
* Gets the stem of this container, that is, the prefix of its base name up to
111-
* (but not including) the last dot character if there is one, or the entire
112-
* base name if there is not.
113-
*
114-
* Here are some examples of absolute paths and the corresponding stems
115-
* (surrounded with quotes to avoid ambiguity):
116-
*
117-
* <table border="1">
118-
* <tr><th>Absolute path</th><th>Stem</th></tr>
119-
* <tr><td>"/tmp/tst.cs"</td><td>"tst"</td></tr>
120-
* <tr><td>"/tmp/.classpath"</td><td>""</td></tr>
121-
* <tr><td>"/bin/bash"</td><td>"bash"</td></tr>
122-
* <tr><td>"/tmp/tst2."</td><td>"tst2"</td></tr>
123-
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
124-
* </table>
125-
*/
126-
string getStem() {
127-
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
128-
}
129-
130-
/** Gets the parent container of this file or folder, if any. */
131-
Container getParentContainer() { containerparent(result, this) }
8+
private module Input implements InputSig {
9+
abstract class ContainerBase extends @container {
10+
abstract string getAbsolutePath();
13211

133-
/** Gets a file or sub-folder in this container. */
134-
Container getAChildContainer() { this = result.getParentContainer() }
12+
ContainerBase getParentContainer() { containerparent(result, this) }
13513

136-
/** Gets a file in this container. */
137-
File getAFile() { result = this.getAChildContainer() }
138-
139-
/** Gets the file in this container that has the given `baseName`, if any. */
140-
File getFile(string baseName) {
141-
result = this.getAFile() and
142-
result.getBaseName() = baseName
14+
string toString() { result = this.getAbsolutePath() }
14315
}
14416

145-
/** Gets a sub-folder in this container. */
146-
Folder getAFolder() { result = this.getAChildContainer() }
147-
148-
/** Gets the sub-folder in this container that has the given `baseName`, if any. */
149-
Folder getFolder(string baseName) {
150-
result = this.getAFolder() and
151-
result.getBaseName() = baseName
17+
class FolderBase extends ContainerBase, @folder {
18+
override string getAbsolutePath() { folders(this, result) }
15219
}
15320

154-
/** Gets the file or sub-folder in this container that has the given `name`, if any. */
155-
Container getChildContainer(string name) {
156-
result = this.getAChildContainer() and
157-
result.getBaseName() = name
21+
class FileBase extends ContainerBase, @file {
22+
override string getAbsolutePath() { files(this, result) }
15823
}
15924

160-
/** Gets the file in this container that has the given `stem` and `extension`, if any. */
161-
File getFile(string stem, string extension) {
162-
result = this.getAChildContainer() and
163-
result.getStem() = stem and
164-
result.getExtension() = extension
165-
}
25+
predicate hasSourceLocationPrefix = sourceLocationPrefix/1;
26+
}
16627

167-
/** Gets a sub-folder contained in this container. */
168-
Folder getASubFolder() { result = this.getAChildContainer() }
28+
private module Impl = Make<Input>;
16929

170-
/**
171-
* Gets a textual representation of the path of this container.
172-
*
173-
* This is the absolute path of the container.
174-
*/
175-
string toString() { result = this.getAbsolutePath() }
176-
}
30+
class Container = Impl::Container;
17731

17832
/** A folder. */
179-
class Folder extends Container, @folder {
180-
override string getAbsolutePath() { folders(this, result) }
181-
182-
override string getURL() { result = "folder://" + this.getAbsolutePath() }
183-
}
33+
class Folder extends Container, Impl::Folder { }
18434

18535
bindingset[flag]
18636
private predicate fileHasExtractionFlag(File f, int flag) {
@@ -191,9 +41,7 @@ private predicate fileHasExtractionFlag(File f, int flag) {
19141
}
19242

19343
/** A file. */
194-
class File extends Container, @file {
195-
override string getAbsolutePath() { files(this, result) }
196-
44+
class File extends Container, Impl::File {
19745
/** Gets the number of lines in this file. */
19846
int getNumberOfLines() { numlines(this, result, _, _) }
19947

csharp/ql/src/Telemetry/ExternalApi.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ private import semmle.code.csharp.dataflow.FlowSummary
88
private import semmle.code.csharp.dataflow.internal.DataFlowImplCommon as DataFlowImplCommon
99
private import semmle.code.csharp.dataflow.internal.DataFlowPrivate
1010
private import semmle.code.csharp.dataflow.internal.DataFlowDispatch as DataFlowDispatch
11+
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1112
private import semmle.code.csharp.dataflow.internal.TaintTrackingPrivate
1213
private import semmle.code.csharp.security.dataflow.flowsources.Remote
1314

@@ -104,8 +105,17 @@ class ExternalApi extends DotNet::Callable {
104105
pragma[nomagic]
105106
predicate isSink() { sinkNode(this.getAnInput(), _) }
106107

107-
/** Holds if this API is supported by existing CodeQL libraries, that is, it is either a recognized source or sink or has a flow summary. */
108-
predicate isSupported() { this.hasSummary() or this.isSource() or this.isSink() }
108+
/** Holds if this API is a known neutral. */
109+
pragma[nomagic]
110+
predicate isNeutral() { this instanceof FlowSummaryImpl::Public::NeutralCallable }
111+
112+
/**
113+
* Holds if this API is supported by existing CodeQL libraries, that is, it is either a
114+
* recognized source, sink or neutral or it has a flow summary.
115+
*/
116+
predicate isSupported() {
117+
this.hasSummary() or this.isSource() or this.isSink() or this.isNeutral()
118+
}
109119
}
110120

111121
/**

csharp/ql/src/Telemetry/SupportedExternalApis.ql

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
private import csharp
1010
private import semmle.code.csharp.dispatch.Dispatch
11-
private import semmle.code.csharp.dataflow.internal.FlowSummaryImpl as FlowSummaryImpl
1211
private import ExternalApi
1312

14-
private predicate relevant(ExternalApi api) {
15-
api.isSupported() or
16-
api instanceof FlowSummaryImpl::Public::NeutralCallable
17-
}
13+
private predicate relevant(ExternalApi api) { api.isSupported() }
1814

1915
from string info, int usages
2016
where Results<relevant/1>::restrict(info, usages)

0 commit comments

Comments
 (0)