aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorPo Lu2024-07-11 11:38:41 +0800
committerPo Lu2024-07-11 11:38:41 +0800
commite0b271e279ba5b606330908604ac4fa42a389b30 (patch)
tree80f3d93a8ee285906b3d8f8c3749844ba57ebecb /java
parent9331ab056a426b334d46c38659c9de2053eb45f3 (diff)
downloademacs-e0b271e279ba5b606330908604ac4fa42a389b30.tar.gz
emacs-e0b271e279ba5b606330908604ac4fa42a389b30.zip
Take precautions against ill-formed content URIs
* java/org/gnu/emacs/EmacsService.java (openContentUri) (checkContentUri): Verify that URIs derived from user-provided file names can be parsed before attempting to open them.
Diffstat (limited to 'java')
-rw-r--r--java/org/gnu/emacs/EmacsService.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/java/org/gnu/emacs/EmacsService.java b/java/org/gnu/emacs/EmacsService.java
index 77124a7d80f..7afe4c7f82e 100644
--- a/java/org/gnu/emacs/EmacsService.java
+++ b/java/org/gnu/emacs/EmacsService.java
@@ -987,6 +987,7 @@ public final class EmacsService extends Service
987 String name, mode; 987 String name, mode;
988 ParcelFileDescriptor fd; 988 ParcelFileDescriptor fd;
989 int i; 989 int i;
990 Uri uriObject;
990 991
991 /* Figure out the file access mode. */ 992 /* Figure out the file access mode. */
992 993
@@ -1001,12 +1002,20 @@ public final class EmacsService extends Service
1001 if (truncate) 1002 if (truncate)
1002 mode += "t"; 1003 mode += "t";
1003 1004
1005 /* Decode the URI. It might be possible for a perverse user to
1006 construct a content file name that Android finds unparsable, so
1007 punt if the result is NULL. */
1008
1009 uriObject = Uri.parse (uri);
1010 if (uriObject == null)
1011 return -1;
1012
1004 /* Try to open a corresponding ParcelFileDescriptor. Though 1013 /* Try to open a corresponding ParcelFileDescriptor. Though
1005 `fd.detachFd' is exclusive to Honeycomb and up, this function is 1014 `fd.detachFd' is exclusive to Honeycomb and up, this function is
1006 never called on systems older than KitKat, which is Emacs's 1015 never called on systems older than KitKat, which is Emacs's
1007 minimum requirement for access to /content/by-authority. */ 1016 minimum requirement for access to /content/by-authority. */
1008 1017
1009 fd = resolver.openFileDescriptor (Uri.parse (uri), mode); 1018 fd = resolver.openFileDescriptor (uriObject, mode);
1010 if (fd == null) 1019 if (fd == null)
1011 return -1; 1020 return -1;
1012 1021
@@ -1027,7 +1036,14 @@ public final class EmacsService extends Service
1027 Uri uri; 1036 Uri uri;
1028 int rc, flags; 1037 int rc, flags;
1029 1038
1039 /* Decode the URI. It might be possible that perverse user should
1040 construct a content file name that Android finds unparsable, so
1041 punt if the result is NULL. */
1042
1030 uri = Uri.parse (name); 1043 uri = Uri.parse (name);
1044 if (uri == null)
1045 return false;
1046
1031 flags = 0; 1047 flags = 0;
1032 1048
1033 if (readable) 1049 if (readable)