diff options
author | Nikita Ioffe <ioffe@google.com> | 2019-10-10 20:42:37 +0100 |
---|---|---|
committer | Nikita Ioffe <ioffe@google.com> | 2019-10-11 17:44:54 +0100 |
commit | aaab596687acc7e6419028525a7ecf4eb4e54597 (patch) | |
tree | 548ff08038a701fa47b8d51856f9e261bb1f531a /init/action_parser.cpp | |
parent | 6b0e789a21cfb796a508e3c5507e49a2e8571582 (diff) |
Only allow alphanumerical characters, '-' and '_' in event trigger names
This should help in preventing silly typos like "on foo:"
Test: atest CtsInitTestCases
Test: builds
Bug: 135984674
Change-Id: I6e4e18970e957d25dea9f557f0d31a759fbe6150
Diffstat (limited to 'init/action_parser.cpp')
-rw-r--r-- | init/action_parser.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/init/action_parser.cpp b/init/action_parser.cpp index 9736824f9..a8e1e09f8 100644 --- a/init/action_parser.cpp +++ b/init/action_parser.cpp @@ -16,11 +16,14 @@ #include "action_parser.h" +#include <ctype.h> + #include <android-base/properties.h> #include <android-base/strings.h> #if defined(__ANDROID__) #include "property_service.h" +#include "selinux.h" #else #include "host_init_stubs.h" #endif @@ -77,6 +80,17 @@ Result<void> ParsePropertyTrigger(const std::string& trigger, Subcontext* subcon return {}; } +Result<void> ValidateEventTrigger(const std::string& event_trigger) { + if (SelinuxGetVendorAndroidVersion() >= __ANDROID_API_R__) { + for (const char& c : event_trigger) { + if (c != '_' && c != '-' && !std::isalnum(c)) { + return Error() << "Illegal character '" << c << "' in '" << event_trigger << "'"; + } + } + } + return {}; +} + Result<void> ParseTriggers(const std::vector<std::string>& args, Subcontext* subcontext, std::string* event_trigger, std::map<std::string, std::string>* property_triggers) { @@ -103,6 +117,9 @@ Result<void> ParseTriggers(const std::vector<std::string>& args, Subcontext* sub if (!event_trigger->empty()) { return Error() << "multiple event triggers are not allowed"; } + if (auto result = ValidateEventTrigger(args[i]); !result) { + return result; + } *event_trigger = args[i]; } |