Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(230)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java

Issue 2392763002: Sanitize unparcable intents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java b/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
index 40952d5cb02d28a8a561b094b7ef413893a1ed13..747512875899808e9514402555b8449187d228f1 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/util/IntentUtils.java
@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.util;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
+import android.os.BadParcelableException;
import android.os.Binder;
import android.os.Bundle;
import android.os.IBinder;
@@ -337,4 +338,24 @@ public class IntentUtils {
public static boolean isIntentTooLarge(Intent intent) {
return getParceledIntentSize(intent) > MAX_INTENT_SIZE_THRESHOLD;
}
+
+ /**
+ * Adds a long extra to an intent (if possible)
+ * In case unmarshalling fails, this will return a safe to use Intent containing the same
+ * action and data.
+ */
+ public static Intent safePutExtra(final Intent incomingIntent, final String extraName,
+ final long extraValue) {
+ try {
+ incomingIntent.putExtra(extraName, extraValue);
+ return incomingIntent;
+ } catch (BadParcelableException e) {
+ Log.e(TAG, "Invalid incoming intent.");
+ // Those two methods do not trigger unmarshalling, as they do not access extras.
+ final Intent safeIntent = new Intent(incomingIntent.getAction(),
+ incomingIntent.getData());
+ safeIntent.putExtra(extraName, extraValue);
+ return safeIntent;
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698