Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
hvitved committed Dec 4, 2024
1 parent 5dbdc9f commit ce6d80c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 51 deletions.
12 changes: 2 additions & 10 deletions shared/dataflow/codeql/dataflow/internal/DataFlowImpl.qll
Original file line number Diff line number Diff line change
Expand Up @@ -1143,16 +1143,8 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {
) {
exists(RetNodeEx ret |
flowOutOfCallNodeCand1(call, ret, _, out) and
c = ret.getEnclosingCallable()
|
c = ret.getEnclosingCallable() and
scope = getSecondLevelScopeEx(ret)
or
// ret = TParamReturnNode(_, scope)
ret = TParamReturnNode(_) and
scope.isNone() // todo
or
parameterNode(ret.asNodeReverse(_), _, _) and
scope.isNone() // todo
)
}

Expand Down Expand Up @@ -3481,7 +3473,7 @@ module MakeImpl<LocationSig Location, InputSig<Location> Lang> {

/** Gets the parameter node through which data is returned, if any. */
final ParameterNode asParameterReturnNode() {
result = super.getNodeEx().asParamReturnNode()
result = super.getNodeEx().asNodeReverse(_)
}

/** Gets the `FlowState` of this node. */
Expand Down
52 changes: 11 additions & 41 deletions shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,6 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
or
exists(Node n | this.isImplicitReadNode(n) | result = n.toString() + " [Ext]")
or
result = this.asParamReturnNode().toString() + " [Return]"
or
// exists(boolean b | result = this.asNodeReverse(b).toString() + " [Reverse, " + b + "]")
result = this.asNodeReverse(_).toString() + " [Reverse]"
}
Expand All @@ -887,12 +885,9 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {

predicate isImplicitReadNode(Node n) { this = TNodeImplicitRead(n) }

ParameterNode asParamReturnNode() { this = TParamReturnNode(result) }

Node projectToNode() {
this = TNodeNormal(result) or
this = TNodeImplicitRead(result) or
this = TParamReturnNode(result) or
this = TNodeReverse(result, _)
}

Expand All @@ -911,8 +906,6 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
nodeDataFlowType(this.asNode(), result)
or
nodeDataFlowType(this.asNodeReverse(_), result)
or
nodeDataFlowType(this.asParamReturnNode(), result)
}

pragma[inline]
Expand Down Expand Up @@ -981,12 +974,9 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
this.asNode().(ArgNode).argumentOf(call_.asDataFlowCall(true), pos_.asArgumentPosition())
or
exists(boolean b |
// this.asNodeReverse() = getAnOutNodeExt(call_, pos_.asReturnKind()) and
this.asNodeReverse(b) =
getAnOutNode(call_.asDataFlowCall(b), pos_.asReturnKind().(ValueReturnKind).getKind()) //and //and
pragma[only_bind_into](this.asNodeReverse(b)) =
getAnOutNode(call_.asDataFlowCall(b), pos_.asReturnKind().(ValueReturnKind).getKind())
)
// not this.asNodeReverse() instanceof PostUpdateNode // needed for swift
// call_.toString().matches("%GetBox1%")
}

predicate argumentOf(DataFlowCallEx call, ArgumentPositionEx pos) {
Expand Down Expand Up @@ -1084,8 +1074,8 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
}

cached
SndLevelScopeOption getSecondLevelScopeEx(NodeEx n) {
result = getSecondLevelScope0(n.asNode())
SndLevelScopeOption getSecondLevelScopeEx(RetNodeEx n) {
result = getSecondLevelScope0([n.asNode(), n.asNodeReverse(_)])
}

cached
Expand Down Expand Up @@ -1139,7 +1129,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {

cached
predicate hiddenNode(NodeEx n) {
nodeIsHidden([n.asNode(), n.asNodeReverse(_), n.asParamReturnNode()])
nodeIsHidden([n.asNode(), n.asNodeReverse(_)])
or
n instanceof TNodeImplicitRead
}
Expand Down Expand Up @@ -1205,10 +1195,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
}

cached
predicate castingNodeEx(NodeEx n) {
[n.asNode(), n.asNodeReverse(_)] instanceof CastingNode or
exists(n.asParamReturnNode())
}
predicate castingNodeEx(NodeEx n) { [n.asNode(), n.asNodeReverse(_)] instanceof CastingNode }

cached
predicate parameterNode(Node p, DataFlowCallable c, ParameterPosition pos) {
Expand Down Expand Up @@ -1790,7 +1777,10 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
predicate readEx(NodeEx node1, ContentSet c, NodeEx node2) {
readSet(pragma[only_bind_into](node1.asNode()), c, pragma[only_bind_into](node2.asNode()))
or
exists(boolean b | storeSet(node2.asNodeReverse(b), c, node1.asNodeReverse(b), _, _))
exists(boolean b |
storeSet(pragma[only_bind_into](node2.asNodeReverse(b)), c,
pragma[only_bind_into](node1.asNodeReverse(b)), _, _)
)
}

cached
Expand Down Expand Up @@ -2028,11 +2018,7 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
cached
newtype TNodeEx =
TNodeNormal(Node n) or
TNodeImplicitRead(Node n) or // will be restricted to nodes with actual implicit reads in `DataFlowImpl.qll`
// TParamReturnNode(ParameterNode p, SndLevelScopeOption scope) {
// paramReturnNode(_, p, scope, _)
// } or
TParamReturnNode(ParameterNode p) or
TNodeImplicitRead(Node n) or
TNodeReverse(Node n, Boolean b)

/**
Expand All @@ -2046,17 +2032,6 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
simpleLocalFlowStepExt(pragma[only_bind_into](n1), pragma[only_bind_into](n2), model)
)
or
// or
// exists(Node n1, Node n2, SndLevelScopeOption scope |
// node1.asNode() = n1 and
// node2 = TParamReturnNode(n2, scope) and
// paramReturnNode(pragma[only_bind_into](n1), pragma[only_bind_into](n2),
// pragma[only_bind_into](scope), _) and
// model = ""
// )
// node2 = TParamReturnNode(node1.asNodeReverse()) and
// model = ""
// or
exists(Node n1, Node n2 |
node1.asNodeReverse(_) = n1 and
node2.asNodeReverse(false) = n2 and
Expand All @@ -2071,11 +2046,6 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
ReturnPosition getReturnPositionEx(NodeEx ret) {
result = getValueReturnPosition(ret.asNode())
or
exists(ParamNode p |
ret = TParamReturnNode(p) and
result = getParamReturnPosition(p)
)
or
exists(DataFlowCallable c, ParameterPosition ppos |
parameterNode(ret.asNodeReverse(_), c, ppos) and
result = TReverseReturnPosition(c, ppos) //and
Expand Down

0 comments on commit ce6d80c

Please sign in to comment.