Skip to content

Commit 59eea2a

Browse files
committed
Change FlowState classes to use IPAs instead of string
1 parent b6eeac5 commit 59eea2a

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

java/ql/lib/semmle/code/java/security/ArbitraryApkInstallationQuery.qll

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,28 @@ private module ApkInstallationConfiguration implements DataFlow::ConfigSig {
2727

2828
module ApkInstallationFlow = DataFlow::Make<ApkInstallationConfiguration>;
2929

30+
private newtype ActionState =
31+
ActionUnset() or
32+
HasInstallPackageAction()
33+
3034
/**
3135
* A dataflow configuration tracking the flow from the `android.content.Intent.ACTION_INSTALL_PACKAGE`
3236
* constant to either the constructor of an intent or the `setAction` method of an intent.
3337
*
3438
* This is used to track if an intent is used to install an APK.
3539
*/
3640
private module InstallPackageActionConfiguration implements DataFlow::StateConfigSig {
37-
class FlowState = string;
41+
class FlowState = ActionState;
3842

3943
predicate isSource(DataFlow::Node source, FlowState state) {
40-
source.asExpr() instanceof InstallPackageAction and state instanceof DataFlow::FlowStateEmpty
44+
source.asExpr() instanceof InstallPackageAction and state instanceof ActionUnset
4145
}
4246

4347
predicate isAdditionalFlowStep(
44-
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
45-
DataFlow::FlowState state2
48+
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
4649
) {
47-
state1 instanceof DataFlow::FlowStateEmpty and
48-
state2 = "hasPackageInstallAction" and
50+
state1 instanceof ActionUnset and
51+
state2 instanceof HasInstallPackageAction and
4952
(
5053
exists(ConstructorCall cc |
5154
cc.getConstructedType() instanceof TypeIntent and
@@ -62,8 +65,8 @@ private module InstallPackageActionConfiguration implements DataFlow::StateConfi
6265
)
6366
}
6467

65-
predicate isSink(DataFlow::Node node, DataFlow::FlowState state) {
66-
state = "hasPackageInstallAction" and node.asExpr().getType() instanceof TypeIntent
68+
predicate isSink(DataFlow::Node node, FlowState state) {
69+
state instanceof HasInstallPackageAction and node.asExpr().getType() instanceof TypeIntent
6770
}
6871

6972
predicate isBarrier(DataFlow::Node node, FlowState state) { none() }
@@ -72,25 +75,28 @@ private module InstallPackageActionConfiguration implements DataFlow::StateConfi
7275
private module InstallPackageActionFlow =
7376
TaintTracking::MakeWithState<InstallPackageActionConfiguration>;
7477

78+
private newtype MimeTypeState =
79+
MimeTypeUnset() or
80+
HasPackageArchiveMimeType()
81+
7582
/**
7683
* A dataflow configuration tracking the flow of the Android APK MIME type to
7784
* the `setType` or `setTypeAndNormalize` method of an intent, followed by a call
7885
* to `setData[AndType][AndNormalize]`.
7986
*/
8087
private module PackageArchiveMimeTypeConfiguration implements DataFlow::StateConfigSig {
81-
class FlowState = string;
88+
class FlowState = MimeTypeState;
8289

8390
predicate isSource(DataFlow::Node node, FlowState state) {
8491
node.asExpr() instanceof PackageArchiveMimeTypeLiteral and
85-
state instanceof DataFlow::FlowStateEmpty
92+
state instanceof MimeTypeUnset
8693
}
8794

8895
predicate isAdditionalFlowStep(
89-
DataFlow::Node node1, DataFlow::FlowState state1, DataFlow::Node node2,
90-
DataFlow::FlowState state2
96+
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
9197
) {
92-
state1 instanceof DataFlow::FlowStateEmpty and
93-
state2 = "typeSet" and
98+
state1 instanceof MimeTypeUnset and
99+
state2 instanceof HasPackageArchiveMimeType and
94100
exists(MethodAccess ma |
95101
ma.getQualifier() = node2.asExpr() and
96102
(
@@ -103,8 +109,8 @@ private module PackageArchiveMimeTypeConfiguration implements DataFlow::StateCon
103109
)
104110
}
105111

106-
predicate isSink(DataFlow::Node node, DataFlow::FlowState state) {
107-
state = "typeSet" and
112+
predicate isSink(DataFlow::Node node, FlowState state) {
113+
state instanceof HasPackageArchiveMimeType and
108114
node instanceof SetDataSink
109115
}
110116

0 commit comments

Comments
 (0)