Skip to content

Commit 8c8321e

Browse files
Rohan Shahandi34
authored andcommitted
DO NOT MERGE Limit account id and id to longs
The security issue occurs because id is allowed to be an arbitrary path instead of being limited to what it is -- a long. Both id and account id are now parsed into longs (and if either fails, an error will be logged and null will be returned). Tested/verified error is logged using the reported attack. BUG=30745403 Change-Id: Ibe87479fd798da7da0e8809e37a39a4dfc708658 (cherry picked from commit 4d43d4a)
1 parent 8537547 commit 8c8321e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/com/android/email/provider/AttachmentProvider.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundEx
166166
long callingId = Binder.clearCallingIdentity();
167167
try {
168168
List<String> segments = uri.getPathSegments();
169-
String accountId = segments.get(0);
170-
String id = segments.get(1);
169+
final long accountId = Long.parseLong(segments.get(0));
170+
final long id = Long.parseLong(segments.get(1));
171171
String format = segments.get(2);
172172
if (AttachmentUtilities.FORMAT_THUMBNAIL.equals(format)) {
173173
int width = Integer.parseInt(segments.get(3));
@@ -176,8 +176,7 @@ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundEx
176176
File dir = getContext().getCacheDir();
177177
File file = new File(dir, filename);
178178
if (!file.exists()) {
179-
Uri attachmentUri = AttachmentUtilities.
180-
getAttachmentUri(Long.parseLong(accountId), Long.parseLong(id));
179+
Uri attachmentUri = AttachmentUtilities.getAttachmentUri(accountId, id);
181180
Cursor c = query(attachmentUri,
182181
new String[] { Columns.DATA }, null, null, null);
183182
if (c != null) {
@@ -218,9 +217,14 @@ public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundEx
218217
}
219218
else {
220219
return ParcelFileDescriptor.open(
221-
new File(getContext().getDatabasePath(accountId + ".db_att"), id),
220+
new File(getContext().getDatabasePath(accountId + ".db_att"),
221+
String.valueOf(id)),
222222
ParcelFileDescriptor.MODE_READ_ONLY);
223223
}
224+
} catch (NumberFormatException e) {
225+
LogUtils.e(Logging.LOG_TAG,
226+
"AttachmentProvider.openFile: Failed to open as id is not a long");
227+
return null;
224228
} finally {
225229
Binder.restoreCallingIdentity(callingId);
226230
}

0 commit comments

Comments
 (0)