1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#define FOR_setprop
18#include "toys.h"
19
20void setprop_main(void)
21{
22 char *name = toys.optargs[0], *value = toys.optargs[1];
23 char *p;
24 size_t name_len = strlen(name), value_len = strlen(value);
25
26
27
28
29
30 if (value_len >= PROP_VALUE_MAX && !strncmp(value, "ro.", 3))
31 error_exit("value '%s' too long; try '%.*s'",
32 value, PROP_VALUE_MAX - 1, value);
33
34 if (*name == '.' || name[name_len - 1] == '.')
35 error_exit("property names must not start or end with '.'");
36 if (strstr(name, ".."))
37 error_exit("'..' is not allowed in a property name");
38 for (p = name; *p; ++p)
39 if (!isalnum(*p) && !strchr(":@_.-", *p))
40 error_exit("invalid character '%c' in name '%s'", *p, name);
41
42 if (__system_property_set(name, value))
43 error_msg("failed to set property '%s' to '%s'", name, value);
44}
45