From f41994cb52ca08856216a8da0a28ed148c833f4e Mon Sep 17 00:00:00 2001 From: LoveSy Date: Sun, 17 Dec 2023 03:12:08 +0800 Subject: [PATCH] Skip svc for ro properties ro properties' triggers should only be triggered once, otherwise it may undefined behaviour. This patch avoids triggering ro properties' actions again when using resetprop to modify them. Co-authored-by: 5ec1cff --- native/src/core/module.cpp | 4 ++-- native/src/core/resetprop/resetprop.cpp | 20 ++++++++++++-------- native/src/core/zygisk/entry.cpp | 4 ++-- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/native/src/core/module.cpp b/native/src/core/module.cpp index 1cf16c537..cd77c6557 100644 --- a/native/src/core/module.cpp +++ b/native/src/core/module.cpp @@ -313,12 +313,12 @@ void load_modules() { native_bridge_orig = "0"; } native_bridge = native_bridge_orig != "0" ? ZYGISKLDR + native_bridge_orig : ZYGISKLDR; - set_prop(NBPROP, native_bridge.data(), true); + set_prop(NBPROP, native_bridge.data()); // Weather Huawei's Maple compiler is enabled. // If so, system server will be created by a special Zygote which ignores the native bridge // and make system server out of our control. Avoid it by disabling. if (get_prop("ro.maple.enable") == "1") { - set_prop("ro.maple.enable", "0", true); + set_prop("ro.maple.enable", "0"); } inject_zygisk_libs(system); } diff --git a/native/src/core/resetprop/resetprop.cpp b/native/src/core/resetprop/resetprop.cpp index a9eca71f7..786428056 100644 --- a/native/src/core/resetprop/resetprop.cpp +++ b/native/src/core/resetprop/resetprop.cpp @@ -9,6 +9,7 @@ #define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_ #include +#include using namespace std; @@ -134,18 +135,21 @@ static int set_prop(const char *name, const char *value, PropFlags flags) { if (!check_legal_property_name(name)) return 1; - const char *msg = flags.isSkipSvc() ? "direct modification" : "property_service"; - 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.")) { - // Skip pruning nodes as we will add it back ASAP - __system_property_delete(name, false); - pi = nullptr; + // Delete existing read-only properties if they are or will be long properties, + // which cannot directly go through __system_property_update + if (str_starts(name, "ro.")) { + if (pi != nullptr && (pi->is_long() || strlen(value) >= PROP_VALUE_MAX)) { + // Skip pruning nodes as we will add it back ASAP + __system_property_delete(name, false); + pi = nullptr; + } + flags.setSkipSvc(); } + const char *msg = flags.isSkipSvc() ? "direct modification" : "property_service"; + int ret; if (pi != nullptr) { if (flags.isSkipSvc()) { diff --git a/native/src/core/zygisk/entry.cpp b/native/src/core/zygisk/entry.cpp index b4dbead4a..b33b09694 100644 --- a/native/src/core/zygisk/entry.cpp +++ b/native/src/core/zygisk/entry.cpp @@ -245,8 +245,8 @@ void reset_zygisk(bool restore) { if (native_bridge.length() > strlen(ZYGISKLDR)) { native_bridge_orig = native_bridge.substr(strlen(ZYGISKLDR)); } - set_prop(NBPROP, native_bridge_orig.data(), true); + set_prop(NBPROP, native_bridge_orig.data()); } else { - set_prop(NBPROP, native_bridge.data(), true); + set_prop(NBPROP, native_bridge.data()); } }