summaryrefslogtreecommitdiffstats
path: root/dalvik
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2012-11-05 11:02:49 -0800
committerElliott Hughes <enh@google.com>2012-11-05 11:17:46 -0800
commit6d17baa25d349e2659eb16fe5eef3088d48e5e22 (patch)
tree419da759e11d35957f551966a9bdde433f788fe3 /dalvik
parentfbc035d73583ae9d5c54214989756ceec743b8d9 (diff)
downloadlibcore-6d17baa25d349e2659eb16fe5eef3088d48e5e22.zip
libcore-6d17baa25d349e2659eb16fe5eef3088d48e5e22.tar.gz
libcore-6d17baa25d349e2659eb16fe5eef3088d48e5e22.tar.bz2
Make System.loadLibrary use open(2) rather than stat(2).
This will let us remove read permission from directories containing .so files. Bug: 6485312 Change-Id: I72daa265ce54747fc91cdb9d915a05a2464041bb
Diffstat (limited to 'dalvik')
-rw-r--r--dalvik/src/main/java/dalvik/system/DexPathList.java47
1 files changed, 17 insertions, 30 deletions
diff --git a/dalvik/src/main/java/dalvik/system/DexPathList.java b/dalvik/src/main/java/dalvik/system/DexPathList.java
index 1253223..048cc83 100644
--- a/dalvik/src/main/java/dalvik/system/DexPathList.java
+++ b/dalvik/src/main/java/dalvik/system/DexPathList.java
@@ -25,6 +25,11 @@ import java.util.Collections;
import java.util.Enumeration;
import java.util.regex.Pattern;
import java.util.zip.ZipFile;
+import libcore.io.ErrnoException;
+import libcore.io.IoUtils;
+import libcore.io.Libcore;
+import libcore.io.StructStat;
+import static libcore.io.OsConstants.*;
/**
* A pair of lists of entries, associated with a {@code ClassLoader}.
@@ -154,36 +159,20 @@ import java.util.zip.ZipFile;
* Helper for {@link #splitPaths}, which does the actual splitting
* and filtering and adding to a result.
*/
- private static void splitAndAdd(String path, boolean wantDirectories,
+ private static void splitAndAdd(String searchPath, boolean wantDirectories,
ArrayList<File> resultList) {
- if (path == null) {
+ if (searchPath == null) {
return;
}
-
- String[] strings = path.split(Pattern.quote(File.pathSeparator));
-
- for (String s : strings) {
- File file = new File(s);
-
- if (! (file.exists() && file.canRead())) {
- continue;
- }
-
- /*
- * Note: There are other entities in filesystems than
- * regular files and directories.
- */
- if (wantDirectories) {
- if (!file.isDirectory()) {
- continue;
- }
- } else {
- if (!file.isFile()) {
- continue;
+ for (String path : searchPath.split(":")) {
+ try {
+ StructStat sb = Libcore.os.stat(path);
+ if ((wantDirectories && S_ISDIR(sb.st_mode)) ||
+ (!wantDirectories && S_ISREG(sb.st_mode))) {
+ resultList.add(new File(path));
}
+ } catch (ErrnoException ignored) {
}
-
- resultList.add(file);
}
}
@@ -370,14 +359,12 @@ import java.util.zip.ZipFile;
*/
public String findLibrary(String libraryName) {
String fileName = System.mapLibraryName(libraryName);
-
for (File directory : nativeLibraryDirectories) {
- File file = new File(directory, fileName);
- if (file.exists() && file.isFile() && file.canRead()) {
- return file.getPath();
+ String path = new File(directory, fileName).getPath();
+ if (IoUtils.canOpenReadOnly(path)) {
+ return path;
}
}
-
return null;
}