summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorChristopher Tate <ctate@google.com>2013-03-25 14:14:02 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-03-25 14:14:02 -0700
commitb559b58e950c8fe7ffe0c3201443ab814f24a701 (patch)
tree1a4c44ea7c4cd65ce6c9237f88c809d89737733b /core/java
parent728c4a7e4c19f134b82dbda2c8b1457a890e3765 (diff)
parent5769c0b803ec604efafbf983dbf38e223646fb74 (diff)
am 5769c0b8: am 9432f83c: am 7b3ac9ad: am 0cb27e28: Validate restored file paths against their nominal domain
* commit '5769c0b803ec604efafbf983dbf38e223646fb74': Validate restored file paths against their nominal domain
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/backup/BackupAgent.java28
1 files changed, 19 insertions, 9 deletions
diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java
index 9ad33a5a4105..0e835ed9f5b3 100644
--- a/core/java/android/app/backup/BackupAgent.java
+++ b/core/java/android/app/backup/BackupAgent.java
@@ -440,21 +440,31 @@ public abstract class BackupAgent extends ContextWrapper {
basePath = getCacheDir().getCanonicalPath();
} else {
// Not a supported location
- Log.i(TAG, "Data restored from non-app domain " + domain + ", ignoring");
+ Log.i(TAG, "Unrecognized domain " + domain);
}
// Now that we've figured out where the data goes, send it on its way
if (basePath != null) {
+ // Canonicalize the nominal path and verify that it lies within the stated domain
File outFile = new File(basePath, path);
- if (DEBUG) Log.i(TAG, "[" + domain + " : " + path + "] mapped to " + outFile.getPath());
- onRestoreFile(data, size, outFile, type, mode, mtime);
- } else {
- // Not a supported output location? We need to consume the data
- // anyway, so just use the default "copy the data out" implementation
- // with a null destination.
- if (DEBUG) Log.i(TAG, "[ skipping data from unsupported domain " + domain + "]");
- FullBackup.restoreFile(data, size, type, mode, mtime, null);
+ String outPath = outFile.getCanonicalPath();
+ if (outPath.startsWith(basePath + File.separatorChar)) {
+ if (DEBUG) Log.i(TAG, "[" + domain + " : " + path + "] mapped to " + outPath);
+ onRestoreFile(data, size, outFile, type, mode, mtime);
+ return;
+ } else {
+ // Attempt to restore to a path outside the file's nominal domain.
+ if (DEBUG) {
+ Log.e(TAG, "Cross-domain restore attempt: " + outPath);
+ }
+ }
}
+
+ // Not a supported output location, or bad path: we need to consume the data
+ // anyway, so just use the default "copy the data out" implementation
+ // with a null destination.
+ if (DEBUG) Log.i(TAG, "[ skipping file " + path + "]");
+ FullBackup.restoreFile(data, size, type, mode, mtime, null);
}
// ----- Core implementation -----