Skip to content

Commit a2bcc53

Browse files
author
Max Schaefer
authored
Merge branch 'master' into url-concat
2 parents 4ccd5cf + 2f0e693 commit a2bcc53

File tree

94 files changed

+3571
-321
lines changed

Some content is hidden

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

94 files changed

+3571
-321
lines changed

change-notes/1.19/analysis-cpp.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
| **Query** | **Expected impact** | **Change** |
1717
|----------------------------|------------------------|------------------------------------------------------------------|
1818
| Empty branch of conditional | Fewer false positive results | The query now recognizes commented blocks more reliably. |
19+
| Expression has no effect | Fewer false positive results | Expressions in template instantiations are now excluded from this query. |
1920
| Resource not released in destructor | Fewer false positive results | Placement new is now excluded from the query. Also fixed an issue where false positives could occur if the destructor body was not in the snapshot. |
2021
| Missing return statement (`cpp/missing-return`) | Visible by default | The precision of this query has been increased from 'medium' to 'high', which makes it visible by default in LGTM. It was 'medium' in release 1.17 and 1.18 because it had false positives due to an extractor bug that was fixed in 1.18. |
2122
| Missing return statement | Fewer false positive results | The query is now produces correct results when a function returns a template-dependent type. |

change-notes/1.19/analysis-csharp.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
## General improvements
44

55
* Control flow graph improvements:
6-
* The control flow graph construction now takes simple Boolean conditions on local scope variables into account. For example, in `if (b) x = 0; if (b) x = 1;`, the control flow graph will reflect that taking the `true` (resp. `false`) branch in the first condition implies taking the same branch in the second condition. In effect, the first assignment to `x` will now be identified as being dead.
6+
* The control flow graph construction now takes simple Boolean conditions on local scope variables into account. For example, in `if (b) x = 0; if (b) x = 1;`, the control flow graph will reflect that taking the `true` (resp. `false`) branch in the first condition implies taking the same branch in the second condition. In effect, the first assignment to `x` will now be identified as being dead.
77
* Code that is only reachable from a constant failing assertion, such as `Debug.Assert(false)`, is considered to be unreachable.
88

99
## New queries
1010

1111
| **Query** | **Tags** | **Purpose** |
1212
|-----------------------------|-----------|--------------------------------------------------------------------|
13-
| *@name of query (Query ID)* | *Tags* |*Aim of the new query and whether it is enabled by default or not* |
13+
| Using a package with a known vulnerability (cs/use-of-vulnerable-package) | security, external/cwe/cwe-937 | Finds project build files that import packages with known vulnerabilities. This is included by default. |
14+
1415

1516
## Changes to existing queries
1617

@@ -21,3 +22,5 @@
2122

2223

2324
## Changes to QL libraries
25+
26+
* `getArgument()` on `AccessorCall` has been improved so it now takes tuple assignments into account. For example, the argument for the implicit `value` parameter in the setter of property `P` is `0` in `(P, x) = (0, 1)`. Additionally, the argument for the `value` parameter in compound assignments is now only the expanded value, for example, in `P += 7` the argument is `P + 7` and not `7`.

