Skip to content

Commit ceb198f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into SimpleRangeAnalysis-NotExpr
2 parents 911dec6 + a1cec12 commit ceb198f

File tree

462 files changed

+19821
-10313
lines changed

Some content is hidden

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

462 files changed

+19821
-10313
lines changed

change-notes/1.26/analysis-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ The following changes in version 1.26 affect C/C++ analysis in all applications.
1313

1414
| **Query** | **Expected impact** | **Change** |
1515
|----------------------------|------------------------|------------------------------------------------------------------|
16+
| Declaration hides parameter (`cpp/declaration-hides-parameter`) | Fewer false positive results | False positives involving template functions have been fixed. |
1617
| Inconsistent direction of for loop (`cpp/inconsistent-loop-direction`) | Fewer false positive results | The query now accounts for intentional wrapping of an unsigned loop counter. |
1718
| Overflow in uncontrolled allocation size (`cpp/uncontrolled-allocation-size`) | | The precision of this query has been decreased from "high" to "medium". As a result, the query is still run but results are no longer displayed on LGTM by default. |
1819
| Comparison result is always the same (`cpp/constant-comparison`) | More correct results | Bounds on expressions involving multiplication can now be determined in more cases. |
1920

2021
## Changes to libraries
2122

23+
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.
2224
* The models library now models many taint flows through `std::array`, `std::vector`, `std::deque`, `std::list` and `std::forward_list`.
2325
* The models library now models many more taint flows through `std::string`.
2426
* The `SimpleRangeAnalysis` library now supports multiplications of the form

change-notes/1.26/analysis-java.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Improvements to Java analysis
2+
3+
The following changes in version 1.26 affect Java analysis in all applications.
4+
5+
## General improvements
6+
7+
## New queries
8+
9+
| **Query** | **Tags** | **Purpose** |
10+
|-----------------------------|-----------|--------------------------------------------------------------------|
11+
12+
13+
## Changes to existing queries
14+
15+
| **Query** | **Expected impact** | **Change** |
16+
|------------------------------|------------------------|-----------------------------------|
17+
18+
19+
## Changes to libraries
20+
21+
* The QL class `Block`, denoting the `{ ... }` statement, is renamed to `BlockStmt`.

change-notes/1.26/analysis-javascript.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
| Incomplete URL substring sanitization (`js/incomplete-url-substring-sanitization`) | More results | This query now recognizes additional URLs when the substring check is an inclusion check. |
3131
| Ambiguous HTML id attribute (`js/duplicate-html-id`) | Results no longer shown | Precision tag reduced to "low". The query is no longer run by default. |
3232
| Unused loop iteration variable (`js/unused-loop-variable`) | Fewer results | This query no longer flags variables in a destructuring array assignment that are not the last variable in the destructed array. |
33+
| Unsafe shell command constructed from library input (`js/shell-command-constructed-from-input`) | More results | This query now recognizes more commands where colon, dash, and underscore are used. |
34+
| Unsafe jQuery plugin (`js/unsafe-jquery-plugin`) | More results | This query now detects more unsafe uses of nested option properties. |
3335

3436

3537
## Changes to libraries
38+
* The predicate `TypeAnnotation.hasQualifiedName` now works in more cases when the imported library was not present during extraction.

cpp/ql/examples/snippets/emptyblock.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
import cpp
1111

12-
from Block blk
12+
from BlockStmt blk
1313
where blk.getNumStmt() = 0
1414
select blk

cpp/ql/examples/snippets/emptythen.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
import cpp
1414

1515
from IfStmt i
16-
where i.getThen().(Block).getNumStmt() = 0
16+
where i.getThen().(BlockStmt).getNumStmt() = 0
1717
select i

cpp/ql/examples/snippets/singletonblock.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
import cpp
1010

11-
from Block b
11+
from BlockStmt b
1212
where b.getNumStmt() = 1
1313
select b

cpp/ql/src/Best Practices/BlockWithTooManyStatements.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import cpp
1414

