Skip to content

Commit 490d22d

Browse files
committed
Merge remote-tracking branch 'upstream/main' into post-release-prep/codeql-cli-2.13.3
2 parents d2e1920 + 60a5ef7 commit 490d22d

File tree

360 files changed

+40424
-18063
lines changed

Some content is hidden

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

360 files changed

+40424
-18063
lines changed

.github/workflows/check-change-note.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
- "*/ql/lib/**/*.yml"
1212
- "!**/experimental/**"
1313
- "!ql/**"
14-
- "!swift/**"
1514
- ".github/workflows/check-change-note.yml"
1615

1716
jobs:
@@ -32,4 +31,4 @@ jobs:
3231
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3332
run: |
3433
gh api 'repos/${{github.repository}}/pulls/${{github.event.number}}/files' --paginate --jq '[.[].filename | select(test("/change-notes/.*[.]md$"))] | all(test("/change-notes/[0-9]{4}-[0-9]{2}-[0-9]{2}.*[.]md$") or test("/change-notes/released/[0-9]*[.][0-9]*[.][0-9]*[.]md$"))' |
35-
grep true -c
34+
grep true -c

.github/workflows/ql-for-ql-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
path: |
3333
ql/extractor-pack/
3434
ql/target/release/buramu
35-
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('ql/**/*.rs') }}
35+
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-extractor-${{ hashFiles('ql/**/Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ql/**/*.rs') }}
3636
- name: Cache cargo
3737
if: steps.cache-extractor.outputs.cache-hit != 'true'
3838
uses: actions/cache@v3

.github/workflows/ruby-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
ruby/extractor/target/release/codeql-extractor-ruby
6262
ruby/extractor/target/release/codeql-extractor-ruby.exe
6363
ruby/extractor/ql/lib/codeql/ruby/ast/internal/TreeSitter.qll
64-
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/Cargo.lock') }}--${{ hashFiles('ruby/extractor/**/*.rs') }}
64+
key: ${{ runner.os }}-${{ steps.os_version.outputs.version }}-ruby-extractor-${{ hashFiles('ruby/extractor/rust-toolchain.toml', 'ruby/extractor/Cargo.lock') }}-${{ hashFiles('shared/tree-sitter-extractor') }}-${{ hashFiles('ruby/extractor/**/*.rs') }}
6565
- uses: actions/cache@v3
6666
if: steps.cache-extractor.outputs.cache-hit != 'true'
6767
with:

.github/workflows/sync-files.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ jobs:
1717
- uses: actions/checkout@v3
1818
- name: Check synchronized files
1919
run: python config/sync-files.py
20+
- name: Check dbscheme fragments
21+
run: python config/sync-dbscheme-fragments.py
2022

config/dbscheme-fragments.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"files": [
3+
"javascript/ql/lib/semmlecode.javascript.dbscheme",
4+
"python/ql/lib/semmlecode.python.dbscheme",
5+
"ruby/ql/lib/ruby.dbscheme",
6+
"ql/ql/src/ql.dbscheme"
7+
],
8+
"fragments": [
9+
"/*- External data -*/",
10+
"/*- Files and folders -*/",
11+
"/*- Diagnostic messages -*/",
12+
"/*- Diagnostic messages: severity -*/",
13+
"/*- Source location prefix -*/",
14+
"/*- Lines of code -*/",
15+
"/*- Configuration files with key value pairs -*/",
16+
"/*- YAML -*/",
17+
"/*- XML Files -*/",
18+
"/*- XML: sourceline -*/",
19+
"/*- DEPRECATED: External defects and metrics -*/",
20+
"/*- DEPRECATED: Snapshot date -*/",
21+
"/*- DEPRECATED: Duplicate code -*/",
22+
"/*- DEPRECATED: Version control data -*/",
23+
"/*- JavaScript-specific part -*/",
24+
"/*- Ruby dbscheme -*/",
25+
"/*- Erb dbscheme -*/",
26+
"/*- QL dbscheme -*/",
27+
"/*- Dbscheme dbscheme -*/",
28+
"/*- Yaml dbscheme -*/",
29+
"/*- Blame dbscheme -*/",
30+
"/*- JSON dbscheme -*/",
31+
"/*- Python dbscheme -*/"
32+
]
33+
}

