add checks for initialization for system properties
If a __system_property* function is called before
__system_properties_init() then the app will will abort. This commit
returns either an error code or a safe return value instead.
Bug 26027140
Change-Id: I95ffd143e9563658ab67a397991e84fb4c46ab77
diff --git a/libc/bionic/system_properties.cpp b/libc/bionic/system_properties.cpp
index 3fd41d7..9b44ff2 100644
--- a/libc/bionic/system_properties.cpp
+++ b/libc/bionic/system_properties.cpp
@@ -1006,6 +1006,10 @@
const prop_info *__system_property_find(const char *name)
{
+ if (!__system_property_area__) {
+ return nullptr;
+ }
+
if (__predict_false(compat_mode)) {
return __system_property_find_compat(name);
}
@@ -1091,11 +1095,15 @@
int __system_property_update(prop_info *pi, const char *value, unsigned int len)
{
- prop_area *pa = __system_property_area__;
-
if (len >= PROP_VALUE_MAX)
return -1;
+ prop_area* pa = __system_property_area__;
+
+ if (!pa) {
+ return -1;
+ }
+
uint32_t serial = atomic_load_explicit(&pi->serial, memory_order_relaxed);
serial |= 1;
atomic_store_explicit(&pi->serial, serial, memory_order_relaxed);
@@ -1129,6 +1137,10 @@
if (namelen < 1)
return -1;
+ if (!__system_property_area__) {
+ return -1;
+ }
+
prop_area* pa = get_prop_area_for_name(name);
if (!pa) {
@@ -1168,6 +1180,10 @@
prop_area *pa = __system_property_area__;
uint32_t my_serial;
+ if (!pa) {
+ return 0;
+ }
+
do {
__futex_wait(pa->serial(), serial, NULL);
my_serial = atomic_load_explicit(pa->serial(), memory_order_acquire);
@@ -1191,6 +1207,10 @@
int __system_property_foreach(void (*propfn)(const prop_info *pi, void *cookie),
void *cookie)
{
+ if (!__system_property_area__) {
+ return -1;
+ }
+
if (__predict_false(compat_mode)) {
return __system_property_foreach_compat(propfn, cookie);
}