Bug 1277214 - Use SafeIntent in getEnvVarMap. r=grisha
authorMichael Comella <michael.l.comella@gmail.com>
Wed, 01 Jun 2016 15:34:34 -0700
changeset 339104 ed3c76c1685c4332ba58eeee2a8dc2e0cf70d380
parent 339103 265ac4f0ca980d2b09095e309da948d4d6a17040
child 339105 0262393b42771cc570b55e5b6f31ef437cc6ea4f
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgrisha
bugs1277214
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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
@@ -27,38 +27,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);
     }