Skip to content

Commit 0344381

Browse files
committed
Merge remote-tracking branch 'upstream/main' into docsforautofix
2 parents 7438462 + 81593ec commit 0344381

File tree

182 files changed

+830
-272
lines changed

Some content is hidden

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

182 files changed

+830
-272
lines changed

.github/workflows/compile-queries.yml

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
key: all-queries
3030
- name: check formatting
3131
run: find shared */ql -type f \( -name "*.qll" -o -name "*.ql" \) -print0 | xargs -0 -n 3000 -P 10 codeql query format -q --check-only
32+
- name: Omit DatabaseQualityDiagnostics.ql from compile checking # Remove me once CodeQL 2.18.0 is released!
33+
run: mv java/ql/src/Telemetry/DatabaseQualityDiagnostics.ql{,.hidden}
3234
- name: compile queries - check-only
3335
# run with --check-only if running in a PR (github.sha != main)
3436
if : ${{ github.event_name == 'pull_request' }}
@@ -39,3 +41,6 @@ jobs:
3941
if : ${{ github.event_name != 'pull_request' }}
4042
shell: bash
4143
run: codeql query compile -q -j0 */ql/{src,examples} --keep-going --warnings=error --compilation-cache "${{ steps.query-cache.outputs.cache-dir }}" --compilation-cache-size=500
44+
- name: Restore DatabaseQualityDiagnostics.ql after compile checking # Remove me once CodeQL 2.18.0 is released
45+
run: mv java/ql/src/Telemetry/DatabaseQualityDiagnostics.ql{.hidden,}
46+

cpp/ql/lib/CHANGELOG.md

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## 1.2.0
2+
3+
### New Features
4+
5+
* The syntax for models-as-data rows has been extended to make it easier to select sources, sinks, and summaries that involve templated functions and classes. Additionally, the syntax has also been extended to make it easier to specify models with arbitrary levels of indirection. See `dataflow/ExternalFlow.qll` for the updated documentation and specification for the model format.
6+
* It is now possible to extend the classes `AllocationFunction` and `DeallocationFunction` via data extensions. Extensions of these classes should be added to the `lib/ext/allocation` and `lib/ext/deallocation` directories respectively.
7+
8+
### Minor Analysis Improvements
9+
10+
* The queries "Potential double free" (`cpp/double-free`) and "Potential use after free" (`cpp/use-after-free`) now produce fewer false positives.
11+
* The "Guards" library (`semmle.code.cpp.controlflow.Guards`) now also infers guards from calls to the builtin operation `__builtin_expect`. As a result, some queries may produce fewer false positives.
12+
113
## 1.1.1
214

315
No user-facing changes.

cpp/ql/lib/change-notes/2024-06-10-builtin-expect.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2024-06-13-double-free.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2024-06-20-extensible-allocation-deallocation.md

-4
This file was deleted.

cpp/ql/lib/change-notes/2024-07-03-extended-mad-syntax.md

-4
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
## 1.2.0
2+
3+
### New Features
4+
5+
* The syntax for models-as-data rows has been extended to make it easier to select sources, sinks, and summaries that involve templated functions and classes. Additionally, the syntax has also been extended to make it easier to specify models with arbitrary levels of indirection. See `dataflow/ExternalFlow.qll` for the updated documentation and specification for the model format.
6+
* It is now possible to extend the classes `AllocationFunction` and `DeallocationFunction` via data extensions. Extensions of these classes should be added to the `lib/ext/allocation` and `lib/ext/deallocation` directories respectively.
7+
8+
### Minor Analysis Improvements
9+
10+
* The queries "Potential double free" (`cpp/double-free`) and "Potential use after free" (`cpp/use-after-free`) now produce fewer false positives.
11+
* The "Guards" library (`semmle.code.cpp.controlflow.Guards`) now also infers guards from calls to the builtin operation `__builtin_expect`. As a result, some queries may produce fewer false positives.

cpp/ql/lib/codeql-pack.release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 1.1.1
2+
lastReleaseVersion: 1.2.0

cpp/ql/lib/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-all
2-
version: 1.1.2-dev
2+
version: 1.2.1-dev
33
groups: cpp
44
dbscheme: semmlecode.cpp.dbscheme
55
extractor: cpp

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

+22-10
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ predicate hasRawIndirectInstruction(Instruction instr, int indirectionIndex) {
104104

105105
cached
106106
private newtype TDefImpl =
107-
TDefAddressImpl(BaseIRVariable v) or
107+
TDefAddressImpl(BaseSourceVariable v) or
108108
TDirectDefImpl(Operand address, int indirectionIndex) {
109109
isDef(_, _, address, _, _, indirectionIndex)
110110
} or
@@ -325,9 +325,9 @@ private Instruction getInitializationTargetAddress(IRVariable v) {
325325
)
326326
}
327327

