Skip to content

Commit 2c64fa5

Browse files
committed
Merge branch 'main' into impropnullfp
2 parents b9a1a45 + 7f7f906 commit 2c64fa5

File tree

491 files changed

+18666
-1841
lines changed

Some content is hidden

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

491 files changed

+18666
-1841
lines changed

.github/workflows/csv-coverage-pr-artifacts.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- '.github/workflows/csv-coverage-pr-comment.yml'
77
- '*/ql/src/**/*.ql'
88
- '*/ql/src/**/*.qll'
9+
- '*/ql/lib/**/*.ql'
10+
- '*/ql/lib/**/*.qll'
911
- 'misc/scripts/library-coverage/*.py'
1012
# input data files
1113
- '*/documentation/library-coverage/cwe-sink.csv'

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ This open source repository contains the standard CodeQL libraries and queries t
44

55
## 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 CodeQL.
8-
You can use the [interactive query console](https://lgtm.com/help/lgtm/using-query-console) on LGTM.com or the [CodeQL for Visual Studio Code](https://help.semmle.com/codeql/codeql-for-vscode.html) extension to try out your queries on any open source project that's currently being analyzed.
7+
There is [extensive documentation](https://codeql.github.com/docs/) 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 [CodeQL for Visual Studio Code](https://codeql.github.com/docs/codeql-for-visual-studio-code/) extension to try out your queries on any open source project that's currently being analyzed.
99

1010
## Contributing
1111

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* A new query (`cpp/cleartext-transmission`) has been added. This is similar to the `cpp/cleartext-storage-file`, `cpp/cleartext-storage-buffer` and `cpp/cleartext-storage-database` queries but looks for cases where sensitive information is most likely transmitted over a network.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lgtm,codescanning
2+
* The "Uncontrolled data used in OS command" (`cpp/command-line-injection`) query has been enhanced to reduce false positive results and its `@precision` increased to `high`
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lgtm,codescanning
2+
* Increase precision to high for the "Static buffer overflow" query
3+
(`cpp/static-buffer-overflow`). This means the query is run and displayed by default on Code Scanning and LGTM.

cpp/ql/lib/semmle/code/cpp/File.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Container extends Locatable, @container {
3838
* DEPRECATED: Use `getLocation` instead.
3939
* Gets a URL representing the location of this container.
4040
*
41-
* For more information see [Providing URLs](https://help.semmle.com/QL/learn-ql/ql/locations.html#providing-urls).
41+
* For more information see [Providing URLs](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/#providing-urls).
4242
*/
4343
deprecated string getURL() { none() } // overridden by subclasses
4444

cpp/ql/lib/semmle/code/cpp/Location.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class Location extends @location {
6161
* The location spans column `startcolumn` of line `startline` to
6262
* column `endcolumn` of line `endline` in file `filepath`.
6363
* For more information, see
64-
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
64+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
6565
*/
6666
predicate hasLocationInfo(
6767
string filepath, int startline, int startcolumn, int endline, int endcolumn

cpp/ql/lib/semmle/code/cpp/XML.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class XMLLocatable extends @xmllocatable, TXMLLocatable {
2424
* The location spans column `startcolumn` of line `startline` to
2525
* column `endcolumn` of line `endline` in file `filepath`.
2626
* For more information, see
27-
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
27+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
2828
*/
2929
predicate hasLocationInfo(
3030
string filepath, int startline, int startcolumn, int endline, int endcolumn

cpp/ql/lib/semmle/code/cpp/commons/Buffer.qll

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,11 @@ import semmle.code.cpp.dataflow.DataFlow
1010
* char data[1]; // v
1111
* };
1212
* ```
13-
* This requires that `v` is an array of size 0 or 1, and `v` is the last member of `c`.
14-
* In addition, if the size of the structure is taken, there must be at least one instance
15-
* where a `c` pointer is allocated with additional space.
16-
* For example, holds for `c` if it occurs as
17-
* ```
18-
* malloc(sizeof(c) + 100 * sizeof(char))
19-
* ```
20-
* but not if it only ever occurs as
21-
* ```
22-
* malloc(sizeof(c))
23-
* ```
13+
* This requires that `v` is an array of size 0 or 1.
2414
*/
2515
predicate memberMayBeVarSize(Class c, MemberVariable v) {
26-
exists(int i |
27-
// `v` is the last field in `c`
28-
i = max(int j | c.getCanonicalMember(j) instanceof Field | j) and
29-
v = c.getCanonicalMember(i) and
30-
// v is an array of size at most 1
31-
v.getUnspecifiedType().(ArrayType).getArraySize() <= 1 and
32-
not c instanceof Union
33-
) and
34-
// If the size is taken, then arithmetic is performed on the result at least once
35-
(
36-
// `sizeof(c)` is not taken
37-
not exists(SizeofOperator so |
38-
so.(SizeofTypeOperator).getTypeOperand().getUnspecifiedType() = c or
39-
so.(SizeofExprOperator).getExprOperand().getUnspecifiedType() = c
40-
)
41-
or
42-
// or `sizeof(c)` is taken
43-
exists(SizeofOperator so |
44-
so.(SizeofTypeOperator).getTypeOperand().getUnspecifiedType() = c or
45-
so.(SizeofExprOperator).getExprOperand().getUnspecifiedType() = c
46-
|
47-
// and arithmetic is performed on the result
48-
so.getParent*() instanceof AddExpr
49-
)
50-
)
16+
c = v.getDeclaringType() and
17+
v.getUnspecifiedType().(ArrayType).getArraySize() <= 1
5118
}
5219

5320
/**
@@ -60,10 +27,6 @@ int getBufferSize(Expr bufferExpr, Element why) {
6027
result = bufferVar.getUnspecifiedType().(ArrayType).getSize() and
6128
why = bufferVar and
6229
not memberMayBeVarSize(_, bufferVar) and
63-
not exists(Union bufferType |
64-
bufferType.getAMemberVariable() = why and
65-
bufferVar.getUnspecifiedType().(ArrayType).getSize() <= 1
66-
) and
6730
not result = 0 // zero sized arrays are likely to have special usage, for example
6831
or
6932
// behaving a bit like a 'union' overlapping other fields.
@@ -85,13 +48,6 @@ int getBufferSize(Expr bufferExpr, Element why) {
8548
parentPtr.getTarget().getUnspecifiedType().(PointerType).getBaseType() = parentClass and
8649
result = getBufferSize(parentPtr, _) + bufferVar.getType().getSize() - parentClass.getSize()
8750
)
88-
or
89-
exists(Union bufferType |
90-
bufferType.getAMemberVariable() = why and
91-
why = bufferVar and
92-
bufferVar.getUnspecifiedType().(ArrayType).getSize() <= 1 and
93-
result = bufferType.getSize()
94-
)
9551
)
9652
or
9753
// buffer is a fixed size dynamic allocation

cpp/ql/lib/semmle/code/cpp/commons/NullTermination.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,15 @@ predicate variableMustBeNullTerminated(VariableAccess va) {
100100
fc.getArgument(i) = va
101101
)
102102
or
103+
// String argument to a formatting function (such as `printf`)
104+
exists(int n, FormatLiteral fl |
105+
fc.(FormattingFunctionCall).getConversionArgument(n) = va and
106+
fl = fc.(FormattingFunctionCall).getFormat() and
107+
fl.getConversionType(n) instanceof PointerType and // `%s`, `%ws` etc
108+
not fl.getConversionType(n) instanceof VoidPointerType and // exclude: `%p`
109+
not fl.hasPrecision(n) // exclude: `%.*s`
110+
)
111+
or
103112
// Call to a wrapper function that requires null termination
104113
// (not itself adding a null terminator)
105114
exists(Function wrapper, int i, Parameter p, VariableAccess use |

0 commit comments

Comments
 (0)