Skip to content

Commit cca77ed

Browse files
committed
Merge branch 'main' into add-return-value-deref-to-model-util
2 parents 0679142 + 62aa7b7 commit cca77ed

File tree

171 files changed

+2886
-423
lines changed

Some content is hidden

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

171 files changed

+2886
-423
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'
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/Printf.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,21 @@ class FormattingFunctionCall extends Expr {
253253
// format arguments must be known
254254
exists(getTarget().(FormattingFunction).getFirstFormatArgumentIndex())
255255
}
256+
257+
/**
258+
* Gets the argument, if any, to which the output is written. If `isStream` is
259+
* `true`, the output argument is a stream (that is, this call behaves like
260+
* `fprintf`). If `isStream` is `false`, the output argument is a buffer (that
261+
* is, this call behaves like `sprintf`)
262+
*/
263+
Expr getOutputArgument(boolean isStream) {
264+
result =
265+
this.(Call)
266+
.getArgument(this.(Call)
267+
.getTarget()
268+
.(FormattingFunction)
269+
.getOutputParameterIndex(isStream))
270+
}
256271
}
257272

258273
/**

cpp/ql/lib/semmle/code/cpp/controlflow/BasicBlocks.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class BasicBlock extends ControlFlowNodeBase {
194194
* The location spans column `startcolumn` of line `startline` to
195195
* column `endcolumn` of line `endline` in file `filepath`.
196196
* For more information, see
197-
* [Locations](https://help.semmle.com/QL/learn-ql/ql/locations.html).
197+
* [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/).
198198
*
199199
* Yields no result if this basic block spans multiple source files.
200200
*/

0 commit comments

Comments
 (0)