Skip to content

Commit b3d83be

Browse files
committed
Revert "Merge pull request github#15599 from aschackmull/dataflow/fieldflowbranchlimit-v2"
This reverts commit b2f0994, reversing changes made to 19974f0.
1 parent 8e251ee commit b3d83be

File tree

20 files changed

+46
-325
lines changed

20 files changed

+46
-325
lines changed

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

-2
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,6 @@ predicate knownSourceModel(Node source, string model) { none() }
290290

291291
predicate knownSinkModel(Node sink, string model) { none() }
292292

293-
class DataFlowSecondLevelScope = Unit;
294-
295293
/**
296294
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
297295
* side-effect, resulting in a summary from `p` to itself.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowImplSpecific.qll

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ module CppDataFlow implements InputSig<Location> {
2222

2323
predicate getAdditionalFlowIntoCallNodeTerm = Private::getAdditionalFlowIntoCallNodeTerm/2;
2424

25-
predicate getSecondLevelScope = Private::getSecondLevelScope/1;
26-
2725
predicate validParameterAliasStep = Private::validParameterAliasStep/2;
2826

2927
predicate mayBenefitFromCallContext = Private::mayBenefitFromCallContext/1;

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowPrivate.qll

-82
Original file line numberDiff line numberDiff line change
@@ -1583,85 +1583,3 @@ predicate validParameterAliasStep(Node node1, Node node2) {
15831583
)
15841584
)
15851585
}
1586-
1587-
private predicate isTopLevel(Cpp::Stmt s) { any(Function f).getBlock().getAStmt() = s }
1588-
1589-
private Cpp::Stmt getAChainedBranch(Cpp::IfStmt s) {
1590-
result = s.getThen()
1591-
or
1592-
exists(Cpp::Stmt elseBranch | s.getElse() = elseBranch |
1593-
result = getAChainedBranch(elseBranch)
1594-
or
1595-
result = elseBranch and not elseBranch instanceof Cpp::IfStmt
1596-
)
1597-
}
1598-
1599-
private Instruction getAnInstruction(Node n) {
1600-
result = n.asInstruction()
1601-
or
1602-
not n instanceof InstructionNode and
1603-
result = n.asOperand().getUse()
1604-
or
1605-
result = n.(SsaPhiNode).getPhiNode().getBasicBlock().getFirstInstruction()
1606-
or
1607-
n.(IndirectInstruction).hasInstructionAndIndirectionIndex(result, _)
1608-
or
1609-
not n instanceof IndirectInstruction and
1610-
exists(Operand operand |
1611-
n.(IndirectOperand).hasOperandAndIndirectionIndex(operand, _) and
1612-
result = operand.getUse()
1613-
)
1614-
or
1615-
result = getAnInstruction(n.(PostUpdateNode).getPreUpdateNode())
1616-
}
1617-
1618-
private newtype TDataFlowSecondLevelScope =
1619-
TTopLevelIfBranch(Cpp::Stmt s) {
1620-
exists(Cpp::IfStmt ifstmt | s = getAChainedBranch(ifstmt) and isTopLevel(ifstmt))
1621-
} or
1622-
TTopLevelSwitchCase(Cpp::SwitchCase s) {
1623-
exists(Cpp::SwitchStmt switchstmt | s = switchstmt.getASwitchCase() and isTopLevel(switchstmt))
1624-
}
1625-
1626-
/**
1627-
* A second-level control-flow scope in a `switch` or a chained `if` statement.
1628-
*
1629-
* This is a `switch` case or a branch of a chained `if` statement, given that
1630-
* the `switch` or `if` statement is top level, that is, it is not nested inside
1631-
* other CFG constructs.
1632-
*/
1633-
class DataFlowSecondLevelScope extends TDataFlowSecondLevelScope {
1634-
/** Gets a textual representation of this element. */
1635-
string toString() {
1636-
exists(Cpp::Stmt s | this = TTopLevelIfBranch(s) | result = s.toString())
1637-
or
1638-
exists(Cpp::SwitchCase s | this = TTopLevelSwitchCase(s) | result = s.toString())
1639-
}
1640-
1641-
/** Gets the primary location of this element. */
1642-
Cpp::Location getLocation() {
1643-
exists(Cpp::Stmt s | this = TTopLevelIfBranch(s) | result = s.getLocation())
1644-
or
1645-
exists(Cpp::SwitchCase s | this = TTopLevelSwitchCase(s) | result = s.getLocation())
1646-
}
1647-
1648-
/**
1649-
* Gets a statement directly contained in this scope. For an `if` branch, this
1650-
* is the branch itself, and for a `switch case`, this is one the statements
1651-
* of that case branch.
1652-
*/
1653-
private Cpp::Stmt getAStmt() {
1654-
exists(Cpp::Stmt s | this = TTopLevelIfBranch(s) | result = s)
1655-
or
1656-
exists(Cpp::SwitchCase s | this = TTopLevelSwitchCase(s) | result = s.getAStmt())
1657-
}
1658-
1659-
/** Gets a data-flow node nested within this scope. */
1660-
Node getANode() {
1661-
getAnInstruction(result).getAst().(Cpp::ControlFlowNode).getEnclosingStmt().getParentStmt*() =
1662-
this.getAStmt()
1663-
}
1664-
}
1665-
1666-
/** Gets the second-level scope containing the node `n`, if any. */
1667-
DataFlowSecondLevelScope getSecondLevelScope(Node n) { result.getANode() = n }

