Skip to content

Commit 811815a

Browse files
committed
Merge branch 'master' into python-cwe-312
2 parents 4f172bd + 4f26b58 commit 811815a

File tree

135 files changed

+12094
-2557
lines changed

Some content is hidden

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

135 files changed

+12094
-2557
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Improvements to C# analysis
2+
3+
The following changes in version 1.23 affect C# analysis in all applications.
4+
5+
## Changes to existing queries
6+
7+
| **Query** | **Expected impact** | **Change** |
8+
|------------------------------|------------------------|-----------------------------------|
9+
10+
## Removal of old queries
11+
12+
## Changes to code extraction
13+
14+
* `nameof` expressions are now extracted correctly when the name is a namespace.
15+
16+
## Changes to QL libraries
17+
18+
* The new class `NamespaceAccess` models accesses to namespaces, for example in `nameof` expressions.
19+
20+
## Changes to autobuilder
21+

cpp/ql/src/Likely Bugs/Leap Year/Adding365DaysPerYear.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* @name Year field changed using an arithmetic operation is used on an unchecked time conversion function
3-
* @description A year field changed using an arithmetic operation is used on a time conversion function, but the return value of the function is not checked for success or failure.
2+
* @name Arithmetic operation assumes 365 days per year
3+
* @description When an arithmetic operation modifies a date by a constant
4+
* value of 365, it may be a sign that leap years are not taken
5+
* into account.
46
* @kind problem
57
* @problem.severity warning
68
* @id cpp/leap-year/adding-365-days-per-year

cpp/ql/src/Likely Bugs/Leap Year/UncheckedReturnValueForTimeFunctions.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
2-
* @name Year field changed using an arithmetic operation is used on an unchecked time conversion function
3-
* @description A year field changed using an arithmetic operation is used on a time conversion function, but the return value of the function is not checked for success or failure
2+
* @name Unchecked return value for time conversion function
3+
* @description When the return value of a fallible time conversion function is
4+
* not checked for failure, its output parameters may contain
5+
* invalid dates.
46
* @kind problem
57
* @problem.severity warning
68
* @id cpp/leap-year/unchecked-return-value-for-time-conversion-function

cpp/ql/src/semmle/code/cpp/Enum.qll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ import semmle.code.cpp.Type
22
private import semmle.code.cpp.internal.ResolveClass
33

44
/**
5-
* A C/C++ enum [N4140 7.2]. For example, the type `MyEnum` in:
5+
* A C/C++ enum [N4140 7.2]. For example, the types `MyEnum` and
6+
* `MyScopedEnum` in:
67
* ```
78
* enum MyEnum {
89
* MyEnumConstant
910
* };
11+
*
12+
* enum class MyScopedEnum {
13+
* MyScopedEnumConstant
14+
* };
1015
* ```
1116
* This includes C++ scoped enums, see the `ScopedEnum` QL class.
1217
*/

cpp/ql/src/semmle/code/cpp/NameQualifiers.qll

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
import cpp
22

33
/**
4-
* A C++ name qualifier, for example `N::`.
4+
* A C++ name qualifier, for example `N::` in the following code:
5+
* ```
6+
* namespace N {
7+
* int f() {
8+
* ...
9+
* }
10+
* }
11+
*
12+
* int g() {
13+
* return N::f();
14+
* }
15+
* ```
516
*/
617
class NameQualifier extends NameQualifiableElement, @namequalifier {
718
/**
@@ -61,10 +72,21 @@ class NameQualifier extends NameQualifiableElement, @namequalifier {
6172

6273
/**
6374
* A C++ element that can be qualified with a name. This is in practice
64-
* either an expression or a name qualifier. For instance, in
65-
* `N1::N2::f()`, there are two name-qualifiable elements: the expression
66-
* `f()` and the name qualifier `N2::`. The former is qualified by `N2` and
67-
* the latter is qualified by `N1`.
75+
* either an expression or a name qualifier. For example, there are two
76+
* name-qualifiable elements in the following code, the expression `f()`
77+
* (which is qualified by `N::`), and the qualifier `N::` (which is not
78+
* itself qualified in this example):
79+
* ```
80+
* namespace N {
81+
* int f() {
82+
* ...
83+
* }
84+
* }
85+
*
86+
* int g() {
87+
* return N::f();
88+
* }
89+
* ```
6890
*/
6991
class NameQualifiableElement extends Element, @namequalifiableelement {
7092
/**
@@ -99,8 +121,19 @@ class NameQualifiableElement extends Element, @namequalifiableelement {
99121
}
100122

101123
/**
102-
* A C++ element that can qualify a name. For example, `N` in `N::f()`. A
103-
* name-qualifying element is either a namespace or a user-defined type.
124+
* A C++ element that can qualify a name. For example, the namespaces `A` and
125+
* `A::B` and the class `A::C` in the following code:
126+
* ```
127+
* namespace A {
128+
* namespace B {
129+
* ...
130+
* }
131+
*
132+
* class C {
133+
* ...
134+
* };
135+
* }
136+
* ```
104137
*/
105138
class NameQualifyingElement extends Element, @namequalifyingelement {
106139
/**

cpp/ql/src/semmle/code/cpp/exprs/Expr.qll

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,32 @@ class Expr extends StmtParent, @expr {
8585
override string toString() { none() }
8686

8787
/** Gets the value of this expression, if it is a constant. */
88-
string getValue() { exists(@value v | values(v,result,_) and valuebind(v,underlyingElement(this))) }
88+
string getValue() { exists(@value v | values(v,result) and valuebind(v,underlyingElement(this))) }
89+
90+
/** Gets the value text of this expression that's in the database. */
91+
private string getDbValueText() {
92+
exists(@value v | valuebind(v,underlyingElement(this)) and valuetext(v, result))
93+
}
94+
95+
/**
96+
* Gets the value text of `this`. If it doesn't have one, then instead
97+
* gets the value text is `this`'s nearest compatible conversion, if any.
98+
*/
99+
private string getValueTextFollowingConversions() {
100+
if exists(this.getDbValueText())
101+
then result = this.getDbValueText()
102+
else exists(Expr e |
103+
e = this.getConversion() and
104+
e.getValue() = this.getValue() and
105+
result = e.getValueTextFollowingConversions())
106+
}
89107

90108
/** Gets the source text for the value of this expression, if it is a constant. */
91-
string getValueText() { exists(@value v | values(v,_,result) and valuebind(v,underlyingElement(this))) }
109+
string getValueText() {
110+
if exists(this.getValueTextFollowingConversions())
111+
then result = this.getValueTextFollowingConversions()
112+
else result = this.getValue()
113+
}
92114

93115
/** Holds if this expression has a value that can be determined at compile time. */
94116
cached

cpp/ql/src/semmlecode.cpp.dbscheme

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,11 +1237,15 @@ expr_cond_false(
12371237
int false: @expr ref
12381238
);
12391239

1240-
// the second field is a string representation of the value
1241-
// the third field is the actual text in the source or the same as the second field
1240+
/** A string representation of the value. */
12421241
values(
12431242
unique int id: @value,
1244-
string str: string ref,
1243+
string str: string ref
1244+
);
1245+
1246+
/** The actual text in the source code for the value, if any. */
1247+
valuetext(
1248+
unique int id: @value ref,
12451249
string text: string ref
12461250
);
12471251

0 commit comments

Comments
 (0)