328-
/** An initial definition of an `IRVariable`'s address. */
329-
private class DefAddressImpl extends DefImpl, TDefAddressImpl {
330-
BaseIRVariable v;
328+
/** An initial definition of an SSA variable address. */
329+
abstract private class DefAddressImpl extends DefImpl, TDefAddressImpl {
330+
BaseSourceVariable v;
331331

332332
DefAddressImpl() {
333333
this = TDefAddressImpl(v) and
@@ -342,6 +342,19 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
342342

343343
final override Node0Impl getValue() { none() }
344344

345+
override Cpp::Location getLocation() { result = v.getLocation() }
346+
347+
final override SourceVariable getSourceVariable() {
348+
result.getBaseVariable() = v and
349+
result.getIndirection() = 0
350+
}
351+
352+
final override BaseSourceVariable getBaseSourceVariable() { result = v }
353+
}
354+
355+
private class DefVariableAddressImpl extends DefAddressImpl {
356+
override BaseIRVariable v;
357+
345358
final override predicate hasIndexInBlock(IRBlock block, int index) {
346359
exists(IRVariable var | var = v.getIRVariable() |
347360
block.getInstruction(index) = getInitializationTargetAddress(var)
@@ -353,15 +366,14 @@ private class DefAddressImpl extends DefImpl, TDefAddressImpl {
353366
index = 0
354367
)
355368
}
369+
}
356370

357-
override Cpp::Location getLocation() { result = v.getIRVariable().getLocation() }
371+
private class DefCallAddressImpl extends DefAddressImpl {
372+
override BaseCallVariable v;
358373

359-
final override SourceVariable getSourceVariable() {
360-
result.getBaseVariable() = v and
361-
result.getIndirection() = 0
374+
final override predicate hasIndexInBlock(IRBlock block, int index) {
375+
block.getInstruction(index) = v.getCallInstruction()
362376
}
363-
364-
final override BaseSourceVariable getBaseSourceVariable() { result = v }
365377
}
366378

367379
private class DirectDef extends DefImpl, TDirectDefImpl {

cpp/ql/src/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.3
2+
3+
No user-facing changes.
4+
15
## 1.0.2
26

37
No user-facing changes.

cpp/ql/src/Likely Bugs/Memory Management/SuspiciousCallToStrncat.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @kind problem
55
* @problem.severity warning
66
* @security-severity 9.3
7-
* @precision medium
7+
* @precision high
88
* @id cpp/unsafe-strncat
99
* @tags reliability
1010
* correctness
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: queryMetadata
3+
---
4+
* The precision of `cpp/unsafe-strncat` ("Potentially unsafe call to strncat") has been increased to `high`. As a result, it will be run by default as part of the Code Scanning suite.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.3
2+
3+
No user-facing changes.

cpp/ql/src/codeql-pack.release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 1.0.2
2+
lastReleaseVersion: 1.0.3

cpp/ql/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/cpp-queries
2-
version: 1.0.3-dev
2+
version: 1.0.4-dev
33
groups:
44
- cpp
55
- queries
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
namespace std
2+
{
3+
struct ptrdiff_t;
4+
struct input_iterator_tag
5+
{
6+
};
7+
struct forward_iterator_tag : public input_iterator_tag
8+
{
9+
};
10+
}
11+
12+
struct A
13+
{
14+
using value_type = int;
15+
using difference_type = std::ptrdiff_t;
16+
using pointer = int*;
17+
using reference = int&;
18+
using iterator_category = std::forward_iterator_tag;
19+
};
20+
21+
A get();
22+
23+
void test()
24+
{
25+
while (true)
26+
{
27+
auto &&x = get();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
edges
2+
nodes
3+
subpaths
4+
#select
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @kind path-problem
3+
*/
4+
5+
import semmle.code.cpp.ir.IR
6+
import semmle.code.cpp.dataflow.new.DataFlow
7+
import Flow::PathGraph
8+
9+
module Config implements DataFlow::ConfigSig {
10+
predicate isSource(DataFlow::Node source) {
11+
source.asInstruction().(VariableAddressInstruction).getIRVariable() instanceof IRTempVariable
12+
}
13+
14+
predicate isSink(DataFlow::Node sink) {
15+
sink.asInstruction().(CallInstruction).getStaticCallTarget().hasName("get")
16+
}
17+
}
18+
19+
module Flow = DataFlow::Global<Config>;
20+
21+
from Flow::PathNode source, Flow::PathNode sink
22+
where Flow::flowPath(source, sink)
23+
select sink.getNode(), source, sink, ""

cpp/ql/test/query-tests/Likely Bugs/Memory Management/SuspiciousCallToStrncat/SuspiciousCallToStrncat.expected

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
| test.c:67:3:67:9 | call to strncat | Potentially unsafe call to strncat. |
44
| test.c:75:3:75:9 | call to strncat | Potentially unsafe call to strncat. |
55
| test.c:76:3:76:9 | call to strncat | Potentially unsafe call to strncat. |
6+
| test.c:91:3:91:9 | call to strncat | Potentially unsafe call to strncat. |
7+
| test.c:99:3:99:9 | call to strncat | Potentially unsafe call to strncat. |

cpp/ql/test/query-tests/Likely Bugs/Memory Management/SuspiciousCallToStrncat/test.c

+17
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,20 @@ void strncat_test5(char *s) {
8282
strncat(buf, s, len - strlen(buf) - 1); // GOOD
8383
strncat(buf, s, len - strlen(buf)); // GOOD
8484
}
85+
86+
void strncat_test6() {
87+
{
88+
char dest[60];
89+
dest[0] = '\0';
90+
// Will write `dest[0 .. 5]`
91+
strncat(dest, "small", sizeof(dest)); // GOOD [FALSE POSITIVE]
92+
}
93+
94+
{
95+
char dest[60];
96+
memset(dest, 'a', sizeof(dest));
97+
dest[54] = '\0';
98+
// Will write `dest[54 .. 59]`
99+
strncat(dest, "small", sizeof(dest)); // GOOD [FALSE POSITIVE]
100+
}
101+
}

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/IteratorToExpiredContainer/IteratorToExpiredContainer.expected

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
| test.cpp:702:27:702:27 | call to operator[] | This object is destroyed at the end of the full-expression. |
44
| test.cpp:727:23:727:23 | call to operator[] | This object is destroyed at the end of the full-expression. |
55
| test.cpp:735:23:735:23 | call to operator[] | This object is destroyed at the end of the full-expression. |
6+
| test.cpp:857:3:857:17 | pointer to ~PlusPlusReturnByValueIterator output argument | This object is destroyed at the end of the full-expression. |

cpp/ql/test/query-tests/Security/CWE/CWE-416/semmle/tests/IteratorToExpiredContainer/test.cpp

+56
Original file line numberDiff line numberDiff line change
@@ -801,4 +801,60 @@ void test5(int i)
801801
for(const auto& vs : vvs) { }
802802
++i;
803803
} // GOOD
804+
}
805+
806+
struct HasBeginAndEnd
807+
{
808+
~HasBeginAndEnd();
809+
using value_type = int;
810+
using difference_type = std::ptrdiff_t;
811+
using pointer = int*;
812+
using reference = int&;
813+
using iterator_category = std::random_access_iterator_tag;
814+
std::vector<int>::iterator begin() const;
815+
std::vector<int>::iterator end() const;
816+
};
817+
818+
HasBeginAndEnd getHasBeginAndEnd();
819+
820+
bool getBool();
821+
822+
void test6()
823+
{
824+
while(getBool())
825+
{
826+
for (const int& x : getHasBeginAndEnd()) // GOOD
827+
{
828+
}
829+
}
830+
}
831+
832+
struct PlusPlusReturnByValueIterator
833+
{
834+
using value_type = int;
835+
using difference_type = std::ptrdiff_t;
836+
using pointer = int *;
837+
using reference = int &;
838+
using iterator_category = std::forward_iterator_tag;
839+
840+
PlusPlusReturnByValueIterator();
841+
PlusPlusReturnByValueIterator(PlusPlusReturnByValueIterator const &);
842+
843+
PlusPlusReturnByValueIterator operator++();
844+
bool operator==(PlusPlusReturnByValueIterator other) const;
845+
bool operator!=(PlusPlusReturnByValueIterator other) const;
846+
reference operator*() const;
847+
pointer operator->() const;
848+
849+
~PlusPlusReturnByValueIterator();
850+
851+
PlusPlusReturnByValueIterator begin();
852+
};
853+
854+
void test7()
855+
{
856+
PlusPlusReturnByValueIterator it;
857+
it.operator++(); // GOOD [FALSE POSITIVE]
858+
859+
it.begin();
804860
}

csharp/ql/campaigns/Solorigate/lib/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.7.20
2+
3+
No user-facing changes.
4+
15
## 1.7.19
26

37
No user-facing changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.7.20
2+
3+
No user-facing changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 1.7.19
2+
lastReleaseVersion: 1.7.20

csharp/ql/campaigns/Solorigate/lib/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/csharp-solorigate-all
2-
version: 1.7.20-dev
2+
version: 1.7.21-dev
33
groups:
44
- csharp
55
- solorigate

csharp/ql/campaigns/Solorigate/src/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.7.20
2+
3+
No user-facing changes.
4+
15
## 1.7.19
26

37
No user-facing changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.7.20
2+
3+
No user-facing changes.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 1.7.19
2+
lastReleaseVersion: 1.7.20

csharp/ql/campaigns/Solorigate/src/qlpack.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: codeql/csharp-solorigate-queries
2-
version: 1.7.20-dev
2+
version: 1.7.21-dev
33
groups:
44
- csharp
55
- solorigate

csharp/ql/lib/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.3
2+
3+
No user-facing changes.
4+
15
## 1.0.2
26

37
No user-facing changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 1.0.3
2+
3+
No user-facing changes.

csharp/ql/lib/codeql-pack.release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
lastReleaseVersion: 1.0.2
2+
lastReleaseVersion: 1.0.3

0 commit comments

Comments
 (0)