config/sync-dbscheme-fragments.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/env python3
2+
3+
import argparse
4+
import json
5+
import os
6+
import pathlib
7+
import re
8+
9+
10+
def make_groups(blocks):
11+
groups = {}
12+
for block in blocks:
13+
groups.setdefault("".join(block["lines"]), []).append(block)
14+
return list(groups.values())
15+
16+
17+
def validate_fragments(fragments):
18+
ok = True
19+
for header, blocks in fragments.items():
20+
groups = make_groups(blocks)
21+
if len(groups) > 1:
22+
ok = False
23+
print("Warning: dbscheme fragments with header '{}' are different for {}".format(header, ["{}:{}:{}".format(
24+
group[0]["file"], group[0]["start"], group[0]["end"]) for group in groups]))
25+
return ok
26+
27+
28+
def main():
29+
script_path = os.path.realpath(__file__)
30+
script_dir = os.path.dirname(script_path)
31+
parser = argparse.ArgumentParser(
32+
prog=os.path.basename(script_path),
33+
description='Sync dbscheme fragments across files.'
34+
)
35+
parser.add_argument('files', metavar='dbscheme_file', type=pathlib.Path, nargs='*', default=[],
36+
help='dbscheme files to check')
37+
args = parser.parse_args()
38+
39+
with open(os.path.join(script_dir, "dbscheme-fragments.json"), "r") as f:
40+
config = json.load(f)
41+
42+
fragment_headers = set(config["fragments"])
43+
fragments = {}
44+
ok = True
45+
for file in args.files + config["files"]:
46+
with open(os.path.join(os.path.dirname(script_dir), file), "r") as dbscheme:
47+
header = None
48+
line_number = 1
49+
block = {"file": file, "start": line_number,
50+
"end": None, "lines": []}
51+
52+
def end_block():
53+
block["end"] = line_number - 1
54+
if len(block["lines"]) > 0:
55+
if header is None:
56+
if re.match(r'(?m)\A(\s|//.*$|/\*(\**[^\*])*\*+/)*\Z', "".join(block["lines"])):
57+
# Ignore comments at the beginning of the file
58+
pass
59+
else:
60+
ok = False
61+
print("Warning: dbscheme fragment without header: {}:{}:{}".format(
62+
block["file"], block["start"], block["end"]))
63+
else:
64+
fragments.setdefault(header, []).append(block)
65+
for line in dbscheme:
66+
m = re.match(r"^\/\*-.*-\*\/$", line)
67+
if m:
68+
end_block()
69+
header = line.strip()
70+
if header not in fragment_headers:
71+
ok = False
72+
print("Warning: unknown header for dbscheme fragment: '{}': {}:{}".format(
73+
header, file, line_number))
74+
block = {"file": file, "start": line_number,
75+
"end": None, "lines": []}
76+
block["lines"].append(line)
77+
line_number += 1
78+
block["lines"].append('\n')
79+
line_number += 1
80+
end_block()
81+
if not ok or not validate_fragments(fragments):
82+
exit(1)
83+
84+
85+
if __name__ == "__main__":
86+
main()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ class IndirectOperand extends Node {
210210
this.(RawIndirectOperand).getOperand() = operand and
211211
this.(RawIndirectOperand).getIndirectionIndex() = indirectionIndex
212212
or
213-
this.(OperandNode).getOperand() =
214-
Ssa::getIRRepresentationOfIndirectOperand(operand, indirectionIndex)
213+
nodeHasOperand(this, Ssa::getIRRepresentationOfIndirectOperand(operand, indirectionIndex),
214+
indirectionIndex - 1)
215215
}
216216

217217
/** Gets the underlying operand. */
@@ -250,8 +250,8 @@ class IndirectInstruction extends Node {
250250
this.(RawIndirectInstruction).getInstruction() = instr and
251251
this.(RawIndirectInstruction).getIndirectionIndex() = indirectionIndex
252252
or
253-
this.(InstructionNode).getInstruction() =
254-
Ssa::getIRRepresentationOfIndirectInstruction(instr, indirectionIndex)
253+
nodeHasInstruction(this, Ssa::getIRRepresentationOfIndirectInstruction(instr, indirectionIndex),
254+
indirectionIndex - 1)
255255
}
256256

257257
/** Gets the underlying instruction. */

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,15 @@ predicate localInstructionFlow(Instruction e1, Instruction e2) {
16401640
localFlow(instructionNode(e1), instructionNode(e2))
16411641
}
16421642

