Skip to content

Commit 47a4cac

Browse files
authored
Merge branch 'main' into redsun82/swift-extraction
2 parents 3940643 + 70838fe commit 47a4cac

File tree

8 files changed

+91
-2
lines changed

8 files changed

+91
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
- "*/ql/lib/**/*.qll"
1111
- "!**/experimental/**"
1212
- "!ql/**"
13+
- "!swift/**"
1314
- ".github/workflows/check-change-note.yml"
1415

1516
jobs:

cpp/ql/src/Likely Bugs/Conversion/LossyFunctionResultCast.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ predicate whiteListWrapped(FunctionCall fc) {
4444

4545
from FunctionCall c, FloatingPointType t1, IntegralType t2
4646
where
47-
t1 = c.getTarget().getType().getUnderlyingType() and
47+
pragma[only_bind_into](t1) = c.getTarget().getType().getUnderlyingType() and
4848
t2 = c.getActualType() and
4949
c.hasImplicitConversion() and
5050
not whiteListWrapped(c)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
| test.cpp:9:9:9:9 | v | test.cpp:5:13:5:13 | v | is not null | is valid |
2+
| test.cpp:10:9:10:10 | ! ... | test.cpp:5:13:5:13 | v | is null | is not valid |
3+
| test.cpp:11:9:11:14 | ... == ... | test.cpp:5:13:5:13 | v | is null | is not valid |
4+
| test.cpp:12:9:12:17 | ... == ... | test.cpp:5:13:5:13 | v | is not null | is valid |
5+
| test.cpp:13:9:13:14 | ... != ... | test.cpp:5:13:5:13 | v | is not null | is valid |
6+
| test.cpp:14:9:14:17 | ... != ... | test.cpp:5:13:5:13 | v | is null | is not valid |
7+
| test.cpp:15:8:15:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is not null | is valid |
8+
| test.cpp:16:8:16:23 | call to __builtin_expect | test.cpp:5:13:5:13 | v | is null | is not valid |
9+
| test.cpp:17:9:17:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is valid |
10+
| test.cpp:18:9:18:17 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
11+
| test.cpp:19:9:19:18 | ... && ... | test.cpp:5:13:5:13 | v | is null | is not valid |
12+
| test.cpp:20:9:20:18 | ... && ... | test.cpp:5:13:5:13 | v | is not null | is not valid |
13+
| test.cpp:21:9:21:14 | ... = ... | test.cpp:5:13:5:13 | v | is null | is not valid |
14+
| test.cpp:21:9:21:14 | ... = ... | test.cpp:7:10:7:10 | b | is not null | is valid |
15+
| test.cpp:22:17:22:17 | b | test.cpp:7:10:7:10 | b | is not null | is valid |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import cpp
2+
3+
from AnalysedExpr a, LocalScopeVariable v, string isNullCheck, string isValidCheck
4+
where
5+
a.getParent() instanceof IfStmt and
6+
v.getAnAccess().getEnclosingStmt() = a.getParent() and
7+
(if a.isNullCheck(v) then isNullCheck = "is null" else isNullCheck = "is not null") and
8+
(if a.isValidCheck(v) then isValidCheck = "is valid" else isValidCheck = "is not valid")
9+
select a, v, isNullCheck, isValidCheck
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// semmle-extractor-options: -std=c++17
2+
3+
long __builtin_expect(long);
4+
5+
void f(int *v) {
6+
int *w;
7+
bool b;
8+
9+
if (v) {}
10+
if (!v) {}
11+
if (v == 0) {}
12+
if ((!v) == 0) {}
13+
if (v != 0) {}
14+
if ((!v) != 0) {}
15+
if(__builtin_expect((long)v)) {}
16+
if(__builtin_expect((long)!v)) {}
17+
if (true && v) {}
18+
if (v && true) {}
19+
if (true && !v) {}
20+
if (!v && true) {}
21+
if (b = !v) {}
22+
if (b = !v; b) {}
23+
}

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,47 @@ pack names and use the ``--download`` flag::
135135
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/security-queries`` on the specified database.
136136
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
137137

138+
Running a subset of queries in a CodeQL pack
139+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140+
141+
If you are using CodeQL CLI v2.8.1 or later, you can include a path at the end of a pack specification to run a subset of queries inside the pack. This applies to any command that locates or runs queries within a pack.
142+
143+
The complete way to specify a set of queries is in the form ``scope/name@range:path``, where:
144+
145+
- ``scope/name`` is the qualified name of a CodeQL pack.
146+
- ``range`` is a `semver range <https://docs.npmjs.com/cli/v6/using-npm/semver#ranges>`_.
147+
- ``path`` is a file system path to a single query, a directory containing queries, or a query suite file.
148+
149+
When you specify a ``scope/name``, the ``range`` and ``path`` are
150+
optional. If you omit a ``range`` then the latest version of the
151+
specified pack is used. If you omit a ``path`` then the default query suite
152+
of the specified pack is used.
153+
154+
The ``path`` can be one of a ``*.ql`` query file, a directory
155+
containing one or more queries, or a ``.qls`` query suite file. If
156+
you omit a pack name, then you must provide a ``path``,
157+
which will be interpreted relative to the working directory
158+
of the current process.
159+
160+
If you specify a ``scope/name`` and ``path``, then the ``path`` cannot
161+
be absolute. It is considered relative to the root of the CodeQL
162+
pack.
163+
164+
To analyze a database using all queries in the `experimental/Security` folder within the `codeql/cpp-queries` CodeQL pack you can use::
165+
166+
codeql database analyze --format=sarif-latest --output=results <db> \
167+
codeql/cpp-queries:experimental/Security
168+
169+
To run the `RedundantNullCheckParam.ql` query in the `codeql/cpp-queries` CodeQL pack use::
170+
171+
codeql database analyze --format=sarif-latest --output=results <db> \
172+
'codeql/cpp-queries:experimental/Likely Bugs/RedundantNullCheckParam.ql'
173+
174+
To analyze your database using the `cpp-security-and-quality.qls` query suite from a version of the `codeql/cpp-queries` CodeQL pack that is >= 0.0.3 and < 0.1.0 (the highest compatible version will be chosen) you can use::
175+
176+
codeql database analyze --format=sarif-latest --output=results <db> \
177+
'codeql/cpp-queries@~0.0.3:codeql-suites/cpp-security-and-quality.qls'
178+
138179
For more information about CodeQL packs, see :doc:`About CodeQL Packs <about-codeql-packs>`.
139180

140181
Running query suites
@@ -223,7 +264,7 @@ you can include the query help for your custom queries in SARIF files generated
223264
After uploading the SARIF file to GitHub, the query help is shown in the code scanning UI for any
224265
alerts generated by the custom queries.
225266

226-
From CodeQL CLI 2.7.1 onwards, you can include markdown-rendered query help in SARIF files
267+
From CodeQL CLI v2.7.1 onwards, you can include markdown-rendered query help in SARIF files
227268
by providing the ``--sarif-add-query-help`` option when running
228269
``codeql database analyze``.
229270
For more information, see `Configuring CodeQL CLI in your CI system <https://docs.github.com/en/code-security/code-scanning/using-codeql-code-scanning-with-your-existing-ci-system/configuring-codeql-cli-in-your-ci-system#analyzing-a-codeql-database>`__

0 commit comments

Comments
 (0)