11/** Provides definitions for working with uses of Android external storage */
22
33import java
4- import semmle.code.java.dataflow.DataFlow
4+ private import semmle.code.java.dataflow.DataFlow
55private import semmle.code.java.dataflow.ExternalFlow
66
77private class ExternalStorageDirSourceModel extends SourceModelCsv {
@@ -10,11 +10,11 @@ private class ExternalStorageDirSourceModel extends SourceModelCsv {
1010 [
1111 //"package;type;overrides;name;signature;ext;spec;kind"
1212 "android.content;Context;true;getExternalFilesDir;(String);;ReturnValue;android-external-storage-dir" ,
13- "android.content;Context;true;getExternalFilesDirs;(String);;ReturnValue.ArrayElement ;android-external-storage-dir" ,
14- "android.content;Context;true;getExternalCachesDir;(String );;ReturnValue;android-external-storage-dir" ,
15- "android.content;Context;true;getExternalCachesDirs;(String );;ReturnValue.ArrayElement ;android-external-storage-dir" ,
16- "android.os;Environment;false;getExternalStorageDirectory;(String );;ReturnValue.ArrayElement ;android-external-storage-dir" ,
17- "android.os;Environment;false;getExternalStoragePublicDirectory;(String);;ReturnValue.ArrayElement ;android-external-storage-dir" ,
13+ "android.content;Context;true;getExternalFilesDirs;(String);;ReturnValue;android-external-storage-dir" ,
14+ "android.content;Context;true;getExternalCacheDir;( );;ReturnValue;android-external-storage-dir" ,
15+ "android.content;Context;true;getExternalCacheDirs;( );;ReturnValue;android-external-storage-dir" ,
16+ "android.os;Environment;false;getExternalStorageDirectory;();;ReturnValue;android-external-storage-dir" ,
17+ "android.os;Environment;false;getExternalStoragePublicDirectory;(String);;ReturnValue;android-external-storage-dir" ,
1818 ]
1919 }
2020}
@@ -23,9 +23,13 @@ private predicate externalStorageFlowStep(DataFlow::Node node1, DataFlow::Node n
2323 DataFlow:: localFlowStep ( node1 , node2 )
2424 or
2525 exists ( ConstructorCall c | c .getConstructedType ( ) instanceof TypeFile |
26- node1 .asExpr ( ) = c .getArgument ( 1 ) and
26+ node1 .asExpr ( ) = c .getArgument ( 0 ) and
2727 node2 .asExpr ( ) = c
2828 )
29+ or
30+ node2 .asExpr ( ) .( ArrayAccess ) .getArray ( ) = node1 .asExpr ( )
31+ or
32+ node2 .asExpr ( ) .( FieldRead ) .getField ( ) .getInitializer ( ) = node1 .asExpr ( )
2933}
3034
3135private predicate externalStorageFlow ( DataFlow:: Node node1 , DataFlow:: Node node2 ) {
0 commit comments