1
0
mirror of https://github.com/topjohnwu/Magisk.git synced 2025-04-02 02:02:25 +00:00

Update preference migration implementation

Only try to read preference through content provider when the app
is fresh install and a previous package ID is set. Also catch all
Exceptions to prevent crashing the app.

This prevents malicious settings injection and crashes when multiple
manager is installed.

Fix 
This commit is contained in:
topjohnwu 2020-12-09 02:07:58 -08:00
parent 039d4936cb
commit 1232113772
5 changed files with 11 additions and 10 deletions
app/src/main

@ -12,7 +12,7 @@
<application <application
android:icon="@drawable/ic_launcher" android:icon="@drawable/ic_launcher"
android:name="a.e" android:name="a.e"
android:allowBackup="true" android:allowBackup="false"
tools:ignore="UnusedAttribute,GoogleAppIndexingWarning"> tools:ignore="UnusedAttribute,GoogleAppIndexingWarning">
<!-- Splash --> <!-- Splash -->

@ -18,7 +18,6 @@ import com.topjohnwu.magisk.ktx.inject
import com.topjohnwu.magisk.ui.theme.Theme import com.topjohnwu.magisk.ui.theme.Theme
import org.xmlpull.v1.XmlPullParser import org.xmlpull.v1.XmlPullParser
import java.io.File import java.io.File
import java.io.IOException
import java.io.InputStream import java.io.InputStream
object Config : PreferenceModel, DBConfig { object Config : PreferenceModel, DBConfig {
@ -159,12 +158,13 @@ object Config : PreferenceModel, DBConfig {
private const val SU_FINGERPRINT = "su_fingerprint" private const val SU_FINGERPRINT = "su_fingerprint"
fun load(pkg: String) { fun load(pkg: String?) {
try { // Only try to load prefs when fresh install and a previous package name is set
if (pkg != null && prefs.all.isEmpty()) runCatching {
context.contentResolver.openInputStream(Provider.PREFS_URI(pkg))?.use { context.contentResolver.openInputStream(Provider.PREFS_URI(pkg))?.use {
prefs.edit { parsePrefs(it) } prefs.edit { parsePrefs(it) }
} }
} catch (e: IOException) {} }
prefs.edit { prefs.edit {
// Settings migration // Settings migration

@ -58,7 +58,7 @@ object Const {
object Key { object Key {
// intents // intents
const val OPEN_SECTION = "section" const val OPEN_SECTION = "section"
const val HIDDEN_PKG = "hidden_pkg" const val PREV_PKG = "prev_pkg"
} }
object Value { object Value {

@ -48,10 +48,10 @@ open class SplashActivity : Activity() {
// Pre-initialize root shell // Pre-initialize root shell
Shell.getShell() Shell.getShell()
val hiddenPackage = intent.getStringExtra(Const.Key.HIDDEN_PKG) val prevPkg = intent.getStringExtra(Const.Key.PREV_PKG)
Config.load(hiddenPackage ?: APPLICATION_ID) Config.load(prevPkg)
handleRepackage(hiddenPackage) handleRepackage(prevPkg)
Notifications.setup(this) Notifications.setup(this)
UpdateCheckService.schedule(this) UpdateCheckService.schedule(this)
Shortcuts.setupDynamic(this) Shortcuts.setupDynamic(this)

@ -123,6 +123,7 @@ object HideAPK {
Config.suManager = pkg Config.suManager = pkg
grantUriPermission(pkg, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission(pkg, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
grantUriPermission(pkg, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission(pkg, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.putExtra(Const.Key.PREV_PKG, packageName)
startActivity(intent) startActivity(intent)
} }
@ -167,7 +168,7 @@ object HideAPK {
Config.suManager = "" Config.suManager = ""
grantUriPermission(APPLICATION_ID, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission(APPLICATION_ID, APK_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
grantUriPermission(APPLICATION_ID, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION) grantUriPermission(APPLICATION_ID, PREFS_URI, Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.putExtra(Const.Key.HIDDEN_PKG, packageName) intent.putExtra(Const.Key.PREV_PKG, packageName)
startActivity(intent) startActivity(intent)
} }