summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorJeff Sharkey <jsharkey@google.com>2018-10-18 14:51:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-10-18 14:51:08 +0000
commit64d704f0fba3b8634a6b2316a606caee8af4cf36 (patch)
tree8f4c7ee525255a4779194ea6f75a3a45d03078ea /core/java/android
parentbde9aa118f7fc8a38897d80c10b4ffd57caff337 (diff)
parent0c91451bc86587663bb221d053f4d3e521ae99e5 (diff)
Merge "Catch more invalid file modes."
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/os/FileUtils.java13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java
index a9cb0d9579c9..f71fdd7fdac1 100644
--- a/core/java/android/os/FileUtils.java
+++ b/core/java/android/os/FileUtils.java
@@ -1198,6 +1198,19 @@ public class FileUtils {
/** {@hide} */
public static int translateModeStringToPosix(String mode) {
+ // Sanity check for invalid chars
+ for (int i = 0; i < mode.length(); i++) {
+ switch (mode.charAt(i)) {
+ case 'r':
+ case 'w':
+ case 't':
+ case 'a':
+ break;
+ default:
+ throw new IllegalArgumentException("Bad mode: " + mode);
+ }
+ }
+
int res = 0;
if (mode.startsWith("rw")) {
res |= O_RDWR | O_CREAT;