init: allow '.' and '@' in service names
Services implementing HIDL HALs must be named the same as the HIDL package, e.g. android.hardware.nfc@1.0. Allow init to accept names containing '.' and '@'. Also combined logic for legal property names and legal service names. Bug: 31458381 Bug: 32109611 Test: Tested creating service nfc@1.0-service which creates property 'init.svc.nfc@1.0-service' with and without this change. This service successfully started only with this change. Change-Id: Ie7a4310742bc03498d774d37b3b5fafa7c6068cc Signed-off-by: Iliyan Malchev <malchev@google.com>
This commit is contained in:
parent
fbe0b45544
commit
f655480b48
3 changed files with 11 additions and 18 deletions
|
@ -141,23 +141,24 @@ static void write_persistent_property(const char *name, const char *value)
|
|||
}
|
||||
}
|
||||
|
||||
static bool is_legal_property_name(const char* name, size_t namelen)
|
||||
bool is_legal_property_name(const std::string &name)
|
||||
{
|
||||
size_t i;
|
||||
size_t namelen = name.size();
|
||||
|
||||
if (namelen >= PROP_NAME_MAX) return false;
|
||||
if (namelen < 1) return false;
|
||||
if (name[0] == '.') return false;
|
||||
if (name[namelen - 1] == '.') return false;
|
||||
|
||||
/* Only allow alphanumeric, plus '.', '-', or '_' */
|
||||
/* Only allow alphanumeric, plus '.', '-', '@', or '_' */
|
||||
/* Don't allow ".." to appear in a property name */
|
||||
for (i = 0; i < namelen; i++) {
|
||||
for (size_t i = 0; i < namelen; i++) {
|
||||
if (name[i] == '.') {
|
||||
// i=0 is guaranteed to never have a dot. See above.
|
||||
if (name[i-1] == '.') return false;
|
||||
continue;
|
||||
}
|
||||
if (name[i] == '_' || name[i] == '-') continue;
|
||||
if (name[i] == '_' || name[i] == '-' || name[i] == '@') continue;
|
||||
if (name[i] >= 'a' && name[i] <= 'z') continue;
|
||||
if (name[i] >= 'A' && name[i] <= 'Z') continue;
|
||||
if (name[i] >= '0' && name[i] <= '9') continue;
|
||||
|
@ -168,10 +169,9 @@ static bool is_legal_property_name(const char* name, size_t namelen)
|
|||
}
|
||||
|
||||
static int property_set_impl(const char* name, const char* value) {
|
||||
size_t namelen = strlen(name);
|
||||
size_t valuelen = strlen(value);
|
||||
|
||||
if (!is_legal_property_name(name, namelen)) return -1;
|
||||
if (!is_legal_property_name(name)) return -1;
|
||||
if (valuelen >= PROP_VALUE_MAX) return -1;
|
||||
|
||||
if (strcmp("selinux.restorecon_recursive", name) == 0 && valuelen > 0) {
|
||||
|
@ -188,7 +188,7 @@ static int property_set_impl(const char* name, const char* value) {
|
|||
|
||||
__system_property_update(pi, value, valuelen);
|
||||
} else {
|
||||
int rc = __system_property_add(name, namelen, value, valuelen);
|
||||
int rc = __system_property_add(name, strlen(name), value, valuelen);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ static void handle_property_set_fd()
|
|||
msg.name[PROP_NAME_MAX-1] = 0;
|
||||
msg.value[PROP_VALUE_MAX-1] = 0;
|
||||
|
||||
if (!is_legal_property_name(msg.name, strlen(msg.name))) {
|
||||
if (!is_legal_property_name(msg.name)) {
|
||||
LOG(ERROR) << "sys_prop: illegal property name \"" << msg.name << "\"";
|
||||
close(s);
|
||||
return;
|
||||
|
|
|
@ -34,6 +34,7 @@ extern void load_system_props(void);
|
|||
extern void start_property_service(void);
|
||||
std::string property_get(const char* name);
|
||||
extern int property_set(const char *name, const char *value);
|
||||
extern bool is_legal_property_name(const std::string &name);
|
||||
|
||||
|
||||
#endif /* _INIT_PROPERTY_H */
|
||||
|
|
|
@ -996,13 +996,5 @@ void ServiceParser::EndSection() {
|
|||
}
|
||||
|
||||
bool ServiceParser::IsValidName(const std::string& name) const {
|
||||
if (name.size() > PROP_NAME_MAX - sizeof("init.svc.")) {
|
||||
return false;
|
||||
}
|
||||
for (const auto& c : name) {
|
||||
if (!isalnum(c) && (c != '_') && (c != '-')) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return is_legal_property_name("init.svc." + name);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue