Skip to content

Commit 7fe3c3d

Browse files
authored
Merge branch 'master' into python-mutating-descriptor
2 parents 3992346 + d776d9f commit 7fe3c3d

File tree

94 files changed

+2500
-1009
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

+2500
-1009
lines changed

change-notes/1.20/analysis-cpp.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
|-----------------------------|-----------|--------------------------------------------------------------------|
1111
| Use of string copy function in a condition (`cpp/string-copy-return-value-as-boolean`) | correctness | This query identifies calls to string copy functions used in conditions, where it's likely that a different function was intended to be called. |
1212
| Lossy function result cast (`cpp/lossy-function-result-cast`) | correctness | Finds function calls whose result type is a floating point type, which are implicitly cast to an integral type. Newly available but not displayed by default on LGTM. |
13+
| Array argument size mismatch (`cpp/array-arg-size-mismatch`) | reliability | Finds function calls where the size of an array being passed is smaller than the array size of the declared parameter. Newly displayed on LGTM. |
1314

1415
## Changes to existing queries
1516

1617
| **Query** | **Expected impact** | **Change** |
1718
|----------------------------|------------------------|------------------------------------------------------------------|
19+
| Array argument size mismatch (`cpp/array-arg-size-mismatch`) | Fewer false positives | An exception has been added to this query for variable sized arrays. |
1820
| Suspicious add with sizeof (`cpp/suspicious-add-sizeof`) | Fewer false positives | Pointer arithmetic on `char * const` expressions (and other variations of `char *`) are now correctly excluded from the results. |
1921
| Suspicious pointer scaling (`cpp/suspicious-pointer-scaling`) | Fewer false positives | False positives involving types that are not uniquely named in the snapshot have been fixed. |
2022
| Call to memory access function may overflow buffer (`cpp/overflow-buffer`) | More correct results | Calls to `fread` are now examined by this query. |

change-notes/1.20/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
| Useless assignment to property. | Fewer false-positive results | This rule now treats assignments with complex right-hand sides correctly. |
3838
| Unsafe dynamic method access | Fewer false-positive results | This rule no longer flags concatenated strings as unsafe method names. |
3939
| Unvalidated dynamic method call | More true-positive results | This rule now flags concatenated strings as unvalidated method names in more cases. |
40+
| Useless conditional | More true-positive results | This rule now flags additional uses of function call values. |
4041

4142
## Changes to QL libraries
4243

change-notes/1.20/analysis-python.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ Removes false positives seen when using Python 3.6, but not when using earlier v
1414
| **Query** | **Tags** | **Purpose** |
1515
|-----------------------------|-----------|--------------------------------------------------------------------|
1616
| Default version of SSL/TLS may be insecure (`py/insecure-default-protocol`) | security, external/cwe/cwe-327 | Finds instances where an insecure default protocol may be used. Results are shown on LGTM by default. |
17+
| Overly permissive file permissions (`py/overly-permissive-file`) | security, external/cwe/cwe-732 | Finds instances where a file is created with overly permissive permissions. Results are not shown on LGTM by default. |
1718
| Use of insecure SSL/TLS version (`py/insecure-protocol`) | security, external/cwe/cwe-327 | Finds instances where a known insecure protocol has been specified. Results are shown on LGTM by default. |
1819

1920
## Changes to existing queries
2021

2122
| **Query** | **Expected impact** | **Change** |
2223
|----------------------------|------------------------|------------------------------------------------------------------|
24+
| Comparison using is when operands support \_\_eq\_\_ (`py/comparison-using-is`) | Fewer false positive results | Results where one of the objects being compared is an enum member are no longer reported. |
2325
| Mutation of descriptor in \_\_get\_\_ or \_\_set\_\_ method (`py/mutable-descriptor`) | Fewer false positive results | Results where the mutation does not occur when calling one of the `__get__`, `__set__` or `__delete__` methods are no longer reported. |
2426
| Unused import (`py/unused-import`) | Fewer false positive results | Results where the imported module is used in a `doctest` string are no longer reported. |
2527
| Unused import (`py/unused-import`) | Fewer false positive results | Results where the imported module is used in a type-hint comment are no longer reported. |

cpp/config/suites/c/correctness

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
+ semmlecode-cpp-queries/Likely Bugs/Conversion/NonzeroValueCastToPointer.ql: /Correctness/Dangerous Conversions
88
+ semmlecode-cpp-queries/Likely Bugs/Conversion/ImplicitDowncastFromBitfield.ql: /Correctness/Dangerous Conversions
99
+ semmlecode-cpp-queries/Security/CWE/CWE-253/HResultBooleanConversion.ql: /Correctness/Dangerous Conversions
10-
# Consistent Use
10+
# Consistent Use
1111
+ semmlecode-cpp-queries/Critical/ReturnValueIgnored.ql: /Correctness/Consistent Use
1212
+ semmlecode-cpp-queries/Likely Bugs/InconsistentCheckReturnNull.ql: /Correctness/Consistent Use
1313
+ semmlecode-cpp-queries/Likely Bugs/InconsistentCallOnResult.ql: /Correctness/Consistent Use
1414
# Common Errors
1515
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/AssignWhereCompareMeant.ql: /Correctness/Common Errors
1616
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql: /Correctness/Common Errors
1717
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/ExprHasNoEffect.ql: /Correctness/Common Errors
18+
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/FutileParams.ql: /Correctness/Common Errors
1819
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/ShortCircuitBitMask.ql: /Correctness/Common Errors
1920
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/MissingEnumCaseInSwitch.ql: /Correctness/Common Errors
2021
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/FloatComparison.ql: /Correctness/Common Errors

