Merge "setProperty check for byte limit" am: 18b4802337

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2004952

Change-Id: Ia43944b29bc5da26590057e67aaa99b3bd4b7819
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ling Ma
2022-04-01 22:14:02 +00:00
committed by Automerger Merge Worker

View File

@@ -226,9 +226,10 @@ public class SystemProperties {
*/ */
@UnsupportedAppUsage @UnsupportedAppUsage
public static void set(@NonNull String key, @Nullable String val) { 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 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); if (TRACK_KEY_ACCESS) onKeyAccess(key);
native_set(key, val); native_set(key, val);