Skip to content

Commit 209e084

Browse files
committed
Merge branch 'master' into ir-flow-fields
2 parents cde34c9 + b603a3d commit 209e084

File tree

82 files changed

+1578
-871
lines changed

Some content is hidden

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

82 files changed

+1578
-871
lines changed

cpp/ql/src/Critical/FileClosed.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import semmle.code.cpp.pointsto.PointsTo
22

3+
/** Holds if there exists a call to a function that might close the file specified by `e`. */
34
predicate closed(Expr e) {
45
fcloseCall(_, e) or
56
exists(ExprCall c |
@@ -8,10 +9,19 @@ predicate closed(Expr e) {
89
)
910
}
1011

12+
/** An expression for which there exists a function call that might close it. */
1113
class ClosedExpr extends PointsToExpr {
1214
ClosedExpr() { closed(this) }
1315

1416
override predicate interesting() { closed(this) }
1517
}
1618

19+
/**
20+
* Holds if `fc` is a call to a function that opens a file that might be closed. For example:
21+
* ```
22+
* FILE* f = fopen("file.txt", "r");
23+
* ...
24+
* fclose(f);
25+
* ```
26+
*/
1727
predicate fopenCallMayBeClosed(FunctionCall fc) { fopenCall(fc) and anythingPointsTo(fc) }

cpp/ql/src/Critical/LoopBounds.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22

33
import cpp
44

5+
/**
6+
* An assignment to a variable with the value `0`. For example:
7+
* ```
8+
* int x;
9+
* x = 0;
10+
* ```
11+
* but not:
12+
* ```
13+
* int x = 0;
14+
* ```
15+
*/
516
class ZeroAssignment extends AssignExpr {
617
ZeroAssignment() {
718
this.getAnOperand() instanceof VariableAccess and
819
this.getAnOperand() instanceof Zero
920
}
1021

22+
/** Gets a variable that is assigned the value `0`. */
1123
Variable assignedVariable() { result.getAnAccess() = this.getAnOperand() }
1224
}
1325

cpp/ql/src/Critical/MemoryFreed.qll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@ private predicate freed(Expr e) {
99
)
1010
}
1111

12+
/** An expression that might be deallocated. */
1213
class FreedExpr extends PointsToExpr {
1314
FreedExpr() { freed(this) }
1415

1516
override predicate interesting() { freed(this) }
1617
}
1718

19+
/**
20+
* An allocation expression that might be deallocated. For example:
21+
* ```
22+
* int* p = new int;
23+
* ...
24+
* delete p;
25+
* ```
26+
*/
1827
predicate allocMayBeFreed(AllocationExpr alloc) { anythingPointsTo(alloc) }

cpp/ql/src/JPL_C/LOC-3/Rule 17/BasicIntTypes.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ predicate allowedTypedefs(TypedefType t) {
3030
* Gets a type which appears literally in the declaration of `d`.
3131
*/
3232
Type getAnImmediateUsedType(Declaration d) {
33-
d.isDefined() and
33+
d.hasDefinition() and
3434
(
3535
result = d.(Function).getType() or
3636
result = d.(Variable).getType()

cpp/ql/src/Options.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* By default they fall back to the reasonable defaults provided in
66
* `DefaultOptions.qll`, but by modifying this file, you can customize
7-
* the standard Semmle analyses to give better results for your project.
7+
* the standard analyses to give better results for your project.
88
*/
99

1010
import cpp

cpp/ql/src/Security/CWE/CWE-457/InitializationFunctions.qll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ class InitializationFunction extends Function {
198198
)
199199
or
200200
// If we have no definition, we look at SAL annotations
201-
not this.isDefined() and
201+
not this.hasDefinition() and
202202
this.getParameter(i).(SALParameter).isOut() and
203203
evidence = SuggestiveSALAnnotation()
204204
or
205205
// We have some external information that this function conditionally initializes
206-
not this.isDefined() and
206+
not this.hasDefinition() and
207207
any(ValidatedExternalCondInitFunction vc).isExternallyVerified(this, i) and
208208
evidence = ExternalEvidence()
209209
}
@@ -406,7 +406,7 @@ class ConditionalInitializationFunction extends InitializationFunction {
406406
* Explicitly ignore pure virtual functions.
407407
*/
408408

409-
this.isDefined() and
409+
this.hasDefinition() and
410410
this.paramNotReassignedAt(this, i, c) and
411411
not this instanceof PureVirtualFunction
412412
)
@@ -616,11 +616,11 @@ private predicate functionSignature(Function f, string qualifiedName, string typ
616616
* are never statically linked together.
617617
*/
618618
private Function getAPossibleDefinition(Function undefinedFunction) {
619-
not undefinedFunction.isDefined() and
619+
not undefinedFunction.hasDefinition() and
620620
exists(string qn, string typeSig |
621621
functionSignature(undefinedFunction, qn, typeSig) and functionSignature(result, qn, typeSig)
622622
) and
623-
result.isDefined()
623+
result.hasDefinition()
624624
}
625625

626626
/**
@@ -631,7 +631,7 @@ private Function getAPossibleDefinition(Function undefinedFunction) {
631631
*/
632632
private Function getTarget1(Call c) {
633633
result = VirtualDispatch::getAViableTarget(c) and
634-
result.isDefined()
634+
result.hasDefinition()
635635
}
636636

637637
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ private predicate idOf(@compilation x, int y) = equivalenceRelation(id/2)(x, y)
2121
* Three things happen to each file during a compilation:
2222
*
2323
* 1. The file is compiled by a real compiler, such as gcc or VC.
24-
* 2. The file is parsed by Semmle's C++ front-end.
24+
* 2. The file is parsed by the CodeQL C++ front-end.
2525
* 3. The parsed representation is converted to database tables by
26-
* Semmle's extractor.
26+
* the CodeQL extractor.
2727
*
2828
* This class provides CPU and elapsed time information for steps 2 and 3,
2929
* but not for step 1.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ abstract class Declaration extends Locatable, @declaration {
161161
/** Holds if the declaration has a definition. */
162162
predicate hasDefinition() { exists(this.getDefinition()) }
163163

164+
/** DEPRECATED: Use `hasDefinition` instead. */
164165
predicate isDefined() { hasDefinition() }
165166

166167
/** Gets the preferred location of this declaration, if any. */
@@ -303,7 +304,7 @@ abstract class DeclarationEntry extends Locatable {
303304
* available), or the name declared by this entry otherwise.
304305
*/
305306
string getCanonicalName() {
306-
if getDeclaration().isDefined()
307+
if getDeclaration().hasDefinition()
307308
then result = getDeclaration().getDefinition().getName()
308309
else result = getName()
309310
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class UserType extends Type, Declaration, NameQualifyingElement, AccessHolder, @
3838
override Specifier getASpecifier() { result = Type.super.getASpecifier() }
3939

4040
override Location getLocation() {
41-
if isDefined()
41+
if hasDefinition()
4242
then result = this.getDefinitionLocation()
4343
else result = this.getADeclarationLocation()
4444
}

cpp/ql/src/semmle/code/cpp/dataflow/RecursionPrevention.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* DEPRECATED: Recursion through `DataFlow::Configuration` is impossible in
3-
* Semmle Core 1.17 and above. There is no need for this module because it's
3+
* any supported tooling. There is no need for this module because it's
44
* impossible to accidentally depend on recursion through
55
* `DataFlow::Configuration` in current releases.
66
*

0 commit comments

Comments
 (0)