change-notes/1.19/analysis-javascript.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
* Support for popular libraries has been improved. Consequently, queries may produce more results on code bases that use the following features:
1010
- file system access, for example through [fs-extra](https://github.com/jprichardson/node-fs-extra) or [globby](https://www.npmjs.com/package/globby)
1111
- outbound network access, for example through the [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
12-
- the [Google Cloud Spanner](https://cloud.google.com/spanner), [lodash](https://lodash.com), [underscore](https://underscorejs.org/), [async](https://www.npmjs.com/package/async) and [async-es](https://www.npmjs.com/package/async-es) libraries
13-
14-
* The type inference now handles nested imports (that is, imports not appearing at the toplevel). This may yield fewer false-positive results on projects that use this non-standard language feature.
12+
- the [lodash](https://lodash.com), [underscore](https://underscorejs.org/), [async](https://www.npmjs.com/package/async) and [async-es](https://www.npmjs.com/package/async-es) libraries
1513

1614
* Type inference for function calls has been improved. This may give additional results for queries that rely on type inference.
1715

@@ -25,6 +23,7 @@
2523
| Replacement of a substring with itself (`js/identity-replacement`) | correctness, security, external/cwe/cwe-116 | Highlights string replacements that replace a string with itself, which usually indicates a mistake. Results shown on LGTM by default. |
2624
| Stored cross-site scripting (`js/stored-xss`) | security, external/cwe/cwe-079, external/cwe/cwe-116 | Highlights uncontrolled stored values flowing into HTML content, indicating a violation of [CWE-079](https://cwe.mitre.org/data/definitions/79.html). Results shown on LGTM by default. |
2725
| Unclear precedence of nested operators (`js/unclear-operator-precedence`) | maintainability, correctness, external/cwe/cwe-783 | Highlights nested binary operators whose relative precedence is easy to misunderstand. Results shown on LGTM by default. |
26+
| Useless assignment to property | maintainability | Highlights property assignments whose value is always overwritten. Results are shown on LGTM by default. |
2827
| User-controlled data in file | security, external/cwe/cwe-912 | Highlights locations where user-controlled data is written to a file. Results are not shown on LGTM by default. |
2928

3029
## Changes to existing queries
@@ -39,13 +38,13 @@
3938
| Server-side URL redirect | More results | This rule now recognizes redirection calls in more cases. |
4039
| Unused variable, import, function or class | Fewer false-positive results | This rule now flags fewer variables that may be used by `eval` calls. |
4140
| Unused variable, import, function or class | Fewer results | This rule now flags import statements with multiple unused imports once. |
42-
| User-controlled bypass of security check | Fewer results | This rule no longer flags conditions that guard early returns. The precision of this rule has been revised to "medium". Results are no longer shown on LGTM by default. |
4341
| Whitespace contradicts operator precedence | Fewer false-positive results | This rule no longer flags operators with asymmetric whitespace. |
4442
| Unused import | Fewer false-positive results | This rule no longer flags imports used by the `transform-react-jsx` Babel plugin. |
4543
| Self assignment | Fewer false-positive results | This rule now ignores self-assignments preceded by a JSDoc comment with a `@type` tag. |
4644
| Client side cross-site scripting | More results | This rule now also flags HTML injection in the body of an email. |
4745
| Client-side URL redirect | Fewer false-positive results | This rule now recognizes safe redirects in more cases. |
4846
| Server-side URL redirect | Fewer false-positive results | This rule now recognizes safe redirects in more cases. |
47+
| Information exposure through a stack trace | More results | This rule now also flags cases where the entire exception object (including the stack trace) may be exposed. |
4948

5049
## Changes to QL libraries
5150

change-notes/1.19/extractor-javascript.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
2222
## Changes to code extraction
2323

24-
* Destructuring assignments are now modeled more precisely, which fixes both false-negative and false-positive results for the rules
25-
"Missing variable declaration" and "Useless assignment to local variable" in certain corner cases.
2624
* The TypeScript compiler is now bundled with the distribution, and no longer needs to be installed manually.
2725
Should the compiler version need to be overridden, set the `SEMMLE_TYPESCRIPT_HOME` environment variable to
2826
point to an installation of the `typescript` NPM package.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
void* f() {
2-
block = malloc(BLOCK_SIZE);
2+
block = (MyBlock *)malloc(sizeof(MyBlock));
33
if (block) { //correct: block is checked for nullness here
44
block->id = NORMAL_BLOCK_ID;
55
}
66
//...
77
/* make sure data-portion is null-terminated */
8-
block[BLOCK_SIZE - 1] = '\0'; //wrong: block not checked for nullness here
8+
block->data[BLOCK_SIZE - 1] = '\0'; //wrong: block not checked for nullness here
99
return block;
1010
}

cpp/ql/src/Critical/OverflowCalculated.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
void f(char* string) {
2-
// wrong: allocates space for characters, put not zero terminator
2+
// wrong: allocates space for characters, but not zero terminator
33
char* buf = malloc(strlen(string));
44
strcpy(buf, string);
55

cpp/ql/src/Likely Bugs/Likely Typos/ExprHasNoEffect.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ where // EQExprs are covered by CompareWhereAssignMeant.ql
100100
not accessInInitOfForStmt(peivc) and
101101
not peivc.isCompilerGenerated() and
102102
not exists(Macro m | peivc = m.getAnInvocation().getAnExpandedElement()) and
103+
not peivc.isFromTemplateInstantiation(_) and
103104
parent = peivc.getParent() and
104105
not parent.isInMacroExpansion() and
105106
not parent instanceof PureExprInVoidContext and
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#define FLAGS 0x4004
2+
3+
void f_warning(int i)
4+
{
5+
// The usage of the logical not operator in this case is unlikely to be correct
6+
// as the output is being used as an operator for a bit-wise and operation
7+
if (i & !FLAGS)
8+
{
9+
// code
10+
}
11+
}
12+
13+
14+
void f_fixed(int i)
15+
{
16+
if (i & ~FLAGS) // Changing the logical not operator for the bit-wise not operator would fix this logic
17+
{
18+
// code
19+
}
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
<overview>
7+
<p>This rule finds logical-not operator usage as an operator for in a bit-wise operation.</p>
8+
9+
<p>Due to the nature of logical operation result value, only the lowest bit could possibly be set, and it is unlikely to be intent in bitwise opeartions. Violations are often indicative of a typo, using a logical-not (<code>!</code>) opeartor instead of the bit-wise not (<code>~</code>) operator. </p>
10+
<p>This rule is restricted to analyze bit-wise and (<code>&amp;</code>) and bit-wise or (<code>|</code>) operation in order to provide better precision.</p>
11+
<p>This rule ignores instances where a double negation (<code>!!</code>) is explicitly used as the opeartor of the bitwise operation, as this is a commonly used as a mechanism to normalize an integer value to either 1 or 0.</p>
12+
<p>NOTE: It is not recommended to use this rule in kernel code or older C code as it will likely find several false positive instances.</p>
13+
14+
</overview>
15+
<recommendation>
16+
<p>Carefully inspect the flagged expressions. Consider the intent in the code logic, and decide whether it is necessary to change the not operator.</p>
17+
</recommendation>
18+
19+
<example><sample src="IncorrectNotOperatorUsage.cpp" /></example>
20+
21+
<references>
22+
<li>
23+
<a href="https://docs.microsoft.com/en-us/visualstudio/code-quality/c6317?view=vs-2017">warning C6317: incorrect operator: logical-not (!) is not interchangeable with ones-complement (~)</a>
24+
</li>
25+
</references>
26+
</qhelp>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @name Incorrect Not Operator Usage
3+
* @description Usage of a logical-not (!) operator as an operand for a bit-wise operation.
4+
* This commonly indicates the usage of an incorrect operator instead of the bit-wise not (~) operator,
5+
* also known as ones' complement operator.
6+
* @kind problem
7+
* @id cpp/incorrect-not-operator-usage
8+
* @problem.severity warning
9+
* @precision medium
10+
* @tags security
11+
* external/cwe/cwe-480
12+
* external/microsoft/c6317
13+
*/
14+
15+
import cpp
16+
17+
/**
18+
* It's common in some projects to use "a double negation" to normalize the boolean
19+
* result to either 1 or 0.
20+
* This predciate is intended to filter explicit usage of a double negation as it typically
21+
* indicates the explicit purpose to normalize the result for bit-wise or arithmetic purposes.
22+
*/
23+
predicate doubleNegationNormalization( NotExpr notexpr ){
24+
notexpr.getAnOperand() instanceof NotExpr
25+
}
26+
27+
from BinaryBitwiseOperation binbitwop
28+
where exists( NotExpr notexpr |
29+
binbitwop.getAnOperand() = notexpr
30+
and not doubleNegationNormalization(notexpr)
31+
and ( binbitwop instanceof BitwiseAndExpr
32+
or binbitwop instanceof BitwiseOrExpr )
33+
)
34+
select binbitwop, "Usage of a logical not (!) expression as a bitwise operator."
35+

0 commit comments

Comments
 (0)