Skip to content

Commit 3332f70

Browse files
committed
PS: Mirror the changes from #20300.
1 parent c83268f commit 3332f70

File tree

9 files changed

+22
-129
lines changed

9 files changed

+22
-129
lines changed

powershell/ql/lib/semmle/code/powershell/controlflow/BasicBlocks.qll

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
private import powershell
44
private import ControlFlowGraph
55
private import CfgNodes
6-
private import SuccessorTypes
76
private import internal.ControlFlowGraphImpl as CfgImpl
87
private import CfgImpl::BasicBlocks as BasicBlocksImpl
98
private import codeql.controlflow.BasicBlock as BB
@@ -163,13 +162,9 @@ private class BasicBlockAlias = BasicBlock;
163162

164163
private class EntryBasicBlockAlias = EntryBasicBlock;
165164

166-
private class SuccessorTypeAlias = SuccessorType;
167-
168165
module Cfg implements BB::CfgSig<Location> {
169166
class ControlFlowNode = CfgNode;
170167

171-
class SuccessorType = SuccessorTypeAlias;
172-
173168
class BasicBlock = BasicBlockAlias;
174169

175170
class EntryBasicBlock = EntryBasicBlockAlias;

powershell/ql/lib/semmle/code/powershell/controlflow/ControlFlowGraph.qll

Lines changed: 1 addition & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/** Provides classes representing the control flow graph. */
22

3+
import codeql.controlflow.SuccessorType
34
private import powershell
45
private import BasicBlocks
5-
private import SuccessorTypes
66
private import internal.ControlFlowGraphImpl as CfgImpl
77
private import internal.Splitting as Splitting
88
private import internal.Completion
@@ -57,73 +57,6 @@ class CfgNode extends CfgImpl::Node {
5757
BasicBlock getBasicBlock() { result.getANode() = this }
5858
}
5959

60-
/** The type of a control flow successor. */
61-
class SuccessorType extends CfgImpl::TSuccessorType {
62-
/** Gets a textual representation of successor type. */
63-
string toString() { none() }
64-
}
65-
66-
/** Provides different types of control flow successor types. */
67-
module SuccessorTypes {
68-
/** A normal control flow successor. */
69-
class NormalSuccessor extends SuccessorType, CfgImpl::TSuccessorSuccessor {
70-
final override string toString() { result = "successor" }
71-
}
72-
73-
/**
74-
* A conditional control flow successor. Either a Boolean successor (`BooleanSuccessor`)
75-
* or a matching successor (`MatchingSuccessor`)
76-
*/
77-
abstract class ConditionalSuccessor extends SuccessorType {
78-
boolean value;
79-
80-
bindingset[value]
81-
ConditionalSuccessor() { any() }
82-
83-
/** Gets the Boolean value of this successor. */
84-
final boolean getValue() { result = value }
85-
86-
override string toString() { result = this.getValue().toString() }
87-
}
88-
89-
class BooleanSuccessor extends ConditionalSuccessor, CfgImpl::TBooleanSuccessor {
90-
BooleanSuccessor() { this = CfgImpl::TBooleanSuccessor(value) }
91-
}
92-
93-
class MatchingSuccessor extends ConditionalSuccessor, CfgImpl::TMatchingSuccessor {
94-
MatchingSuccessor() { this = CfgImpl::TMatchingSuccessor(value) }
95-
}
96-
97-
class ReturnSuccessor extends SuccessorType, CfgImpl::TReturnSuccessor {
98-
final override string toString() { result = "return" }
99-
}
100-
101-
class BreakSuccessor extends SuccessorType, CfgImpl::TBreakSuccessor {
102-
final override string toString() { result = "break" }
103-
}
104-
105-
class ContinueSuccessor extends SuccessorType, CfgImpl::TContinueSuccessor {
106-
final override string toString() { result = "continue" }
107-
}
108-
109-
class ThrowSuccessor extends SuccessorType, CfgImpl::TThrowSuccessor {
110-
final override string toString() { result = "throw" }
111-
}
112-
113-
class ExitSuccessor extends SuccessorType, CfgImpl::TExitSuccessor {
114-
final override string toString() { result = "exit" }
115-
}
116-
117-
class EmptinessSuccessor extends ConditionalSuccessor, CfgImpl::TEmptinessSuccessor {
118-
EmptinessSuccessor() { this = CfgImpl::TEmptinessSuccessor(value) }
119-
120-
/** Holds if this is an empty successor. */
121-
predicate isEmpty() { value = true }
122-
123-
override string toString() { if this.isEmpty() then result = "empty" else result = "non-empty" }
124-
}
125-
}
126-
12760
class Split = Splitting::Split;
12861

12962
/** Provides different kinds of control flow graph splittings. */

powershell/ql/lib/semmle/code/powershell/controlflow/internal/Completion.qll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
private import powershell
88
private import semmle.code.powershell.controlflow.ControlFlowGraph
99
private import ControlFlowGraphImpl as CfgImpl
10-
private import SuccessorTypes
1110
private import codeql.util.Boolean
1211

1312
// TODO: We most likely need a TrapCompletion as well
@@ -202,7 +201,7 @@ abstract class NormalCompletion extends Completion { }
202201

203202
/** A simple (normal) completion. */
204203
class SimpleCompletion extends NormalCompletion, TSimpleCompletion {
205-
override NormalSuccessor getAMatchingSuccessorType() { any() }
204+
override DirectSuccessor getAMatchingSuccessorType() { any() }
206205

207206
override string toString() { result = "simple" }
208207
}
@@ -293,7 +292,7 @@ class ContinueCompletion extends Completion, TContinueCompletion {
293292
* expression resulting in a thrown exception.
294293
*/
295294
class ThrowCompletion extends Completion, TThrowCompletion {
296-
override ThrowSuccessor getAMatchingSuccessorType() { any() }
295+
override ExceptionSuccessor getAMatchingSuccessorType() { any() }
297296

298297
override string toString() { result = "throw" }
299298
}

powershell/ql/lib/semmle/code/powershell/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,10 @@ private module CfgInput implements CfgShared::InputSig<Location> {
3636
scope.(Impl::CfgScope).exit(last, c)
3737
}
3838

39-
class SuccessorType = Cfg::SuccessorType;
39+
private class SuccessorType = Cfg::SuccessorType;
4040

4141
SuccessorType getAMatchingSuccessorType(Completion c) { result = c.getAMatchingSuccessorType() }
4242

43-
predicate successorTypeIsSimple(SuccessorType t) {
44-
t instanceof Cfg::SuccessorTypes::NormalSuccessor
45-
}
46-
47-
predicate successorTypeIsCondition(SuccessorType t) {
48-
t instanceof Cfg::SuccessorTypes::ConditionalSuccessor
49-
}
50-
51-
predicate isAbnormalExitType(SuccessorType t) {
52-
t instanceof Cfg::SuccessorTypes::ThrowSuccessor or
53-
t instanceof Cfg::SuccessorTypes::ExitSuccessor
54-
}
55-
5643
private predicate id(Raw::Ast node1, Raw::Ast node2) { node1 = node2 }
5744

5845
private predicate idOf(Raw::Ast node, int id) = equivalenceRelation(id/2)(node, id)
@@ -927,20 +914,3 @@ CfgScope getCfgScope(Ast n) {
927914
pragma[only_bind_into](result) = getCfgScopeImpl(n0)
928915
)
929916
}
930-
931-
cached
932-
private module Cached {
933-
cached
934-
newtype TSuccessorType =
935-
TSuccessorSuccessor() or
936-
TBooleanSuccessor(Boolean b) or
937-
TReturnSuccessor() or
938-
TBreakSuccessor() or
939-
TContinueSuccessor() or
940-
TThrowSuccessor() or
941-
TExitSuccessor() or
942-
TMatchingSuccessor(Boolean b) or
943-
TEmptinessSuccessor(Boolean b)
944-
}
945-
946-
import Cached

powershell/ql/lib/semmle/code/powershell/controlflow/internal/Splitting.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ private import powershell
66
private import Completion as Comp
77
private import Comp
88
private import ControlFlowGraphImpl
9-
private import Cfg::SuccessorTypes
109
private import semmle.code.powershell.controlflow.ControlFlowGraph as Cfg
1110

1211
cached

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ private module DataFlowIntegrationInput implements Impl::DataFlowIntegrationInpu
344344
* from `bb1` to `bb2`.
345345
*/
346346
predicate hasValueBranchEdge(BasicBlock bb1, BasicBlock bb2, GuardValue branch) {
347-
exists(Cfg::SuccessorTypes::ConditionalSuccessor s |
347+
exists(Cfg::ConditionalSuccessor s |
348348
this.getBasicBlock() = bb1 and
349349
bb2 = bb1.getASuccessor(s) and
350350
s.getValue() = branch

powershell/ql/src/experimental/ConvertToSecureStringAsPlainText.ql

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
* security
1111
*/
1212

13-
import powershell
13+
import powershell
1414

15-
from CmdCall c
16-
where
17-
c.matchesName("ConvertTo-SecureString") and
18-
c.hasNamedArgument("asplaintext")
19-
select c, "Use of AsPlainText parameter in ConvertTo-SecureString call"
15+
from CmdCall c
16+
where
17+
c.matchesName("ConvertTo-SecureString") and
18+
c.hasNamedArgument("asplaintext")
19+
select c, "Use of AsPlainText parameter in ConvertTo-SecureString call"

powershell/ql/src/experimental/UseOfReservedCmdletChar.ql

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010
* security
1111
*/
1212

13-
import powershell
13+
import powershell
1414

1515
class ReservedCharacter extends string {
16-
ReservedCharacter() {
17-
this = [
18-
"!", "@", "#", "$",
19-
"&", "*", "(", ")",
20-
"+", "=", "{", "^",
21-
"}", "[", "]", "|",
22-
";", ":", "'", "\"",
23-
"<", ">", ",", "?",
24-
"/", "~"]
25-
}
16+
ReservedCharacter() {
17+
this =
18+
[
19+
"!", "@", "#", "$", "&", "*", "(", ")", "+", "=", "{", "^", "}", "[", "]", "|", ";", ":",
20+
"'", "\"", "<", ">", ",", "?", "/", "~"
21+
]
22+
}
2623
}
2724

2825
from Function f, ReservedCharacter r
29-
where f.getLowerCaseName().matches("%"+ r + "%")
30-
select f, "Function name contains a reserved character: " + r
26+
where f.getLowerCaseName().matches("%" + r + "%")
27+
select f, "Function name contains a reserved character: " + r

powershell/ql/src/experimental/UsernameOrPasswordParameter.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* security
1111
*/
1212

13-
import powershell
13+
import powershell
1414

1515
from Parameter p
1616
where p.matchesName(["username", "password"])

0 commit comments

Comments
 (0)