aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Cherry <tomcherry@google.com>2017-10-12 09:43:32 -0700
committerRob Landley <rob@landley.net>2017-10-17 12:27:05 -0500
commit11c385314ac0fac9694509639b03aa88a2ee5f6c (patch)
tree0e5bd7af90e2224daf2eaa42c2a0ad9b7b2d3389
parent46d2cda500242caae2ccf7cee71200d4bfe7c7a5 (diff)
downloadtoybox-11c385314ac0fac9694509639b03aa88a2ee5f6c.tar.gz
Allow ro. properties to have arbitrary lengths
Android now allows ro. properties to have arbitrary lengths. Two changes need to happen to support this: 1) The length check in setprop.c before attempting to set a property needs to be removed for ro. properties 2) __system_property_read_callback() must be used in place of __system_property_get() in getprop.c as only the former is capable of reading properties with size > 92 characters. Bug: 23102347 Bug: 34954705 Change-Id: Ib8565a3e6d987dd5e6a5fe790e804ecf8ad1e020
-rw-r--r--toys/android/getprop.c15
-rw-r--r--toys/android/setprop.c2
2 files changed, 13 insertions, 4 deletions
diff --git a/toys/android/getprop.c b/toys/android/getprop.c
index 04a9b282..51ef7f6b 100644
--- a/toys/android/getprop.c
+++ b/toys/android/getprop.c
@@ -57,6 +57,12 @@ static void add_property(const prop_info *pi, void *unused)
__system_property_read_callback(pi, read_callback, NULL);
}
+static void print_callback(void *unused, const char *unused_name, const char *value,
+ unsigned unused_serial)
+{
+ puts(value);
+}
+
// Needed to supress extraneous "Loaded property_contexts from" message
static int selinux_log_callback_local(int type, const char *fmt, ...)
{
@@ -87,9 +93,12 @@ void getprop_main(void)
puts(context);
if (CFG_TOYBOX_FREE) free(context);
} else {
- if (__system_property_get(*toys.optargs, toybuf) <= 0)
- strcpy(toybuf, toys.optargs[1] ? toys.optargs[1] : "");
- puts(toybuf);
+ const prop_info* pi = __system_property_find(*toys.optargs);
+ if (pi == NULL) {
+ puts(toys.optargs[1] ? toys.optargs[1] : "");
+ } else {
+ __system_property_read_callback(pi, print_callback, NULL);
+ }
}
} else {
size_t i;
diff --git a/toys/android/setprop.c b/toys/android/setprop.c
index ec411f41..14c24d9f 100644
--- a/toys/android/setprop.c
+++ b/toys/android/setprop.c
@@ -29,7 +29,7 @@ void setprop_main(void)
// recognize most failures (because it doesn't wait for init), so
// we duplicate all of init's checks here to help the user.
- if (value_len >= PROP_VALUE_MAX)
+ if (value_len >= PROP_VALUE_MAX && !strncmp(value, "ro.", 3))
error_exit("value '%s' too long; try '%.*s'",
value, PROP_VALUE_MAX - 1, value);