Bug 1277214 - Use SafeIntent in getEnvVarMap. r=grisha draft
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 01 Jun 2016 15:34:34 -0700
changeset 374144 362a73a76f94e1f7403b1c08f804a97f41fbdd26
parent 374143 c03e0c52b9b5a16d651547fb7176dd79c0ed0ecf
child 374145 e2a035f75078b7a66ec7417a0998746b2ef150de
push id19946
push usermichael.l.comella@gmail.com
push dateWed, 01 Jun 2016 23:55:51 +0000
reviewersgrisha
bugs1277214
milestone49.0a1
Bug 1277214 - Use SafeIntent in getEnvVarMap. r=grisha MozReview-Commit-ID: 5eXjgCsd6Rl
mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
--- a/mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
+++ b/mobile/android/base/java/org/mozilla/gecko/util/IntentUtils.java
@@ -26,38 +26,40 @@ public class IntentUtils {
      * Returns a list of environment variables and their values. These are parsed from an Intent extra
      * with the key -> value format:
      *   env# -> ENV_VAR=VALUE
      *
      * # in env# is expected to be increasing from 0.
      *
      * @return A Map of environment variable name to value, e.g. ENV_VAR -> VALUE
      */
-    public static HashMap<String, String> getEnvVarMap(@NonNull final Intent intent) {
+    public static HashMap<String, String> getEnvVarMap(@NonNull final Intent unsafeIntent) {
+        // This is expected to be an external intent so we should use SafeIntent to prevent crashing.
+        final SafeIntent safeIntent = new SafeIntent(unsafeIntent);
         final HashMap<String, String> out = new HashMap<>();
         final Pattern envVarPattern = Pattern.compile(ENV_VAR_REGEX);
         Matcher matcher = null;
 
-        String envValue = intent.getStringExtra("env0");
+        String envValue = safeIntent.getStringExtra("env0");
         int i = 1;
         while (envValue != null) {
             // Optimization to re-use matcher rather than creating new
             // objects because this is used in the startup path.
             if (matcher == null) {
                 matcher = envVarPattern.matcher(envValue);
             } else {
                 matcher.reset(envValue);
             }
 
             if (matcher.matches()) {
                 final String envVarName = matcher.group(1);
                 final String envVarValue = matcher.group(2);
                 out.put(envVarName, envVarValue);
             }
-            envValue = intent.getStringExtra("env" + i);
+            envValue = safeIntent.getStringExtra("env" + i);
             i += 1;
         }
         return out;
     }
 
     public static Bundle getBundleExtraSafe(final Intent intent, final String name) {
         return new SafeIntent(intent).getBundleExtra(name);
     }