1643+
/**
1644+
* INTERNAL: Do not use.
1645+
*
1646+
* Ideally this module would be private, but the `asExprInternal` predicate is
1647+
* needed in `DefaultTaintTrackingImpl`. Once `DefaultTaintTrackingImpl` is gone
1648+
* we can make this module private.
1649+
*/
16431650
cached
1644-
private module ExprFlowCached {
1651+
module ExprFlowCached {
16451652
/**
16461653
* Holds if `n` is an indirect operand of a `PointerArithmeticInstruction`, and
16471654
* `e` is the result of loading from the `PointerArithmeticInstruction`.
@@ -1692,7 +1699,8 @@ private module ExprFlowCached {
16921699
* `x[i]` steps to the expression `x[i - 1]` without traversing the
16931700
* entire chain.
16941701
*/
1695-
private Expr asExpr(Node n) {
1702+
cached
1703+
Expr asExprInternal(Node n) {
16961704
isIndirectBaseOfArrayAccess(n, result)
16971705
or
16981706
not isIndirectBaseOfArrayAccess(n, _) and
@@ -1704,7 +1712,7 @@ private module ExprFlowCached {
17041712
* dataflow step.
17051713
*/
17061714
private predicate localStepFromNonExpr(Node n1, Node n2) {
1707-
not exists(asExpr(n1)) and
1715+
not exists(asExprInternal(n1)) and
17081716
localFlowStep(n1, n2)
17091717
}
17101718

@@ -1715,7 +1723,7 @@ private module ExprFlowCached {
17151723
pragma[nomagic]
17161724
private predicate localStepsToExpr(Node n1, Node n2, Expr e2) {
17171725
localStepFromNonExpr*(n1, n2) and
1718-
e2 = asExpr(n2)
1726+
e2 = asExprInternal(n2)
17191727
}
17201728

17211729
/**
@@ -1726,7 +1734,7 @@ private module ExprFlowCached {
17261734
exists(Node mid |
17271735
localFlowStep(n1, mid) and
17281736
localStepsToExpr(mid, n2, e2) and
1729-
e1 = asExpr(n1)
1737+
e1 = asExprInternal(n1)
17301738
)
17311739
}
17321740

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private DataFlow::Node getNodeForSource(Expr source) {
6060
}
6161

6262
private DataFlow::Node getNodeForExpr(Expr node) {
63-
result = DataFlow::exprNode(node)
63+
node = DataFlow::ExprFlowCached::asExprInternal(result)
6464
or
6565
// Some of the sources in `isUserInput` are intended to match the value of
6666
// an expression, while others (those modeled below) are intended to match
@@ -221,7 +221,7 @@ private module Cached {
221221
predicate nodeIsBarrierIn(DataFlow::Node node) {
222222
// don't use dataflow into taint sources, as this leads to duplicate results.
223223
exists(Expr source | isUserInput(source, _) |
224-
node = DataFlow::exprNode(source)
224+
source = DataFlow::ExprFlowCached::asExprInternal(node)
225225
or
226226
// This case goes together with the similar (but not identical) rule in
227227
// `getNodeForSource`.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Print the dataflow local store steps in IR dumps.
3+
*/
4+
5+
private import cpp
6+
private import semmle.code.cpp.ir.IR
7+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowUtil
8+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
9+
private import PrintIRUtilities
10+
11+
/** A property provider for local IR dataflow store steps. */
12+
class FieldFlowPropertyProvider extends IRPropertyProvider {
13+
override string getOperandProperty(Operand operand, string key) {
14+
exists(PostFieldUpdateNode pfun, Content content |
15+
key = "store " + content.toString() and
16+
operand = pfun.getPreUpdateNode().(IndirectOperand).getOperand() and
17+
result =
18+
strictconcat(string element, Node node |
19+
storeStep(node, content, pfun) and
20+
element = nodeId(node, _, _)
21+
|
22+
element, ", "
23+
)
24+
)
25+
or
26+
exists(Node node2, Content content |
27+
key = "read " + content.toString() and
28+
operand = node2.(IndirectOperand).getOperand() and
29+
result =
30+
strictconcat(string element, Node node1 |
31+
readStep(node1, content, node2) and
32+
element = nodeId(node1, _, _)
33+
|
34+
element, ", "
35+
)
36+
)
37+
}
38+
}

0 commit comments

Comments
 (0)