diff options
| author | Andreas Gampe <agampe@google.com> | 2017-03-03 09:38:58 -0800 |
|---|---|---|
| committer | Andreas Gampe <agampe@google.com> | 2017-03-03 09:38:58 -0800 |
| commit | 7f8466fab49f684ec3f430d15ae765d3886052c5 (patch) | |
| tree | 28e40cbcf6b35459054cc8c77911b43545115467 /core/java/android/util/Patterns.java | |
| parent | 3e6c189c68bcac61216b8c2f0a0fc05d6ab15a53 (diff) | |
Framework: Ensure image heap string literals for Patterns
Do not use Pattern.toString to construct complex patterns. Instead,
make the string literals explicit so they can be compile-time
allocated, thus ending up as clean memory in the image heap.
Bug: 34956610
Test: m
Test: Device boots
Change-Id: I20d45c31243af00168553c218f75fb0795b55149
Diffstat (limited to 'core/java/android/util/Patterns.java')
| -rw-r--r-- | core/java/android/util/Patterns.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/core/java/android/util/Patterns.java b/core/java/android/util/Patterns.java index 0a452dbc39a1..86434b26058b 100644 --- a/core/java/android/util/Patterns.java +++ b/core/java/android/util/Patterns.java @@ -243,12 +243,12 @@ public class Patterns { public static final String GOOD_IRI_CHAR = "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF"; - public static final Pattern IP_ADDRESS - = Pattern.compile( + private static final String IP_ADDRESS_STRING = "((25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(25[0-5]|2[0-4]" + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]" + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}" - + "|[1-9][0-9]|[0-9]))"); + + "|[1-9][0-9]|[0-9]))"; + public static final Pattern IP_ADDRESS = Pattern.compile(IP_ADDRESS_STRING); /** * Valid UCS characters defined in RFC 3987. Excludes space characters. @@ -298,8 +298,8 @@ public class Patterns { private static final String HOST_NAME = "(" + IRI_LABEL + "\\.)+" + TLD; - public static final Pattern DOMAIN_NAME - = Pattern.compile("(" + HOST_NAME + "|" + IP_ADDRESS + ")"); + private static final String DOMAIN_NAME_STR = "(" + HOST_NAME + "|" + IP_ADDRESS_STRING + ")"; + public static final Pattern DOMAIN_NAME = Pattern.compile(DOMAIN_NAME_STR); private static final String PROTOCOL = "(?i:http|https|rtsp):\\/\\/"; @@ -323,7 +323,7 @@ public class Patterns { public static final Pattern WEB_URL = Pattern.compile("(" + "(" + "(?:" + PROTOCOL + "(?:" + USER_INFO + ")?" + ")?" - + "(?:" + DOMAIN_NAME + ")" + + "(?:" + DOMAIN_NAME_STR + ")" + "(?:" + PORT_NUMBER + ")?" + ")" + "(" + PATH_AND_QUERY + ")?" @@ -346,14 +346,14 @@ public class Patterns { * Regular expression that matches domain names using either {@link #STRICT_HOST_NAME} or * {@link #IP_ADDRESS} */ - private static final Pattern STRICT_DOMAIN_NAME - = Pattern.compile("(?:" + STRICT_HOST_NAME + "|" + IP_ADDRESS + ")"); + private static final String STRICT_DOMAIN_NAME = "(?:" + STRICT_HOST_NAME + "|" + + IP_ADDRESS_STRING + ")"; /** * Regular expression that matches domain names without a TLD */ private static final String RELAXED_DOMAIN_NAME = - "(?:" + "(?:" + IRI_LABEL + "(?:\\.(?=\\S))" +"?)+" + "|" + IP_ADDRESS + ")"; + "(?:" + "(?:" + IRI_LABEL + "(?:\\.(?=\\S))" +"?)+" + "|" + IP_ADDRESS_STRING + ")"; /** * Regular expression to match strings that do not start with a supported protocol. The TLDs |
