Skip to content

Commit 6c1d219

Browse files
author
Dave Bartolomeo
committed
Merge from master
2 parents a9e3bfb + c5396d9 commit 6c1d219

File tree

302 files changed

+12256
-7011
lines changed

Some content is hidden

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

302 files changed

+12256
-7011
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to QL
1+
# Contributing to CodeQL
22

33
We welcome contributions to our standard library and standard checks. Got an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request!
44

@@ -9,13 +9,13 @@ Before we accept your pull request, we require that you have agreed to our Contr
99
If you have an idea for a query that you would like to share with other Semmle users, please open a pull request to add it to this repository.
1010
Follow the steps below to help other users understand what your query does, and to ensure that your query is consistent with the other Semmle queries.
1111

12-
1. **Consult the QL documentation for query writers**
12+
1. **Consult the documentation for query writers**
1313

14-
There is lots of useful documentation to help you write QL, ranging from information about query file structure to language-specific tutorials. For more information on the documentation available, see [Writing QL queries](https://help.semmle.com/QL/learn-ql/writing-queries/writing-queries.html) on [help.semmle.com](https://help.semmle.com).
14+
There is lots of useful documentation to help you write queries, ranging from information about query file structure to tutorials for specific target languages. For more information on the documentation available, see [Writing CodeQL queries](https://help.semmle.com/QL/learn-ql/writing-queries/writing-queries.html) on [help.semmle.com](https://help.semmle.com).
1515

16-
2. **Format your QL correctly**
16+
2. **Format your code correctly**
1717

18-
All of Semmle's standard QL queries and libraries are uniformly formatted for clarity and consistency, so we strongly recommend that all QL contributions follow the same formatting guidelines. If you use QL for Eclipse, you can auto-format your query in the [QL editor](https://help.semmle.com/ql-for-eclipse/Content/WebHelp/ql-editor.html). For more information, see the [QL style guide](https://github.com/Semmle/ql/blob/master/docs/ql-style-guide.md).
18+
All of Semmle's standard queries and libraries are uniformly formatted for clarity and consistency, so we strongly recommend that all contributions follow the same formatting guidelines. If you use QL for Eclipse, you can auto-format your query in the [QL editor](https://help.semmle.com/ql-for-eclipse/Content/WebHelp/ql-editor.html). For more information, see the [CodeQL style guide](https://github.com/Semmle/ql/blob/master/docs/ql-style-guide.md).
1919

2020
3. **Make sure your query has the correct metadata**
2121

@@ -29,7 +29,7 @@ Follow the steps below to help other users understand what your query does, and
2929
The `select` statement of your query must be compatible with the query type (determined by the `@kind` metadata property) for alert or path results to be displayed correctly in LGTM and QL for Eclipse.
3030
For more information on `select` statement format, see [Introduction to query files](https://help.semmle.com/QL/learn-ql/writing-queries/introduction-to-queries.html#select-clause) on help.semmle.com.
3131

32-
5. **Save your query in a `.ql` file in correct language directory in this repository**
32+
5. **Save your query in a `.ql` file in the correct language directory in this repository**
3333

3434
There are five language-specific directories in this repository:
3535

@@ -54,7 +54,7 @@ repositories, which might be made public. We might also use this information
5454
to contact you in relation to your contributions, as well as in the
5555
normal course of software development. We also store records of your
5656
CLA agreements. Under GDPR legislation, we do this
57-
on the basis of our legitimate interest in creating the QL product.
57+
on the basis of our legitimate interest in creating the CodeQL product.
5858

5959
Please do get in touch (privacy@semmle.com) if you have any questions about
6060
this or our data protection policies.

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
# Semmle QL
1+
# CodeQL
22

3-
This open source repository contains the standard QL libraries and queries that power [LGTM](https://lgtm.com), and the other products that [Semmle](https://semmle.com) makes available to its customers worldwide.
3+
This open source repository contains the standard CodeQL libraries and queries that power [LGTM](https://lgtm.com), and the other products that [Semmle](https://semmle.com) makes available to its customers worldwide.
44

5-
## How do I learn QL and run queries?
5+
## How do I learn CodeQL and run queries?
66

7-
There is [extensive documentation](https://help.semmle.com/QL/learn-ql/) on getting started with writing QL.
8-
You can use the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) on LGTM.com or the [QL for Eclipse](https://lgtm.com/help/lgtm/running-queries-ide) plugin to try out your queries on any open-source project that's currently being analyzed.
7+
There is [extensive documentation](https://help.semmle.com/QL/learn-ql/) on getting started with writing CodeQL.
8+
You can use the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) on LGTM.com or the [QL for Eclipse](https://lgtm.com/help/lgtm/running-queries-ide) plugin to try out your queries on any open source project that's currently being analyzed.
99

1010
## Contributing
1111

12-
We welcome contributions to our standard library and standard checks. Do you have an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request! Before you do, though, please take the time to read our [contributing guidelines](CONTRIBUTING.md). You can also consult our [style guides](https://github.com/Semmle/ql/tree/master/docs) to learn how to format your QL for consistency and clarity, how to write query metadata, and how to write query help documentation for your query.
12+
We welcome contributions to our standard library and standard checks. Do you have an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request! Before you do, though, please take the time to read our [contributing guidelines](CONTRIBUTING.md). You can also consult our [style guides](https://github.com/Semmle/ql/tree/master/docs) to learn how to format your code for consistency and clarity, how to write query metadata, and how to write query help documentation for your query.
1313

1414
## License
1515

16-
The QL queries in this repository are licensed under [Apache License 2.0](LICENSE) by [Semmle](https://semmle.com).
16+
The code in this repository is licensed under [Apache License 2.0](LICENSE) by [Semmle](https://semmle.com).

change-notes/1.23/analysis-cpp.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The following changes in version 1.23 affect C/C++ analysis in all applications.
2424
| Unclear comparison precedence (`cpp/comparison-precedence`) | Fewer false positive results | False positives involving template classes and functions have been fixed. |
2525
| Comparison of narrow type with wide type in loop condition (`cpp/comparison-with-wider-type`) | Higher precision | The precision of this query has been increased to "high" as the alerts from this query have proved to be valuable on real-world projects. With this precision, results are now displayed by default in LGTM. |
2626

27-
## Changes to QL libraries
27+
## Changes to libraries
2828

2929
* The data-flow library has been extended with a new feature to aid debugging.
3030
Instead of specifying `isSink(Node n) { any() }` on a configuration to
@@ -54,3 +54,8 @@ The following changes in version 1.23 affect C/C++ analysis in all applications.
5454
lead to regressions (or improvements) in how queries are optimized because
5555
optimization in QL relies on static size estimates, and the control-flow edge
5656
relations will now have different size estimates than before.
57+
* Support has been added for non-type template arguments. This means that the
58+
return type of `Declaration::getTemplateArgument()` and
59+
`Declaration::getATemplateArgument` have changed to `Locatable`. See the
60+
documentation for `Declaration::getTemplateArgument()` and
61+
`Declaration::getTemplateArgumentKind()` for details.

change-notes/1.23/analysis-csharp.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ The following changes in version 1.23 affect C# analysis in all applications.
99
| **Query** | **Tags** | **Purpose** |
1010
|-----------------------------|-----------|--------------------------------------------------------------------|
1111
| Deserialized delegate (`cs/deserialized-delegate`) | security, external/cwe/cwe-502 | Finds unsafe deserialization of delegate types. |
12+
| Deserialization of untrusted data (`cs/unsafe-deserialization-untrusted-input`) | security, external/cwe/cwe-502 | Finds flow of untrusted input to calls to unsafe deserializers. |
1213
| Unsafe year argument for 'DateTime' constructor (`cs/unsafe-year-construction`) | reliability, date-time | Finds incorrect manipulation of `DateTime` values, which could lead to invalid dates. |
14+
| Unsafe deserializer (`cs/unsafe-deserialization`) | security, external/cwe/cwe-502 | Finds calls to unsafe deserializers. |
1315
| Mishandling the Japanese era start date (`cs/mishandling-japanese-era`) | reliability, date-time | Finds hard-coded Japanese era start dates that could be invalid. |
1416

1517
## Changes to existing queries
@@ -25,7 +27,7 @@ The following changes in version 1.23 affect C# analysis in all applications.
2527

2628
* `nameof` expressions are now extracted correctly when the name is a namespace.
2729

28-
## Changes to QL libraries
30+
## Changes to libraries
2931

3032
* The new class `NamespaceAccess` models accesses to namespaces, for example in `nameof` expressions.
3133
* The data-flow library now makes it easier to specify barriers/sanitizers

change-notes/1.23/analysis-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The following changes in version 1.23 affect Java analysis in all applications.
1919
| Query built without neutralizing special characters (`java/concatenated-sql-query`) | More results | The query now identifies arguments to `Statement.executeLargeUpdate` and `Connection.prepareCall` as SQL expressions sinks. |
2020
| Useless comparison test (`java/constant-comparison`) | Fewer false positives | Additional overflow check patterns are now recognized and no longer reported. |
2121

22-
## Changes to QL libraries
22+
## Changes to libraries
2323

2424
* The data-flow library has been extended with a new feature to aid debugging.
2525
Instead of specifying `isSink(Node n) { any() }` on a configuration to

change-notes/1.23/analysis-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
| Uncontrolled data used in path expression (`js/path-injection`) | Fewer false-positive results | This query now recognizes calls to Express `sendFile` as safe in some cases. |
5050
| Unknown directive (`js/unknown-directive`) | Fewer false positive results | This query no longer flags uses of ":", which is sometimes used like a directive. |
5151

52-
## Changes to QL libraries
52+
## Changes to libraries
5353

5454
* `Expr.getDocumentation()` now handles chain assignments.
5555

change-notes/support/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Files moved to ``docs`` directory
22

3-
Now that all of the QL documentation is in this repository,
3+
Now that all of the CodeQL documentation is in this repository,
44
notes on the languages, compilers, and frameworks supported have moved.
55
They're now stored as part of the Sphinx ``support`` project with the other documentation:
66
``docs/language/support``.

cpp/ql/src/semmle/code/cpp/Class.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -605,15 +605,6 @@ class Class extends UserType {
605605
class_instantiation(underlyingElement(this), unresolveElement(c))
606606
}
607607

608-
/**
609-
* Gets the `i`th template argument used to instantiate this class from a
610-
* class template. When called on a class template, this will return the
611-
* `i`th template parameter.
612-
*/
613-
override Type getTemplateArgument(int i) {
614-
class_template_argument(underlyingElement(this), i, unresolveElement(result))
615-
}
616-
617608
/**
618609
* Holds if this class/struct is polymorphic (has a virtual function, or
619610
* inherits one).
@@ -623,7 +614,7 @@ class Class extends UserType {
623614
}
624615

625616
override predicate involvesTemplateParameter() {
626-
getATemplateArgument().involvesTemplateParameter()
617+
getATemplateArgument().(Type).involvesTemplateParameter()
627618
}
628619

629620
/** Holds if this class, struct or union was declared 'final'. */

cpp/ql/src/semmle/code/cpp/Declaration.qll

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,83 @@ abstract class Declaration extends Locatable, @declaration {
193193

194194
/**
195195
* Gets a template argument used to instantiate this declaration from a template.
196-
* When called on a template, this will return a template parameter.
196+
* When called on a template, this will return a template parameter type for
197+
* both typed and non-typed parameters.
197198
*/
198-
final Type getATemplateArgument() { result = getTemplateArgument(_) }
199+
final Locatable getATemplateArgument() { result = getTemplateArgument(_) }
200+
201+
/**
202+
* Gets a template argument used to instantiate this declaration from a template.
203+
* When called on a template, this will return a non-typed template
204+
* parameter value.
205+
*/
206+
final Locatable getATemplateArgumentKind() { result = getTemplateArgumentKind(_) }
199207

200208
/**
201209
* Gets the `i`th template argument used to instantiate this declaration from a
202-
* template. When called on a template, this will return the `i`th template parameter.
210+
* template.
211+
*
212+
* For example:
213+
*
214+
* `template<typename T, T X> class Foo;`
215+
*
216+
* Will have `getTemplateArgument(0)` return `T`, and
217+
* `getTemplateArgument(1)` return `X`.
218+
*
219+
* `Foo<int, 1> bar;
220+
*
221+
* Will have `getTemplateArgument())` return `int`, and
222+
* `getTemplateArgument(1)` return `1`.
203223
*/
204-
Type getTemplateArgument(int index) { none() }
224+
final Locatable getTemplateArgument(int index) {
225+
if exists(getTemplateArgumentValue(index))
226+
then result = getTemplateArgumentValue(index)
227+
else result = getTemplateArgumentType(index)
228+
}
229+
230+
/**
231+
* Gets the `i`th template argument value used to instantiate this declaration
232+
* from a template. When called on a template, this will return the `i`th template
233+
* parameter value if it exists.
234+
*
235+
* For example:
236+
*
237+
* `template<typename T, T X> class Foo;`
238+
*
239+
* Will have `getTemplateArgumentKind(1)` return `T`, and no result for
240+
* `getTemplateArgumentKind(0)`.
241+
*
242+
* `Foo<int, 10> bar;
243+
*
244+
* Will have `getTemplateArgumentKind(1)` return `int`, and no result for
245+
* `getTemplateArgumentKind(0)`.
246+
*/
247+
final Locatable getTemplateArgumentKind(int index) {
248+
if exists(getTemplateArgumentValue(index))
249+
then result = getTemplateArgumentType(index)
250+
else none()
251+
}
205252

206253
/** Gets the number of template arguments for this declaration. */
207254
final int getNumberOfTemplateArguments() {
208255
result = count(int i | exists(getTemplateArgument(i)))
209256
}
257+
258+
private Type getTemplateArgumentType(int index) {
259+
class_template_argument(underlyingElement(this), index, unresolveElement(result))
260+
or
261+
function_template_argument(underlyingElement(this), index, unresolveElement(result))
262+
or
263+
variable_template_argument(underlyingElement(this), index, unresolveElement(result))
264+
}
265+
266+
private Expr getTemplateArgumentValue(int index) {
267+
class_template_argument_value(underlyingElement(this), index, unresolveElement(result))
268+
or
269+
function_template_argument_value(underlyingElement(this), index, unresolveElement(result))
270+
or
271+
variable_template_argument_value(underlyingElement(this), index, unresolveElement(result))
272+
}
210273
}
211274

212275
/**

cpp/ql/src/semmle/code/cpp/Function.qll

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,6 @@ class Function extends Declaration, ControlFlowNode, AccessHolder, @function {
343343
function_instantiation(underlyingElement(this), unresolveElement(f))
344344
}
345345

346-
/**
347-
* Gets the `i`th template argument used to instantiate this function from a
348-
* function template. When called on a function template, this will return the
349-
* `i`th template parameter.
350-
*/
351-
override Type getTemplateArgument(int index) {
352-
function_template_argument(underlyingElement(this), index, unresolveElement(result))
353-
}
354-
355346
/**
356347
* Holds if this function is defined in several files. This is illegal in
357348
* C (though possible in some C++ compilers), and likely indicates that

0 commit comments

Comments
 (0)