From 2315827635f39cc876dec9ffb238227b8595e404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Thu, 19 Nov 2015 18:35:19 +0100 Subject: FileHelperLollipop: Check by comparing UID instead of checking files read permissions. This fixes sharing of file uris from sdcard --- .../keychain/util/FileHelperLollipop.java | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelperLollipop.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelperLollipop.java index ab2841ed5..131f9296e 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelperLollipop.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/FileHelperLollipop.java @@ -17,7 +17,6 @@ package org.sufficientlysecure.keychain.util; - import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; @@ -27,7 +26,6 @@ import android.annotation.TargetApi; import android.content.ContentResolver; import android.content.res.AssetFileDescriptor; import android.net.Uri; -import android.os.Build; import android.os.Build.VERSION_CODES; import android.os.ParcelFileDescriptor; import android.system.ErrnoException; @@ -36,10 +34,8 @@ import android.system.StructStat; import org.sufficientlysecure.keychain.Constants; -import static android.system.OsConstants.S_IROTH; - - -/** FileHelper methods which use Lollipop-exclusive API. +/** + * FileHelper methods which use Lollipop-exclusive API. * Some of the methods and static fields used here cause VerifyErrors because * they do not exist in pre-lollipop API, so they must be kept in a * lollipop-only class. All methods here should only be called by FileHelper, @@ -47,12 +43,6 @@ import static android.system.OsConstants.S_IROTH; */ @TargetApi(VERSION_CODES.LOLLIPOP) class FileHelperLollipop { - /** - * Tests whether a file is readable by others - */ - private static boolean S_IROTH(int mode) { - return (mode & S_IROTH) == S_IROTH; - } /** * A replacement for ContentResolver.openInputStream() that does not allow the usage of @@ -76,8 +66,8 @@ class FileHelperLollipop { try { final StructStat st = Os.fstat(pfd.getFileDescriptor()); - if (!S_IROTH(st.st_mode)) { - Log.e(Constants.TAG, "File is not readable by others, aborting!"); + if (st.st_uid == android.os.Process.myUid()) { + Log.e(Constants.TAG, "File is owned by the application itself, aborting!"); throw new FileNotFoundException("Unable to create stream"); } } catch (ErrnoException e) { -- cgit v1.2.3