setProperty check for byte limit

Test: manual
Bug: 210502588
Change-Id: I75a1e5bbd79814429dfac5b0b6449efd72176c2c
This commit is contained in:
Ling Ma
2022-03-02 14:09:12 -08:00
parent d9e8a4f5ff
commit 8c959cde94

View File

@@ -226,9 +226,10 @@ public class SystemProperties {
*/
@UnsupportedAppUsage
public static void set(@NonNull String key, @Nullable String val) {
if (val != null && !key.startsWith("ro.") && val.length() > PROP_VALUE_MAX) {
if (val != null && !key.startsWith("ro.") && val.getBytes(StandardCharsets.UTF_8).length
> PROP_VALUE_MAX) {
throw new IllegalArgumentException("value of system property '" + key
+ "' is longer than " + PROP_VALUE_MAX + " characters: " + val);
+ "' is longer than " + PROP_VALUE_MAX + " bytes: " + val);
}
if (TRACK_KEY_ACCESS) onKeyAccess(key);
native_set(key, val);