diff options
author | Nick Kralevich <nnk@google.com> | 2013-09-16 17:27:43 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-16 17:27:43 +0000 |
commit | 3a0d4b34816d65e21951f44e4d98a954c5c855ae (patch) | |
tree | 5ec95a9521cc43afbe4f4abce31f7c88cd5a6043 | |
parent | c0ce002ae53613f622c3bb2cae258a779e22770c (diff) | |
parent | 694636142113d91c2b9585ad28e143d4ff001584 (diff) | |
download | system_core-3a0d4b34816d65e21951f44e4d98a954c5c855ae.zip system_core-3a0d4b34816d65e21951f44e4d98a954c5c855ae.tar.gz system_core-3a0d4b34816d65e21951f44e4d98a954c5c855ae.tar.bz2 |
Merge "property_service: better validate property names" into klp-dev
-rw-r--r-- | init/property_service.c | 41 |
1 files changed, 37 insertions, 4 deletions
diff --git a/init/property_service.c b/init/property_service.c index 9afc756..9ac2781 100644 --- a/init/property_service.c +++ b/init/property_service.c @@ -276,6 +276,34 @@ static void write_persistent_property(const char *name, const char *value) } } +static bool is_legal_property_name(const char* name, size_t namelen) +{ + size_t i; + bool previous_was_dot = false; + 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 '_' */ + /* Don't allow ".." to appear in a property name */ + for (i = 0; i < namelen; i++) { + if (name[i] == '.') { + if (previous_was_dot == true) return false; + previous_was_dot = true; + continue; + } + previous_was_dot = false; + if (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; + return false; + } + + return true; +} + int property_set(const char *name, const char *value) { prop_info *pi; @@ -284,9 +312,8 @@ int property_set(const char *name, const char *value) size_t namelen = strlen(name); size_t valuelen = strlen(value); - if(namelen >= PROP_NAME_MAX) return -1; - if(valuelen >= PROP_VALUE_MAX) return -1; - if(namelen < 1) return -1; + if (!is_legal_property_name(name, namelen)) return -1; + if (valuelen >= PROP_VALUE_MAX) return -1; pi = (prop_info*) __system_property_find(name); @@ -298,7 +325,7 @@ int property_set(const char *name, const char *value) } else { ret = __system_property_add(name, namelen, value, valuelen); if (ret < 0) { - ERROR("Failed to set '%s'='%s'", name, value); + ERROR("Failed to set '%s'='%s'\n", name, value); return ret; } } @@ -364,6 +391,12 @@ 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))) { + ERROR("sys_prop: illegal property name. Got: \"%s\"\n", msg.name); + close(s); + return; + } + getpeercon(s, &source_ctx); if(memcmp(msg.name,"ctl.",4) == 0) { |