Skip to content

Commit fa710c5

Browse files
committed
Merge remote-tracking branch 'upstream/master' into UrlSearch
2 parents da28d3b + a1e032b commit fa710c5

File tree

1,228 files changed

+77737
-43238
lines changed

Some content is hidden

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

1,228 files changed

+77737
-43238
lines changed

.codeqlmanifest.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
"*/ql/test/qlpack.yml",
33
"*/upgrades/qlpack.yml",
44
"misc/legacy-support/*/qlpack.yml",
5-
"misc/suite-helpers/qlpack.yml",
6-
"codeql/.codeqlmanifest.json" ] }
5+
"misc/suite-helpers/qlpack.yml" ] }

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# editor and OS artifacts
22
*~
33
.DS_STORE
4+
*.swp
45

56
# query compilation caches
67
.cache

CONTRIBUTING.md

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,65 @@
11
# Contributing to CodeQL
22

3-
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!
3+
We welcome contributions to our CodeQL libraries and queries. Got an idea for a new check, or how to improve an existing query? Then please go ahead and open a pull request!
44

5-
Before we accept your pull request, we require that you have agreed to our Contributor License Agreement, this is not something that you need to do before you submit your pull request, but until you've done so, we will be unable to accept your contribution.
5+
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).
66

7-
## Adding a new query
87

9-
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.
10-
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.
8+
## Submitting a new experimental query
119

12-
1. **Consult the documentation for query writers**
10+
If you have an idea for a query that you would like to share with other CodeQL users, please open a pull request to add it to this repository. New queries start out in a `<language>/ql/src/experimental` directory, to which they can be merged when they meet the following requirements.
1311

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).
12+
1. **Directory structure**
1513

