From 7da36079c1cd4c37cc8104afd540e0ee02cd0c08 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Mon, 29 Mar 2021 04:16:18 -0700 Subject: [PATCH] Always delete existing ro props at setprop Close #4113 --- native/jni/resetprop/resetprop.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/native/jni/resetprop/resetprop.cpp b/native/jni/resetprop/resetprop.cpp index 9aebd5974..6ff53824a 100644 --- a/native/jni/resetprop/resetprop.cpp +++ b/native/jni/resetprop/resetprop.cpp @@ -172,10 +172,16 @@ struct resetprop : public sysprop { int ret; auto pi = const_cast(__system_property_find(name)); + + // Always delete existing read-only properties, because they could be + // long properties and cannot directly go through __system_property_update + if (pi != nullptr && str_starts(name, "ro.")) { + delprop(name, false); + pi = nullptr; + } + if (pi != nullptr) { if (prop_svc) { - if (strncmp(name, "ro.", 3) == 0) - delprop(name, false); ret = system_property_set(name, value); } else { ret = __system_property_update(pi, value, strlen(value)); @@ -216,13 +222,18 @@ struct resetprop : public sysprop { callback(key.data(), val.data(), cookie); } + // Not an error when something is deleted int delprop(const char *name, bool persist) override { if (!check_legal_property_name(name)) return 1; LOGD("resetprop: delete prop [%s]\n", name); - if (persist && strncmp(name, "persist.", 8) == 0) - persist = persist_deleteprop(name); - return __system_property_delete(name) && !(persist && strncmp(name, "persist.", 8) == 0); + + int ret = __system_property_delete(name); + if (persist && str_starts(name, "persist.")) { + if (persist_deleteprop(name)) + ret = 0; + } + return ret; } };