mirror of
https://github.com/github/codeql.git
synced 2025-12-21 11:16:30 +01:00
Fix failing test cases
This commit is contained in:
committed by
Tony Torralba
parent
810854d6b5
commit
cb717a22bf
@@ -1,7 +1,7 @@
|
|||||||
/** Provides definitions for working with uses of Android external storage */
|
/** Provides definitions for working with uses of Android external storage */
|
||||||
|
|
||||||
import java
|
import java
|
||||||
import semmle.code.java.dataflow.DataFlow
|
private import semmle.code.java.dataflow.DataFlow
|
||||||
private import semmle.code.java.dataflow.ExternalFlow
|
private import semmle.code.java.dataflow.ExternalFlow
|
||||||
|
|
||||||
private class ExternalStorageDirSourceModel extends SourceModelCsv {
|
private class ExternalStorageDirSourceModel extends SourceModelCsv {
|
||||||
@@ -10,11 +10,11 @@ private class ExternalStorageDirSourceModel extends SourceModelCsv {
|
|||||||
[
|
[
|
||||||
//"package;type;overrides;name;signature;ext;spec;kind"
|
//"package;type;overrides;name;signature;ext;spec;kind"
|
||||||
"android.content;Context;true;getExternalFilesDir;(String);;ReturnValue;android-external-storage-dir",
|
"android.content;Context;true;getExternalFilesDir;(String);;ReturnValue;android-external-storage-dir",
|
||||||
"android.content;Context;true;getExternalFilesDirs;(String);;ReturnValue.ArrayElement;android-external-storage-dir",
|
"android.content;Context;true;getExternalFilesDirs;(String);;ReturnValue;android-external-storage-dir",
|
||||||
"android.content;Context;true;getExternalCachesDir;(String);;ReturnValue;android-external-storage-dir",
|
"android.content;Context;true;getExternalCacheDir;();;ReturnValue;android-external-storage-dir",
|
||||||
"android.content;Context;true;getExternalCachesDirs;(String);;ReturnValue.ArrayElement;android-external-storage-dir",
|
"android.content;Context;true;getExternalCacheDirs;();;ReturnValue;android-external-storage-dir",
|
||||||
"android.os;Environment;false;getExternalStorageDirectory;(String);;ReturnValue.ArrayElement;android-external-storage-dir",
|
"android.os;Environment;false;getExternalStorageDirectory;();;ReturnValue;android-external-storage-dir",
|
||||||
"android.os;Environment;false;getExternalStoragePublicDirectory;(String);;ReturnValue.ArrayElement;android-external-storage-dir",
|
"android.os;Environment;false;getExternalStoragePublicDirectory;(String);;ReturnValue;android-external-storage-dir",
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,9 +23,13 @@ private predicate externalStorageFlowStep(DataFlow::Node node1, DataFlow::Node n
|
|||||||
DataFlow::localFlowStep(node1, node2)
|
DataFlow::localFlowStep(node1, node2)
|
||||||
or
|
or
|
||||||
exists(ConstructorCall c | c.getConstructedType() instanceof TypeFile |
|
exists(ConstructorCall c | c.getConstructedType() instanceof TypeFile |
|
||||||
node1.asExpr() = c.getArgument(1) and
|
node1.asExpr() = c.getArgument(0) and
|
||||||
node2.asExpr() = c
|
node2.asExpr() = c
|
||||||
)
|
)
|
||||||
|
or
|
||||||
|
node2.asExpr().(ArrayAccess).getArray() = node1.asExpr()
|
||||||
|
or
|
||||||
|
node2.asExpr().(FieldRead).getField().getInitializer() = node1.asExpr()
|
||||||
}
|
}
|
||||||
|
|
||||||
private predicate externalStorageFlow(DataFlow::Node node1, DataFlow::Node node2) {
|
private predicate externalStorageFlow(DataFlow::Node node1, DataFlow::Node node2) {
|
||||||
|
|||||||
@@ -13,39 +13,39 @@ class Test {
|
|||||||
InputStream is = new FileInputStream(f);
|
InputStream is = new FileInputStream(f);
|
||||||
byte[] data = new byte[is.available()];
|
byte[] data = new byte[is.available()];
|
||||||
is.read(data);
|
is.read(data);
|
||||||
sink(data); // $hasTaintFlow
|
sink(data); // $ hasTaintFlow
|
||||||
is.close();
|
is.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void test2(Context ctx) throws IOException {
|
void test2(Context ctx) throws IOException {
|
||||||
File f = new File(new File(new File(ctx.getExternalFilesDirs(null)[0], "things"), "stuff"), "file.txt");
|
File f = new File(new File(new File(ctx.getExternalFilesDirs(null)[0], "things"), "stuff"), "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
void test3(Context ctx) throws IOException {
|
void test3(Context ctx) throws IOException {
|
||||||
File f = new File(ctx.getExternalCacheDir(), "file.txt");
|
File f = new File(ctx.getExternalCacheDir(), "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
void test4(Context ctx) throws IOException {
|
void test4(Context ctx) throws IOException {
|
||||||
File f = new File(ctx.getExternalCacheDirs()[0], "file.txt");
|
File f = new File(ctx.getExternalCacheDirs()[0], "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
void test5(Context ctx) throws IOException {
|
void test5(Context ctx) throws IOException {
|
||||||
File f = new File(Environment.getExternalStorageDirectory(), "file.txt");
|
File f = new File(Environment.getExternalStorageDirectory(), "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
void test6(Context ctx) throws IOException {
|
void test6(Context ctx) throws IOException {
|
||||||
File f = new File(Environment.getExternalStoragePublicDirectory(null), "file.txt");
|
File f = new File(Environment.getExternalStoragePublicDirectory(null), "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
|
|
||||||
static final File dir = Environment.getExternalStorageDirectory();
|
static final File dir = Environment.getExternalStorageDirectory();
|
||||||
|
|
||||||
void test7(Context ctx) throws IOException {
|
void test7(Context ctx) throws IOException {
|
||||||
File f = new File(dir, "file.txt");
|
File f = new File(dir, "file.txt");
|
||||||
sink(new FileInputStream(f)); // $hasTaintFlow
|
sink(new FileInputStream(f)); // $ hasTaintFlow
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user