Skip to content

Commit 5ee37bc

Browse files
author
Robert Marsh
committed
Merge branch 'master' into ir-this-parameter-2
Bring in fix for duplicate virtual variables for parameter indirections
2 parents f8cfcef + 91da0d5 commit 5ee37bc

79 files changed

Lines changed: 1470 additions & 1145 deletions

File tree

Some content is hidden

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

change-notes/1.25/analysis-cpp.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ The following changes in version 1.25 affect C/C++ analysis in all applications.
4141
};
4242
```
4343
* The security pack taint tracking library (`semmle.code.cpp.security.TaintTracking`) now considers that equality checks may block the flow of taint. This results in fewer false positive results from queries that use this library.
44-
44+
* The length of a tainted string (such as the return value of a call to `strlen` or `strftime` with tainted parameters) is no longer itself considered tainted by the `models` library. This leads to fewer false positive results in queries that use any of our taint libraries.

cpp/ql/src/semmle/code/cpp/commons/unix/Constants.qll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
import cpp
66

7+
/**
8+
* Gets the number corresponding to the contents of `input` in base-8.
9+
* Note: the first character of `input` must be `0`. For example:
10+
* `parseOctal("012345") = 5349`.
11+
*/
712
bindingset[input]
813
int parseOctal(string input) {
914
input.charAt(0) = "0" and
@@ -15,44 +20,77 @@ int parseOctal(string input) {
1520
)
1621
}
1722

23+
/** Gets the number corresponding to the "set-user-ID on execute bit" in Unix. */
1824
int s_isuid() { result = parseOctal("04000") }
1925

26+
/** Gets the number corresponding to the "set-group-ID on execute bit" in Unix. */
2027
int s_isgid() { result = parseOctal("02000") }
2128

29+
/** Gets the number corresponding to the sticky bit in Unix. */
2230
int s_isvtx() { result = parseOctal("01000") }
2331

32+
/** Gets the number corresponding to the read permission bit for owner of the file in Unix. */
2433
int s_irusr() { result = parseOctal("0400") }
2534

35+
/** Gets the number corresponding to the write permission bit for owner of the file in Unix. */
2636
int s_iwusr() { result = parseOctal("0200") }
2737

38+
/** Gets the number corresponding to the execute permission bit for owner of the file in Unix. */
2839
int s_ixusr() { result = parseOctal("0100") }
2940

41+
/** Gets the number corresponding to the permissions `S_IRUSR | S_IWUSR | S_IXUSR` in Unix. */
3042
int s_irwxu() { result = s_irusr().bitOr(s_iwusr()).bitOr(s_ixusr()) }
3143

44+
/**
45+
* Gets the number corresponding to the read permission bit for the group
46+
* owner of the file in Unix.
47+
*/
3248
int s_irgrp() { result = s_irusr().bitShiftRight(3) }
3349

50+
/**
51+
* Gets the number corresponding to the write permission bit for the group
52+
* owner of the file in Unix.
53+
*/
3454
int s_iwgrp() { result = s_iwusr().bitShiftRight(3) }
3555

56+
/**
57+
* Gets the number corresponding to the execute permission bit for the group
58+
* owner of the file in Unix.
59+
*/
3660
int s_ixgrp() { result = s_ixusr().bitShiftRight(3) }
3761

62+
/** Gets the number corresponding to the permissions `S_IRGRP | S_IWGRP | S_IXGRP` in Unix. */
3863
int s_irwxg() { result = s_irwxu().bitShiftRight(3) }
3964

65+
/** Gets the number corresponding to the read permission bit for other users in Unix. */
4066
int s_iroth() { result = s_irgrp().bitShiftRight(3) }
4167

68+
/** Gets the number corresponding to the write permission bit for other users in Unix. */
4269
int s_iwoth() { result = s_iwgrp().bitShiftRight(3) }
4370

71+
/** Gets the number corresponding to the execute-or-search permission bit for other users in Unix. */
4472
int s_ixoth() { result = s_ixgrp().bitShiftRight(3) }
4573

74+
/** Gets the number corresponding to the permissions `S_IROTH | S_IWOTH | S_IXOTH` in Unix. */
4675
int s_irwxo() { result = s_irwxg().bitShiftRight(3) }
4776

77+
/**
78+
* Gets the number that can be used in a bitwise and with the file status flag
79+
* to produce a number representing the file access mode.
80+
*/
4881
int o_accmode() { result = parseOctal("0003") }
4982

83+
/** Gets the number corresponding to the read-only file access mode. */
5084
int o_rdonly() { result = parseOctal("00") }
5185

86+
/** Gets the number corresponding to the write-only file access mode. */
5287
int o_wronly() { result = parseOctal("01") }
5388

89+
/** Gets the number corresponding to the read-and-write file access mode. */
5490
int o_rdwr() { result = parseOctal("02") }
5591

92+
/** Gets the number corresponding to the file creation flag O_CREAT on Linux. */
5693
int o_creat() { result = parseOctal("0100") }
5794

95+
/** Gets the number corresponding to the file creation flag O_EXCL on Linux. */
5896
int o_excl() { result = parseOctal("0200") }

cpp/ql/src/semmle/code/cpp/controlflow/DefinitionsAndUses.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for reasoning about definitions and uses of variables.
3+
*/
4+
15
import cpp
26
private import semmle.code.cpp.controlflow.StackVariableReachability
37
private import semmle.code.cpp.dataflow.EscapesTree
@@ -135,6 +139,7 @@ library class DefOrUse extends ControlFlowNodeBase {
135139
}
136140
}
137141

142+
/** A definition of a stack variable. */
138143
library class Def extends DefOrUse {
139144
Def() { definition(_, this) }
140145

@@ -149,6 +154,7 @@ private predicate parameterIsOverwritten(Function f, Parameter p) {
149154
definitionBarrier(p, _)
150155
}
151156

157+
/** A definition of a parameter. */
152158
library class ParameterDef extends DefOrUse {
153159
ParameterDef() {
154160
// Optimization: parameters that are not overwritten do not require
@@ -162,6 +168,7 @@ library class ParameterDef extends DefOrUse {
162168
}
163169
}
164170

171+
/** A use of a stack variable. */
165172
library class Use extends DefOrUse {
166173
Use() { useOfVar(_, this) }
167174

cpp/ql/src/semmle/code/cpp/controlflow/Dereferenced.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides predicates for detecting whether an expression dereferences a pointer.
3+
*/
4+
15
import cpp
26
import Nullness
37

cpp/ql/src/semmle/code/cpp/controlflow/Guards.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provides classes and predicates for reasoning about guards and the control
3+
* flow elements controlled by those guards.
4+
*/
5+
16
import cpp
27
import semmle.code.cpp.controlflow.BasicBlocks
38
import semmle.code.cpp.controlflow.SSA

cpp/ql/src/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provides classes and predicates for reasoning about guards and the control
3+
* flow elements controlled by those guards.
4+
*/
5+
16
import cpp
27
import semmle.code.cpp.ir.IR
38

@@ -32,7 +37,7 @@ class GuardCondition extends Expr {
3237
}
3338

3439
/**
35-
* Holds if this condition controls `block`, meaning that `block` is only
40+
* Holds if this condition controls `controlled`, meaning that `controlled` is only
3641
* entered if the value of this condition is `testIsTrue`.
3742
*
3843
* Illustration:
@@ -253,7 +258,7 @@ class IRGuardCondition extends Instruction {
253258
IRGuardCondition() { branch = get_branch_for_condition(this) }
254259

255260
/**
256-
* Holds if this condition controls `block`, meaning that `block` is only
261+
* Holds if this condition controls `controlled`, meaning that `controlled` is only
257262
* entered if the value of this condition is `testIsTrue`.
258263
*
259264
* Illustration:
@@ -290,6 +295,10 @@ class IRGuardCondition extends Instruction {
290295
)
291296
}
292297

298+
/**
299+
* Holds if the control-flow edge `(pred, succ)` may be taken only if
300+
* the value of this condition is `testIsTrue`.
301+
*/
293302
cached
294303
predicate controlsEdge(IRBlock pred, IRBlock succ, boolean testIsTrue) {
295304
pred.getASuccessor() = succ and

cpp/ql/src/semmle/code/cpp/controlflow/Nullness.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for working with null values and checks for nullness.
3+
*/
4+
15
import cpp
26
import DefinitionsAndUses
37

cpp/ql/src/semmle/code/cpp/controlflow/SSA.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1+
/**
2+
* Provides classes and predicates for SSA representation (Static Single Assignment form).
3+
*/
4+
15
import cpp
26
import semmle.code.cpp.controlflow.Dominance
37
import SSAUtils
48

9+
/**
10+
* The SSA logic comes in two versions: the standard SSA and range-analysis RangeSSA.
11+
* This class provides the standard SSA logic.
12+
*/
513
library class StandardSSA extends SSAHelper {
614
StandardSSA() { this = 0 }
715
}
@@ -50,11 +58,13 @@ class SsaDefinition extends ControlFlowNodeBase {
5058
*/
5159
ControlFlowNode getDefinition() { result = this }
5260

61+
/** Gets the `BasicBlock` containing this definition. */
5362
BasicBlock getBasicBlock() { result.contains(getDefinition()) }
5463

5564
/** Holds if this definition is a phi node for variable `v`. */
5665
predicate isPhiNode(StackVariable v) { exists(StandardSSA x | x.phi_node(v, this.(BasicBlock))) }
5766

67+
/** Gets the location of this definition. */
5868
Location getLocation() { result = this.(ControlFlowNode).getLocation() }
5969

6070
/** Holds if the SSA variable `(this, p)` is defined by parameter `p`. */

cpp/ql/src/semmle/code/cpp/controlflow/SSAUtils.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/**
2+
* Provides classes and predicates for use in the SSA library.
3+
*/
4+
15
import cpp
26
import semmle.code.cpp.controlflow.Dominance
37
import semmle.code.cpp.controlflow.SSA // must be imported for proper caching of SSAHelper

cpp/ql/src/semmle/code/cpp/controlflow/StackVariableReachability.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Provides a library for working with local (intra-procedural) control-flow
3+
* reachability involving stack variables.
4+
*/
5+
16
import cpp
27

38
/**

0 commit comments

Comments
 (0)