cpp/config/suites/cpp/correctness

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
+ semmlecode-cpp-queries/Likely Bugs/Conversion/ImplicitDowncastFromBitfield.ql: /Correctness/Dangerous Conversions
99
+ semmlecode-cpp-queries/Likely Bugs/Conversion/CastArrayPointerArithmetic.ql: /Correctness/Dangerous Conversions
1010
+ semmlecode-cpp-queries/Security/CWE/CWE-253/HResultBooleanConversion.ql: /Correctness/Dangerous Conversions
11-
# Consistent Use
11+
# Consistent Use
1212
+ semmlecode-cpp-queries/Critical/ReturnValueIgnored.ql: /Correctness/Consistent Use
1313
+ semmlecode-cpp-queries/Likely Bugs/InconsistentCheckReturnNull.ql: /Correctness/Consistent Use
1414
+ semmlecode-cpp-queries/Likely Bugs/InconsistentCallOnResult.ql: /Correctness/Consistent Use
1515
# Common Errors
1616
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/AssignWhereCompareMeant.ql: /Correctness/Common Errors
1717
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/CompareWhereAssignMeant.ql: /Correctness/Common Errors
1818
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/ExprHasNoEffect.ql: /Correctness/Common Errors
19+
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/FutileParams.ql: /Correctness/Common Errors
1920
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/ShortCircuitBitMask.ql: /Correctness/Common Errors
2021
+ semmlecode-cpp-queries/Likely Bugs/Likely Typos/MissingEnumCaseInSwitch.ql: /Correctness/Common Errors
2122
+ semmlecode-cpp-queries/Likely Bugs/Arithmetic/FloatComparison.ql: /Correctness/Common Errors

cpp/ql/src/Likely Bugs/Conversion/ArrayArgSizeMismatch.ql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
* @kind problem
66
* @id cpp/array-arg-size-mismatch
77
* @problem.severity warning
8+
* @precision high
89
* @tags reliability
910
*/
1011
import cpp
12+
import semmle.code.cpp.commons.Buffer
1113

1214
from Function f, FunctionCall c, int i, ArrayType argType, ArrayType paramType, int a, int b
1315
where f = c.getTarget() and
@@ -17,6 +19,7 @@ where f = c.getTarget() and
1719
b = paramType.getArraySize() and
1820
argType.getBaseType().getSize() = paramType.getBaseType().getSize() and
1921
a < b and
22+
not memberMayBeVarSize(_, c.getArgument(i).(VariableAccess).getTarget()) and
2023
// filter out results for inconsistent declarations
2124
strictcount(f.getParameter(i).getType().getSize()) = 1
2225
select c.getArgument(i), "Array of size " + a +
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
void no_argument();
2+
3+
void one_argument(int x);
4+
5+
void calls() {
6+
no_argument(1) // BAD: `no_argument` will accept and ignore the argument
7+
8+
one_argument(1); // GOOD: `one_argument` will accept and use the argument
9+
10+
no_argument(); // GOOD: `no_argument` has not been passed an argument
11+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE qhelp PUBLIC
2+
"-//Semmle//qhelp//EN"
3+
"qhelp.dtd">
4+
<qhelp>
5+
6+
7+
<overview>
8+
<p>A function is called with arguments despite having an empty parameter list. This may indicate
9+
that the incorrect function is being called, or that the author misunderstood the function.</p>
10+
11+
<p>In C, a function declared with an empty parameter list `()` is considered to have an unknown
12+
parameter list, and therefore can be called with any set of arguments. To declare a function
13+
which takes no arguments, you must use `(void)` as the parameter list in any forward declarations.
14+
In C++, either style of declaration indicates that the function accepts no arguments.</p>
15+
16+
</overview>
17+
<recommendation>
18+
<p>Call the function without arguments, or call a different function that expects the arguments
19+
being passed.</p>
20+
21+
</recommendation>
22+
<example><sample src="FutileParams.c" />
23+
24+
</example>
25+
26+
<references>
27+
<li>SEI CERT C++ Coding Standard: <a href="https://wiki.sei.cmu.edu/confluence/display/c/DCL20-C.+Explicitly+specify+void+when+a+function+accepts+no+arguments"> DCL20-C. Explicitly specify void when a function accepts no arguments </a></li>
28+
</references>
29+
</qhelp>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* @name Non-empty call to function declared without parameters
3+
* @description A call to a function declared without parameters has arguments, which may indicate
4+
* that the code does not follow the author's intent.
5+
* @kind problem
6+
* @problem.severity warning
7+
* @precision very-high
8+
* @id cpp/futile-params
9+
* @tags correctness
10+
* maintainability
11+
*/
12+
13+
import cpp
14+
15+
from Function f, FunctionCall fc
16+
where fc.getTarget() = f
17+
and f.getNumberOfParameters() = 0
18+
and not f.isVarargs()
19+
and fc.getNumberOfArguments() != 0
20+
and not f instanceof BuiltInFunction
21+
and exists(FunctionDeclarationEntry fde | fde = f.getADeclarationEntry() | not fde.isImplicit())
22+
select fc, "This call has arguments, but $@ is not declared with any parameters.", f, f.toString()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.cpp:24:4:24:7 | arr3 | Array of size 3 passed to $@ which expects an array of size 4. | test.cpp:8:6:8:6 | g | g |

0 commit comments

Comments
 (0)