1515
class ComplexStmt extends Stmt {
1616
ComplexStmt() {
17-
exists(Block body |
17+
exists(BlockStmt body |
1818
body = this.(Loop).getStmt() or
1919
body = this.(SwitchStmt).getStmt()
2020
|
@@ -24,7 +24,7 @@ class ComplexStmt extends Stmt {
2424
}
2525
}
2626

27-
from Block b, int n, ComplexStmt complexStmt
27+
from BlockStmt b, int n, ComplexStmt complexStmt
2828
where
2929
n = strictcount(ComplexStmt s | s = b.getAStmt()) and
3030
n > 3 and

cpp/ql/src/Best Practices/Hiding/DeclarationHidesParameter.ql

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,35 @@
1111

1212
import cpp
1313

14+
/**
15+
* Gets the template that a function `f` is constructed from, or just `f` if it
16+
* is not from a template instantiation.
17+
*/
18+
Function getConstructedFrom(Function f) {
19+
f.isConstructedFrom(result)
20+
or
21+
not f.isConstructedFrom(_) and
22+
result = f
23+
}
24+
1425
/**
1526
* Gets the parameter of `f` with name `name`, which has to come from the
1627
* _definition_ of `f` and not a prototype declaration.
1728
* We also exclude names from functions that have multiple definitions.
1829
* This should not happen in a single application but since we
1930
* have a system wide view it is likely to happen for instance for
2031
* the main function.
32+
*
33+
* Note: we use `getConstructedFrom` to ensure that we look at template
34+
* functions rather than their instantiations. We get better results this way
35+
* as the instantiation is artificial and may have inherited parameter names
36+
* from the declaration rather than the definition.
2137
*/
2238
ParameterDeclarationEntry functionParameterNames(Function f, string name) {
2339
exists(FunctionDeclarationEntry fe |
2440
result.getFunctionDeclarationEntry() = fe and
25-
fe.getFunction() = f and
41+
getConstructedFrom(f).getDefinition() = fe and
2642
fe.getLocation() = f.getDefinitionLocation() and
27-
result.getFile() = fe.getFile() and // Work around CPP-331
2843
strictcount(f.getDefinitionLocation()) = 1 and
2944
result.getName() = name
3045
)

cpp/ql/src/Best Practices/Hiding/DeclarationHidesVariable.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ where
1717
shadowing(lv1, lv2) and
1818
not lv1.isCompilerGenerated() and
1919
not lv2.isCompilerGenerated() and
20-
not lv1.getParentScope().(Block).isInMacroExpansion() and
21-
not lv2.getParentScope().(Block).isInMacroExpansion()
20+
not lv1.getParentScope().(BlockStmt).isInMacroExpansion() and
21+
not lv2.getParentScope().(BlockStmt).isInMacroExpansion()
2222
select lv1, "Variable " + lv1.getName() + " hides another variable of the same name (on $@).", lv2,
2323
"line " + lv2.getLocation().getStartLine().toString()

cpp/ql/src/Best Practices/Likely Errors/EmptyBlock.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import cpp
1616

17-
predicate emptyBlock(ControlStructure s, Block b) {
17+
predicate emptyBlock(ControlStructure s, BlockStmt b) {
1818
b = s.getAChild() and
1919
not exists(b.getAChild()) and
2020
not b.isInMacroExpansion() and
@@ -23,7 +23,7 @@ predicate emptyBlock(ControlStructure s, Block b) {
2323

2424
class AffectedFile extends File {
2525
AffectedFile() {
26-
exists(Block b |
26+
exists(BlockStmt b |
2727
emptyBlock(_, b) and
2828
this = b.getFile()
2929
)
@@ -37,7 +37,7 @@ class AffectedFile extends File {
3737
class BlockOrNonChild extends Element {
3838
BlockOrNonChild() {
3939
(
40-
this instanceof Block
40+
this instanceof BlockStmt
4141
or
4242
this instanceof Comment
4343
or
@@ -78,7 +78,7 @@ class BlockOrNonChild extends Element {
7878
/**
7979
* A block that contains a non-child element.
8080
*/
81-
predicate emptyBlockContainsNonchild(Block b) {
81+
predicate emptyBlockContainsNonchild(BlockStmt b) {
8282
emptyBlock(_, b) and
8383
exists(BlockOrNonChild c, AffectedFile file |
8484
c.(BlockOrNonChild).getStartRankIn(file) = 1 + b.(BlockOrNonChild).getStartRankIn(file) and
@@ -91,7 +91,7 @@ predicate emptyBlockContainsNonchild(Block b) {
9191
* A block that is entirely on one line, which also contains a comment. Chances
9292
* are the comment is intended to refer to the block.
9393
*/
94-
predicate lineComment(Block b) {
94+
predicate lineComment(BlockStmt b) {
9595
emptyBlock(_, b) and
9696
exists(Location bLocation, File f, int line |
9797
bLocation = b.getLocation() and
@@ -106,7 +106,7 @@ predicate lineComment(Block b) {
106106
)
107107
}
108108

109-
from ControlStructure s, Block eb
109+
from ControlStructure s, BlockStmt eb
110110
where
111111
emptyBlock(s, eb) and
112112
not emptyBlockContainsNonchild(eb) and

0 commit comments

Comments
 (0)