Skip to content

Commit 7666d85

Browse files
committed
Merge remote-tracking branch 'origin/main' into polynomial_redos
2 parents 4d5928a + 8fbe5c0 commit 7666d85

File tree

26 files changed

+565
-104
lines changed

26 files changed

+565
-104
lines changed

.devcontainer/post_attach.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -xe
33

44
echo "Check installed CodeQL version"
55
CURRENT_CODEQL_BIN=$(readlink -e /usr/local/bin/codeql || echo "")
6-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
6+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
77

88
BASE_DIR=/home/vscode/codeql-binaries
99
mkdir -p "${BASE_DIR}"

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- uses: actions/checkout@v2
7676
- name: Fetch CodeQL
7777
run: |
78-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
78+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
7979
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
8080
unzip -q codeql-linux64.zip
8181
env:
@@ -185,7 +185,7 @@ jobs:
185185
- name: Fetch CodeQL
186186
shell: bash
187187
run: |
188-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
188+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
189189
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql.zip "$LATEST"
190190
unzip -q codeql.zip
191191
env:

.github/workflows/dataset_measure.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- name: Fetch CodeQL
2727
run: |
28-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
28+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
2929
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
3030
unzip -q codeql-linux64.zip
3131
env:

.github/workflows/qhelp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
2424
- name: Fetch CodeQL
2525
run: |
26-
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | sort --version-sort | tail -1)
26+
LATEST=$(gh release list --repo https://github.com/github/codeql-cli-binaries | cut -f 1 | grep -v beta | sort --version-sort | tail -1)
2727
gh release download --repo https://github.com/github/codeql-cli-binaries --pattern codeql-linux64.zip "$LATEST"
2828
unzip -q codeql-linux64.zip
2929
env:

CODE_OF_CONDUCT.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as
6+
contributors and maintainers pledge to make participation in our project and
7+
our community a harassment-free experience for everyone, regardless of age, body
8+
size, disability, ethnicity, sex characteristics, gender identity and expression,
9+
level of experience, education, socio-economic status, nationality, personal
10+
appearance, race, religion, or sexual identity and orientation.
11+
12+
## Our Standards
13+
14+
Examples of behavior that contributes to creating a positive environment
15+
include:
16+
17+
* Using welcoming and inclusive language
18+
* Being respectful of differing viewpoints and experiences
19+
* Gracefully accepting constructive criticism
20+
* Focusing on what is best for the community
21+
* Showing empathy towards other community members
22+
23+
Examples of unacceptable behavior by participants include:
24+
25+
* The use of sexualized language or imagery and unwelcome sexual attention or
26+
advances
27+
* Trolling, insulting/derogatory comments, and personal or political attacks
28+
* Public or private harassment
29+
* Publishing others' private information, such as a physical or electronic
30+
address, without explicit permission
31+
* Other conduct which could reasonably be considered inappropriate in a
32+
professional setting
33+
34+
## Our Responsibilities
35+
36+
Project maintainers are responsible for clarifying the standards of acceptable
37+
behavior and are expected to take appropriate and fair corrective action in
38+
response to any instances of unacceptable behavior.
39+
40+
Project maintainers have the right and responsibility to remove, edit, or
41+
reject comments, commits, code, wiki edits, issues, and other contributions
42+
that are not aligned to this Code of Conduct, or to ban temporarily or
43+
permanently any contributor for other behaviors that they deem inappropriate,
44+
threatening, offensive, or harmful.
45+
46+
## Scope
47+
48+
This Code of Conduct applies within all project spaces, and it also applies when
49+
an individual is representing the project or its community in public spaces.
50+
Examples of representing a project or community include using an official
51+
project e-mail address, posting via an official social media account, or acting
52+
as an appointed representative at an online or offline event. Representation of
53+
a project may be further defined and clarified by project maintainers.
54+
55+
## Enforcement
56+
57+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58+
reported by contacting the project team at [email protected]. All
59+
complaints will be reviewed and investigated and will result in a response that
60+
is deemed necessary and appropriate to the circumstances. The project team is
61+
obligated to maintain confidentiality with regard to the reporter of an incident.
62+
Further details of specific enforcement policies may be posted separately.
63+
64+
Project maintainers who do not follow or enforce the Code of Conduct in good
65+
faith may face temporary or permanent repercussions as determined by other
66+
members of the project's leadership.
67+
68+
## Attribution
69+
70+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72+
73+
[homepage]: https://www.contributor-covenant.org
74+
75+
For answers to common questions about this code of conduct, see
76+
https://www.contributor-covenant.org/faq

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020-2021 GitHub
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

generator/src/ql.rs

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,13 @@ pub enum Expression<'a> {
127127
Or(Vec<Expression<'a>>),
128128
Equals(Box<Expression<'a>>, Box<Expression<'a>>),
129129
Dot(Box<Expression<'a>>, &'a str, Vec<Expression<'a>>),
130-
Aggregate(
131-
&'a str,
132-
Vec<FormalParameter<'a>>,
133-
Box<Expression<'a>>,
134-
Box<Expression<'a>>,
135-
),
130+
Aggregate {
131+
name: &'a str,
132+
vars: Vec<FormalParameter<'a>>,
133+
range: Option<Box<Expression<'a>>>,
134+
expr: Box<Expression<'a>>,
135+
second_expr: Option<Box<Expression<'a>>>,
136+
},
136137
}
137138

138139
impl<'a> fmt::Display for Expression<'a> {
@@ -188,15 +189,31 @@ impl<'a> fmt::Display for Expression<'a> {
188189
}
189190
write!(f, ")")
190191
}
191-
Expression::Aggregate(n, vars, range, term) => {
192-
write!(f, "{}(", n)?;
193-
for (index, var) in vars.iter().enumerate() {
194-
if index > 0 {
195-
write!(f, ", ")?;
192+
Expression::Aggregate {
193+
name,
194+
vars,
195+
range,
196+
expr,
197+
second_expr,
198+
} => {
199+
write!(f, "{}(", name)?;
200+
if vars.len() > 0 {
201+
for (index, var) in vars.iter().enumerate() {
202+
if index > 0 {
203+
write!(f, ", ")?;
204+
}
205+
write!(f, "{}", var)?;
196206
}
197-
write!(f, "{}", var)?;
207+
write!(f, " | ")?;
208+
}
209+
if let Some(range) = range {
210+
write!(f, "{} | ", range)?;
198211
}
199-
write!(f, " | {} | {})", range, term)
212+
write!(f, "{}", expr)?;
213+
if let Some(second_expr) = second_expr {
214+
write!(f, ", {}", second_expr)?;
215+
}
216+
write!(f, ")")
200217
}
201218
}
202219
}

generator/src/ql_gen.rs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@ pub fn create_ast_node_class<'a>(ast_node: &'a str, ast_node_parent: &'a str) ->
7979
Box::new(ql::Expression::String("???")),
8080
),
8181
};
82+
let get_primary_ql_classes = ql::Predicate {
83+
qldoc: Some(
84+
"Gets a comma-separated list of the names of the primary CodeQL \
85+
classes to which this element belongs."
86+
.to_owned(),
87+
),
88+
name: "getPrimaryQlClasses",
89+
overridden: false,
90+
return_type: Some(ql::Type::String),
91+
formal_parameters: vec![],
92+
body: ql::Expression::Equals(
93+
Box::new(ql::Expression::Var("result")),
94+
Box::new(ql::Expression::Aggregate {
95+
name: "concat",
96+
vars: vec![],
97+
range: None,
98+
expr: Box::new(ql::Expression::Pred("getAPrimaryQlClass", vec![])),
99+
second_expr: Some(Box::new(ql::Expression::String(","))),
100+
}),
101+
),
102+
};
82103
ql::Class {
83104
qldoc: Some(String::from("The base class for all AST nodes")),
84105
name: "AstNode",
@@ -92,6 +113,7 @@ pub fn create_ast_node_class<'a>(ast_node: &'a str, ast_node_parent: &'a str) ->
92113
get_parent_index,
93114
get_a_field_or_child,
94115
get_a_primary_ql_class,
116+
get_primary_ql_classes,
95117
],
96118
}
97119
}
@@ -410,15 +432,16 @@ fn create_field_getters<'a>(
410432
})
411433
.collect();
412434
(
413-
ql::Expression::Aggregate(
414-
"exists",
415-
vec![ql::FormalParameter {
435+
ql::Expression::Aggregate {
436+
name: "exists",
437+
vars: vec![ql::FormalParameter {
416438
name: "value",
417439
param_type: ql::Type::Int,
418440
}],
419-
Box::new(get_value),
420-
Box::new(ql::Expression::Or(disjuncts)),
421-
),
441+
range: Some(Box::new(get_value)),
442+
expr: Box::new(ql::Expression::Or(disjuncts)),
443+
second_expr: None,
444+
},
422445
// Since the getter returns a string and not an AstNode, it won't be part of getAFieldOrChild:
423446
None,
424447
)

ql/consistency-queries/AstConsistency.ql

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
import codeql.ruby.AST
22
import codeql.ruby.ast.internal.Synthesis
33

4-
private string getAPrimaryQlClass(AstNode node) {
5-
result = node.getAPrimaryQlClass()
6-
or
7-
not exists(node.getAPrimaryQlClass()) and result = "(none)"
8-
}
9-
104
query predicate missingParent(AstNode node, string cls) {
115
not exists(node.getParent()) and
126
node.getLocation().getFile().getExtension() != "erb" and
137
not node instanceof Toplevel and
14-
cls = getAPrimaryQlClass(node)
8+
cls = node.getPrimaryQlClasses()
159
}
1610

1711
pragma[noinline]
@@ -22,7 +16,7 @@ private AstNode parent(AstNode child, int desugarLevel) {
2216

2317
query predicate multipleParents(AstNode node, AstNode parent, string cls) {
2418
parent = node.getParent() and
25-
cls = getAPrimaryQlClass(parent) and
19+
cls = parent.getPrimaryQlClasses() and
2620
exists(AstNode one, AstNode two, int desugarLevel |
2721
one = parent(node, desugarLevel) and
2822
two = parent(node, desugarLevel) and

ql/lib/codeql/ruby/AST.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class AstNode extends TAstNode {
3232
*/
3333
string getAPrimaryQlClass() { result = "???" }
3434

35+
/**
36+
* Gets a comma-separated list of the names of the primary CodeQL classes to
37+
* which this element belongs.
38+
*/
39+
final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
40+
3541
/** Gets the enclosing module, if any. */
3642
ModuleBase getEnclosingModule() {
3743
exists(Scope::Range s |

0 commit comments

Comments
 (0)