Bug 1277214 - Use SafeIntent in getEnvVarMap. r=grisha
MozReview-Commit-ID: 5eXjgCsd6Rl
--- 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);
}