cpp/ql/test/library-tests/dataflow/taint-tests/swap2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void test_copy_assignment_operator()
8484

8585
swap(z1, z2);
8686

87-
sink(z2.data1); // $ ir ast
87+
sink(z2.data1); // $ ir MISSING: ast
8888
sink(z1.data1); // $ SPURIOUS: ir ast=81:27 ast=82:16
8989
}
9090

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

-2
Original file line numberDiff line numberDiff line change
@@ -2882,8 +2882,6 @@ predicate knownSourceModel(Node source, string model) { sourceNode(source, _, mo
28822882

28832883
predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
28842884

2885-
class DataFlowSecondLevelScope = Unit;
2886-
28872885
/**
28882886
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
28892887
* side-effect, resulting in a summary from `p` to itself.

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.ql

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ module ArrayFlowConfig implements DataFlow::ConfigSig {
1414
mc.getAnArgument() = sink.asExpr()
1515
)
1616
}
17+
18+
int fieldFlowBranchLimit() { result = 100 }
1719
}
1820

1921
module ArrayFlow = DataFlow::Global<ArrayFlowConfig>;

csharp/ql/test/library-tests/dataflow/types/Types.ql

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module TypesConfig implements DataFlow::ConfigSig {
1818
mc.getAnArgument() = sink.asExpr()
1919
)
2020
}
21+
22+
int fieldFlowBranchLimit() { result = 1000 }
2123
}
2224

2325
import ValueFlowTest<TypesConfig>

go/ql/lib/semmle/go/dataflow/internal/DataFlowPrivate.qll

-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,6 @@ predicate knownSourceModel(Node source, string model) { sourceNode(source, _, mo
415415

416416
predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
417417

418-
class DataFlowSecondLevelScope = Unit;
419-
420418
/**
421419
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
422420
* side-effect, resulting in a summary from `p` to itself.

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowImplSpecific.qll

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ module JavaDataFlow implements InputSig<Location> {
2020

2121
Node exprNode(DataFlowExpr e) { result = Public::exprNode(e) }
2222

23-
predicate getSecondLevelScope = Private::getSecondLevelScope/1;
24-
2523
predicate mayBenefitFromCallContext = Private::mayBenefitFromCallContext/1;
2624

2725
predicate viableImplInCallContext = Private::viableImplInCallContext/2;

java/ql/lib/semmle/code/java/dataflow/internal/DataFlowPrivate.qll

-75
Original file line numberDiff line numberDiff line change
@@ -581,81 +581,6 @@ predicate knownSourceModel(Node source, string model) { sourceNode(source, _, mo
581581

582582
predicate knownSinkModel(Node sink, string model) { sinkNode(sink, _, model) }
583583

584-
private predicate isTopLevel(Stmt s) {
585-
any(Callable c).getBody() = s
586-
or
587-
exists(BlockStmt b | s = b.getAStmt() and isTopLevel(b))
588-
}
589-
590-
private Stmt getAChainedBranch(IfStmt s) {
591-
result = s.getThen()
592-
or
593-
exists(Stmt elseBranch | s.getElse() = elseBranch |
594-
result = getAChainedBranch(elseBranch)
595-
or
596-
result = elseBranch and not elseBranch instanceof IfStmt
597-
)
598-
}
599-
600-
private newtype TDataFlowSecondLevelScope =
601-
TTopLevelIfBranch(Stmt s) {
602-
exists(IfStmt ifstmt | s = getAChainedBranch(ifstmt) and isTopLevel(ifstmt))
603-
} or
604-
TTopLevelSwitchCase(SwitchCase s) {
605-
exists(SwitchStmt switchstmt | s = switchstmt.getACase() and isTopLevel(switchstmt))
606-
}
607-
608-
private SwitchCase getPrecedingCase(Stmt s) {
609-
result = s
610-
or
611-
exists(SwitchStmt switch, int i |
612-
s = switch.getStmt(i) and
613-
not s instanceof SwitchCase and
614-
result = getPrecedingCase(switch.getStmt(i - 1))
615-
)
616-
}
617-
618-
/**
619-
* A second-level control-flow scope in a `switch` or a chained `if` statement.
620-
*
621-
* This is a `switch` case or a branch of a chained `if` statement, given that
622-
* the `switch` or `if` statement is top level, that is, it is not nested inside
623-
* other CFG constructs.
624-
*/
625-
class DataFlowSecondLevelScope extends TDataFlowSecondLevelScope {
626-
/** Gets a textual representation of this element. */
627-
string toString() {
628-
exists(Stmt s | this = TTopLevelIfBranch(s) | result = s.toString())
629-
or
630-
exists(SwitchCase s | this = TTopLevelSwitchCase(s) | result = s.toString())
631-
}
632-
633-
/**
634-
* Gets a statement directly contained in this scope. For an `if` branch, this
635-
* is the branch itself, and for a `switch case`, this is one the statements
636-
* of that case branch.
637-
*/
638-
private Stmt getAStmt() {
639-
exists(Stmt s | this = TTopLevelIfBranch(s) | result = s)
640-
or
641-
exists(SwitchCase s | this = TTopLevelSwitchCase(s) |
642-
result = s.getRuleStatement() or
643-
s = getPrecedingCase(result)
644-
)
645-
}
646-
647-
/** Gets a data-flow node nested within this scope. */
648-
Node getANode() { getRelatedExpr(result).getAnEnclosingStmt() = this.getAStmt() }
649-
}
650-
651-
private Expr getRelatedExpr(Node n) {
652-
n.asExpr() = result or
653-
n.(PostUpdateNode).getPreUpdateNode().asExpr() = result
654-
}
655-
656-
/** Gets the second-level scope containing the node `n`, if any. */
657-
DataFlowSecondLevelScope getSecondLevelScope(Node n) { result.getANode() = n }
658-
659584
/**
660585
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
661586
* side-effect, resulting in a summary from `p` to itself.

java/ql/test/library-tests/frameworks/guava/handwritten/flow.ql

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module ValueFlowConfig implements DataFlow::ConfigSig {
1818
predicate isSink(DataFlow::Node n) {
1919
exists(MethodCall ma | ma.getMethod().hasName("sink") | n.asExpr() = ma.getAnArgument())
2020
}
21+
22+
int fieldFlowBranchLimit() { result = 100 }
2123
}
2224

2325
module ValueFlow = DataFlow::Global<ValueFlowConfig>;

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

-2
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,6 @@ predicate knownSinkModel(Node sink, string model) {
10871087
sink = ModelOutput::getASinkNode(_, model).asSink()
10881088
}
10891089

1090-
class DataFlowSecondLevelScope = Unit;
1091-
10921090
/**
10931091
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
10941092
* side-effect, resulting in a summary from `p` to itself.

ruby/ql/lib/codeql/ruby/dataflow/internal/DataFlowPrivate.qll

-2
Original file line numberDiff line numberDiff line change
@@ -2254,8 +2254,6 @@ predicate knownSinkModel(Node sink, string model) {
22542254
sink = ModelOutput::getASinkNode(_, model).asSink()
22552255
}
22562256

2257-
class DataFlowSecondLevelScope = Unit;
2258-
22592257
/**
22602258
* Holds if flow is allowed to pass from parameter `p` and back to itself as a
22612259
* side-effect, resulting in a summary from `p` to itself.

shared/dataflow/change-notes/released/0.2.6.md

-5
This file was deleted.

shared/dataflow/codeql/dataflow/DataFlow.qll

-18
Original file line numberDiff line numberDiff line change
@@ -308,24 +308,6 @@ signature module InputSig<LocationSig Location> {
308308
*/
309309
default int getAdditionalFlowIntoCallNodeTerm(ArgumentNode arg, ParameterNode p) { none() }
310310

311-
/**
312-
* A second-level control-flow scope in a callable.
313-
*
314-
* This is used to provide a more fine-grained separation of a callable
315-
* context for the purpose of identifying uncertain control flow. For most
316-
* languages, this is not needed, as this separation is handled through
317-
* virtual dispatch, but for some cases (for example, C++) this can be used to
318-
* identify, for example, large top-level switch statements acting like
319-
* virtual dispatch.
320-
*/
321-
class DataFlowSecondLevelScope {
322-
/** Gets a textual representation of this element. */
323-
string toString();
324-
}
325-
326-
/** Gets the second-level scope containing the node `n`, if any. */
327-
default DataFlowSecondLevelScope getSecondLevelScope(Node n) { none() }
328-
329311
bindingset[call, p, arg]
330312
default predicate golangSpecificParamArgFilter(
331313
DataFlowCall call, ParameterNode p, ArgumentNode arg

0 commit comments

Comments
 (0)