Skip to content

Commit 1b8f3c4

Browse files
authored
Merge pull request github#3657 from hvitved/dataflow/hidden-nodes
Approved by aschackmull, jbj
2 parents 22d50f0 + a371205 commit 1b8f3c4

25 files changed

+458
-233
lines changed

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl2.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl3.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImpl4.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowImplLocal.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/dataflow/internal/DataFlowPrivate.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,3 +314,6 @@ predicate isImmutableOrUnobservable(Node n) {
314314
// The above list of cases isn't exhaustive, but it narrows down the
315315
// consistency alerts enough that most of them are interesting.
316316
}
317+
318+
/** Holds if `n` should be hidden from path explanations. */
319+
predicate nodeIsHidden(Node n) { none() }

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

cpp/ql/src/semmle/code/cpp/ir/dataflow/internal/DataFlowImpl2.qll

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,14 +2098,31 @@ class PathNode extends TPathNode {
20982098
/** Gets the associated configuration. */
20992099
Configuration getConfiguration() { none() }
21002100

2101+
private predicate isHidden() {
2102+
nodeIsHidden(this.getNode()) and
2103+
not this.isSource() and
2104+
not this instanceof PathNodeSink
2105+
}
2106+
2107+
private PathNode getASuccessorIfHidden() {
2108+
this.isHidden() and
2109+
result = this.(PathNodeImpl).getASuccessorImpl()
2110+
}
2111+
21012112
/** Gets a successor of this node, if any. */
2102-
PathNode getASuccessor() { none() }
2113+
final PathNode getASuccessor() {
2114+
result = this.(PathNodeImpl).getASuccessorImpl().getASuccessorIfHidden*() and
2115+
not this.isHidden() and
2116+
not result.isHidden()
2117+
}
21032118

21042119
/** Holds if this node is a source. */
21052120
predicate isSource() { none() }
21062121
}
21072122

21082123
abstract private class PathNodeImpl extends PathNode {
2124+
abstract PathNode getASuccessorImpl();
2125+
21092126
private string ppAp() {
21102127
this instanceof PathNodeSink and result = ""
21112128
or
@@ -2180,7 +2197,7 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
21802197
result.getConfiguration() = unbind(this.getConfiguration())
21812198
}
21822199

2183-
override PathNodeImpl getASuccessor() {
2200+
override PathNodeImpl getASuccessorImpl() {
21842201
// an intermediate step to another intermediate node
21852202
result = getSuccMid()
21862203
or
@@ -2217,7 +2234,7 @@ private class PathNodeSink extends PathNodeImpl, TPathNodeSink {
22172234

22182235
override Configuration getConfiguration() { result = config }
22192236

2220-
override PathNode getASuccessor() { none() }
2237+
override PathNode getASuccessorImpl() { none() }
22212238

22222239
override predicate isSource() { config.isSource(node) }
22232240
}

0 commit comments

Comments
 (0)