16-
2. **Format your code correctly**
14+
There are five language-specific query directories in this repository:
1715

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 CodeQL for VS Code, you can autoformat your query in the [Editor](https://help.semmle.com/codeql/codeql-for-vscode/reference/editor.html#autoformatting). For more information, see the [CodeQL style guide](https://github.com/Semmle/ql/blob/master/docs/ql-style-guide.md).
16+
* C/C++: `cpp/ql/src`
17+
* C#: `csharp/ql/src`
18+
* Java: `java/ql/src`
19+
* JavaScript: `javascript/ql/src`
20+
* Python: `python/ql/src`
1921

20-
3. **Make sure your query has the correct metadata**
22+
Each language-specific directory contains further subdirectories that group queries based on their `@tags` or purpose.
23+
- Experimental queries and libraries are stored in the `experimental` subdirectory within each language-specific directory in the [CodeQL repository](https://github.com/Semmle/ql). For example, experimental Java queries and libraries are stored in `java/ql/src/experimental` and any corresponding tests in `java/ql/test/experimental`.
24+
- The structure of an `experimental` subdirectory mirrors the structure of its parent directory.
25+
- Select or create an appropriate directory in `experimental` based on the existing directory structure of `experimental` or its parent directory.
2126

22-
Query metadata is used by Semmle's analysis to identify your query and make sure the query results are displayed properly.
23-
The most important metadata to include are the `@name`, `@description`, and the `@kind`.
24-
Other metadata properties (`@precision`, `@severity`, and `@tags`) are usually added after the query has been reviewed by Semmle staff.
25-
For more information on writing query metadata, see the [Query metadata style guide](https://github.com/Semmle/ql/blob/master/docs/query-metadata-style-guide.md).
27+
2. **Query metadata**
2628

27-
4. **Make sure the `select` statement is compatible with the query type**
29+
- The query `@id` must conform to all the requirements in the [guide on query metadata](docs/query-metadata-style-guide.md#query-id-id). In particular, it must not clash with any other queries in the repository, and it must start with the appropriate language-specific prefix.
30+
- The query must have a `@name` and `@description` to explain its purpose.
31+
- The query must have a `@kind` and `@problem.severity` as required by CodeQL tools.
2832

29-
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 CodeQL for VS Code.
30-
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.
33+
For details, see the [guide on query metadata](docs/query-metadata-style-guide.md).
3134

32-
5. **Save your query in a `.ql` file in the correct language directory in this repository**
35+
Make sure the `select` statement is compatible with the query `@kind`. See [Introduction to query files](https://help.semmle.com/QL/learn-ql/writing-queries/introduction-to-queries.html#select-clause) on help.semmle.com.
3336

34-
There are five language-specific directories in this repository:
35-
36-
* C/C++: `ql/cpp/ql/src`
37-
* C#: `ql/csharp/ql/src`
38-
* Java: `ql/java/ql/src`
39-
* JavaScript: `ql/javascript/ql/src`
40-
* Python: `ql/python/ql/src`
37+
3. **Formatting**
4138

42-
Each language-specific directory contains further subdirectories that group queries based on their `@tags` properties or purpose. Select the appropriate subdirectory for your new query, or create a new one if necessary.
39+
- The queries and libraries must be [autoformatted](https://help.semmle.com/codeql/codeql-for-vscode/reference/editor.html#autoformatting).
4340

44-
6. **Write a query help file**
41+
4. **Compilation**
4542

46-
Query help files explain the purpose of your query to other users. Write your query help in a `.qhelp` file and save it in the same directory as your new query.
47-
For more information on writing query help, see the [Query help style guide](https://github.com/Semmle/ql/blob/master/docs/query-help-style-guide.md).
43+
- Compilation of the query and any associated libraries and tests must be resilient to future development of the [supported](docs/supported-queries.md) libraries. This means that the functionality cannot use internal libraries, cannot depend on the output of `getAQlClass`, and cannot make use of regexp matching on `toString`.
44+
- The query and any associated libraries and tests must not cause any compiler warnings to be emitted (such as use of deprecated functionality or missing `override` annotations).
45+
46+
5. **Results**
47+
48+
- The query must have at least one true positive result on some revision of a real project.
49+
50+
6. **Contributor License Agreement**
51+
52+
- The contributor can satisfy the [CLA](#contributor-license-agreement).
53+
54+
Experimental queries and libraries may not be actively maintained as the [supported](docs/supported-queries.md) libraries evolve. They may also be changed in backwards-incompatible ways or may be removed entirely in the future without deprecation warnings.
55+
56+
After the experimental query is merged, we welcome pull requests to improve it. Before a query can be moved out of the `experimental` subdirectory, it must satisfy [the requirements for being a supported query](docs/supported-queries.md).
4857

4958
## Using your personal data
5059

5160
If you contribute to this project, we will record your name and email
5261
address (as provided by you with your contributions) as part of the code
53-
repositories, which might be made public. We might also use this information
62+
repositories, which are public. We might also use this information
5463
to contact you in relation to your contributions, as well as in the
5564
normal course of software development. We also store records of your
5665
CLA agreements. Under GDPR legislation, we do this

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CodeQL
22

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.
3+
This open source repository contains the standard CodeQL libraries and queries that power [LGTM](https://lgtm.com) and the other CodeQL products that [GitHub](https://github.com) makes available to its customers worldwide.
44

55
## How do I learn CodeQL and run queries?
66

@@ -13,4 +13,4 @@ We welcome contributions to our standard library and standard checks. Do you hav
1313

1414
## License
1515

16-
The code in this repository is 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 [GitHub](https://github.com).

change-notes/1.24/analysis-cpp.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
1818
| No space for zero terminator (`cpp/no-space-for-terminator`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
1919
| Memory is never freed (`cpp/memory-never-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
2020
| Memory may not be freed (`cpp/memory-may-not-be-freed`) | More true positive results | This query now identifies a wider variety of buffer allocations using the `semmle.code.cpp.models.interfaces.Allocation` library. |
21+
| Mismatching new/free or malloc/delete (`cpp/new-free-mismatch`) | Fewer false positive results | Fixed false positive results in template code. |
2122
| Missing return statement (`cpp/missing-return`) | Fewer false positive results | Functions containing `asm` statements are no longer highlighted by this query. |
23+
| No space for zero terminator (`cpp/no-space-for-terminator`) | More correct results | String arguments to formatting functions are now (usually) expected to be null terminated strings. |
2224
| Hard-coded Japanese era start date (`cpp/japanese-era/exact-era-date`) | | This query is no longer run on LGTM. |
2325
| No space for zero terminator (`cpp/no-space-for-terminator`) | Fewer false positive results | This query has been modified to be more conservative when identifying which pointers point to null-terminated strings. This approach produces fewer, more accurate results. |
2426
| Overloaded assignment does not return 'this' (`cpp/assignment-does-not-return-this`) | Fewer false positive results | This query no longer reports incorrect results in template classes. |
2527
| Unsafe array for days of the year (`cpp/leap-year/unsafe-array-for-days-of-the-year`) | | This query is no longer run on LGTM. |
28+
| Unsigned comparison to zero (`cpp/unsigned-comparison-zero`) | More correct results | This query now also looks for comparisons of the form `0 <= x`. |
2629

2730
## Changes to libraries
2831

29-
* The data-flow library has been improved when flow through functions needs to be
30-
combined with both taint tracking and flow through fields allowing more flow
31-
to be tracked. This affects and improves some security queries, which may
32-
report additional results.
32+
* The data-flow library has been improved, which affects and improves some security queries. The improvements are:
33+
- Track flow through functions that combine taint tracking with flow through fields.
34+
- Track flow through clone-like functions, that is, functions that read contents of a field from a
35+
parameter and stores the value in the field of a returned object.
3336
* Created the `semmle.code.cpp.models.interfaces.Allocation` library to model allocation such as `new` expressions and calls to `malloc`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3437
* Created the `semmle.code.cpp.models.interfaces.Deallocation` library to model deallocation such as `delete` expressions and calls to `free`. This in intended to replace the functionality in `semmle.code.cpp.commons.Alloc` with a more consistent and useful interface.
3538
* The new class `StackVariable` should be used in place of `LocalScopeVariable`
@@ -41,7 +44,10 @@ The following changes in version 1.24 affect C/C++ analysis in all applications.
4144
* The `LocalScopeVariableReachability` library is deprecated in favor of
4245
`StackVariableReachability`. The functionality is the same.
4346
* The models library models `strlen` in more detail, and includes common variations such as `wcslen`.
47+
* The models library models `gets` and similar functions.
4448
* The taint tracking library (`semmle.code.cpp.dataflow.TaintTracking`) has had
4549
the following improvements:
4650
* The library now models data flow through `strdup` and similar functions.
4751
* The library now models data flow through formatting functions such as `sprintf`.
52+
* The security pack taint tracking library (`semmle.code.cpp.security.TaintTracking`) uses a new intermediate representation. This provides a more precise analysis of pointers to stack variables and flow through parameters, improving the results of many security queries.
53+
* The global value numbering library (`semmle.code.cpp.valuenumbering.GlobalValueNumbering`) uses a new intermediate representation to provide a more precise analysis of heap allocated memory and pointers to stack variables.

change-notes/1.24/analysis-csharp.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,27 @@ The following changes in version 1.24 affect C# analysis in all applications.
2020
| Useless assignment to local variable (`cs/useless-assignment-to-local`) | Fewer false positive results | Results have been removed when the variable is named `_` in a `foreach` statement. |
2121
| Potentially dangerous use of non-short-circuit logic (`cs/non-short-circuit`) | Fewer false positive results | Results have been removed when the expression contains an `out` parameter. |
2222
| Dereferenced variable may be null (`cs/dereferenced-value-may-be-null`) | More results | Results are reported from parameters with a default value of `null`. |
23+
| Useless assignment to local variable (`cs/useless-assignment-to-local`) | Fewer false positive results | Results have been removed when the value assigned is an (implicitly or explicitly) cast default-like value. For example, `var s = (string)null` and `string s = default`. |
24+
| XPath injection (`cs/xml/xpath-injection`) | More results | The query now recognizes calls to methods on `System.Xml.XPath.XPathNavigator` objects. |
2325

2426
## Removal of old queries
2527

2628
## Changes to code extraction
2729

2830
* Tuple expressions, for example `(int,bool)` in `default((int,bool))` are now extracted correctly.
29-
* Expression nullability flow state is extracted.
31+
* Expression nullability flow state is extracted.
32+
* Implicitly typed `stackalloc` expressions are now extracted correctly.
33+
* The difference between `stackalloc` array creations and normal array creations is extracted.
3034

3135
## Changes to libraries
3236

33-
* The data-flow library has been improved when flow through methods needs to be
34-
combined with both taint tracking and flow through fields allowing more flow
35-
to be tracked. This affects and improves most security queries, which may
36-
report additional results.
37+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
38+
- Track flow through methods that combine taint tracking with flow through fields.
39+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
40+
parameter and stores the value in the field of a returned object.
3741
* The taint tracking library now tracks flow through (implicit or explicit) conversion operator calls.
3842
* [Code contracts](https://docs.microsoft.com/en-us/dotnet/framework/debug-trace-profile/code-contracts) are now recognized, and are treated like any other assertion methods.
3943
* Expression nullability flow state is given by the predicates `Expr.hasNotNullFlowState()` and `Expr.hasMaybeNullFlowState()`.
44+
* `stackalloc` array creations are now represented by the QL class `Stackalloc`. Previously they were represented by the class `ArrayCreation`.
4045

4146
## Changes to autobuilder

change-notes/1.24/analysis-java.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ The following changes in version 1.24 affect Java analysis in all applications.
55
## General improvements
66

77
* Alert suppression can now be done with single-line block comments (`/* ... */`) as well as line comments (`// ...`).
8+
* A `Customizations.qll` file has been added to allow customizations of the standard library that apply to all queries.
89

910
## New queries
1011

1112
| **Query** | **Tags** | **Purpose** |
1213
|-----------------------------|-----------|--------------------------------------------------------------------|
13-
| Disabled Spring CSRF protection (`java/spring-disabled-csrf-protection`) | security, external/cwe/cwe-352 | Finds disabled Cross-Site Request Forgery (CSRF) protection in Spring. |
14+
| Disabled Spring CSRF protection (`java/spring-disabled-csrf-protection`) | security, external/cwe/cwe-352 | Finds disabled Cross-Site Request Forgery (CSRF) protection in Spring. Results are shown on LGTM by default. |
1415
| Failure to use HTTPS or SFTP URL in Maven artifact upload/download (`java/maven/non-https-url`) | security, external/cwe/cwe-300, external/cwe/cwe-319, external/cwe/cwe-494, external/cwe/cwe-829 | Finds use of insecure protocols during Maven dependency resolution. Results are shown on LGTM by default. |
16+
| LDAP query built from user-controlled sources (`java/ldap-injection`) | security, external/cwe/cwe-090 | Finds LDAP queries vulnerable to injection of unsanitized user-controlled input. Results are shown on LGTM by default. |
1517
| Left shift by more than the type width (`java/lshift-larger-than-type-width`) | correctness | Finds left shifts of ints by 32 bits or more and left shifts of longs by 64 bits or more. Results are shown on LGTM by default. |
16-
| Suspicious date format (`java/suspicious-date-format`) | correctness | Finds date format patterns that use placeholders that are likely to be incorrect. |
18+
| Suspicious date format (`java/suspicious-date-format`) | correctness | Finds date format patterns that use placeholders that are likely to be incorrect. Results are shown on LGTM by default. |
1719

1820
## Changes to existing queries
1921

@@ -25,10 +27,10 @@ The following changes in version 1.24 affect Java analysis in all applications.
2527

2628
## Changes to libraries
2729

28-
* The data-flow library has been improved when flow through methods needs to be
29-
combined with both taint tracking and flow through fields allowing more flow
30-
to be tracked. This affects and improves most security queries, which may
31-
report additional results.
30+
* The data-flow library has been improved, which affects and improves most security queries. The improvements are:
31+
- Track flow through methods that combine taint tracking with flow through fields.
32+
- Track flow through clone-like methods, that is, methods that read contents of a field from a
33+
parameter and stores the value in the field of a returned object.
3234
* Identification of test classes has been improved. Previously, one of the
3335
match conditions would classify any class with a name containing the string
3436
"Test" as a test class, but now this matching has been replaced with one that

0 commit comments

Comments
 (0)