Skip to content

Commit 91a6dce

Browse files
committed
PS: Add read step when we need unwrapping.
1 parent ea2f155 commit 91a6dce

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,18 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
641641
c.isKnownOrUnknownElement(ec) and
642642
index = ec.getIndex().asInt()
643643
)
644+
or
645+
c.isAnyElement() and
646+
exists(CfgNode cfgNode |
647+
node1 = TPreReturnNodeImpl(cfgNode, false) and
648+
node2.(ReturnNodeImpl).getCfgScope() = cfgNode.getScope()
649+
)
650+
or
651+
exists(CfgNode cfgNode |
652+
node1 = TImplicitWrapNode(cfgNode, true) and
653+
c.isAnyElement() and
654+
node2.(ReturnNodeImpl).getCfgScope() = cfgNode.getScope()
655+
)
644656
}
645657

646658
/**
@@ -668,6 +680,12 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
668680
or
669681
not exists(e.getValue().asInt())
670682
)
683+
or
684+
exists(CfgNode cfgNode |
685+
node1 = TPreReturnNodeImpl(cfgNode, true) and
686+
node2 = TImplicitWrapNode(cfgNode, true) and
687+
c.isSingleton(any(Content::KnownElementContent ec))
688+
)
671689
}
672690

673691
/**
@@ -676,15 +694,23 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
676694
* in `x.f = newValue`.
677695
*/
678696
predicate clearsContent(Node n, ContentSet c) {
697+
c.isSingleton(any(Content::FieldContent fc)) and
679698
n = any(PostUpdateNode pun | storeStep(_, c, pun)).getPreUpdateNode()
699+
or
700+
n = TPreReturnNodeImpl(_, false) and
701+
c.isAnyElement()
680702
}
681703

682704
/**
683705
* Holds if the value that is being tracked is expected to be stored inside content `c`
684706
* at node `n`.
685707
*/
686708
predicate expectsContent(Node n, ContentSet c) {
687-
none() // TODO
709+
n = TPreReturnNodeImpl(_, true) and
710+
c.isKnownOrUnknownElement(_)
711+
or
712+
n = TImplicitWrapNode(_, false) and
713+
c.isSingleton(any(Content::UnknownElementContent ec))
688714
}
689715

690716
class DataFlowType extends TDataFlowType {

0 commit comments

Comments
 (0)