diff options
author | Tom Cherry | 2018-06-19 17:18:40 -0500 |
---|---|---|
committer | Tom Cherry | 2018-06-19 17:18:40 -0500 |
commit | d72432de930b329dd0cf14b62a67618e11e8e7cb (patch) | |
tree | 0e20bf57476557c11535662726a280ddc1392eca | |
parent | 28a3160c077446719fe9c95e0a0730689e8e44ad (diff) | |
download | platform-system-core-d72432de930b329dd0cf14b62a67618e11e8e7cb.tar.gz platform-system-core-d72432de930b329dd0cf14b62a67618e11e8e7cb.tar.xz platform-system-core-d72432de930b329dd0cf14b62a67618e11e8e7cb.zip |
Don't check permissions bits on init scripts for host_init_verifier
Also get rid of the copy in parser. There's no incentive to switch to
a tokenizer that doesn't modify the input, nor is there a reason to
waste cycles making a copy of every init script as its processed.
Bug: 36970783
Test: boot
Change-Id: I8aca9c9d6f1961e1ab35dee50691a6791fc6ec66
-rw-r--r-- | init/host_init_verifier.cpp | 2 | ||||
-rw-r--r-- | init/parser.cpp | 31 | ||||
-rw-r--r-- | init/parser.h | 5 |
3 files changed, 26 insertions, 12 deletions
diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp index 7e93b448c..84077291c 100644 --- a/init/host_init_verifier.cpp +++ b/init/host_init_verifier.cpp | |||
@@ -146,7 +146,7 @@ int main(int argc, char** argv) { | |||
146 | parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr)); | 146 | parser.AddSectionParser("on", std::make_unique<ActionParser>(&am, nullptr)); |
147 | parser.AddSectionParser("import", std::make_unique<HostImportParser>()); | 147 | parser.AddSectionParser("import", std::make_unique<HostImportParser>()); |
148 | 148 | ||
149 | if (!parser.ParseConfig(argv[1])) { | 149 | if (!parser.ParseConfigFileInsecure(argv[1])) { |
150 | LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'"; | 150 | LOG(ERROR) << "Failed to open init rc script '" << argv[1] << "'"; |
151 | return EXIT_FAILURE; | 151 | return EXIT_FAILURE; |
152 | } | 152 | } |
diff --git a/init/parser.cpp b/init/parser.cpp index 4f1cac495..fa0fd11be 100644 --- a/init/parser.cpp +++ b/init/parser.cpp | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <dirent.h> | 19 | #include <dirent.h> |
20 | 20 | ||
21 | #include <android-base/chrono_utils.h> | 21 | #include <android-base/chrono_utils.h> |
22 | #include <android-base/file.h> | ||
22 | #include <android-base/logging.h> | 23 | #include <android-base/logging.h> |
23 | #include <android-base/stringprintf.h> | 24 | #include <android-base/stringprintf.h> |
24 | #include <android-base/strings.h> | 25 | #include <android-base/strings.h> |
@@ -39,14 +40,13 @@ void Parser::AddSingleLineParser(const std::string& prefix, LineCallback callbac | |||
39 | line_callbacks_.emplace_back(prefix, callback); | 40 | line_callbacks_.emplace_back(prefix, callback); |
40 | } | 41 | } |
41 | 42 | ||
42 | void Parser::ParseData(const std::string& filename, const std::string& data) { | 43 | void Parser::ParseData(const std::string& filename, std::string* data) { |
43 | // TODO: Use a parser with const input and remove this copy | 44 | data->push_back('\n'); // TODO: fix tokenizer |
44 | std::vector<char> data_copy(data.begin(), data.end()); | 45 | data->push_back('\0'); |
45 | data_copy.push_back('\0'); | ||
46 | 46 | ||
47 | parse_state state; | 47 | parse_state state; |
48 | state.line = 0; | 48 | state.line = 0; |
49 | state.ptr = &data_copy[0]; | 49 | state.ptr = data->data(); |
50 | state.nexttoken = 0; | 50 | state.nexttoken = 0; |
51 | 51 | ||
52 | SectionParser* section_parser = nullptr; | 52 | SectionParser* section_parser = nullptr; |
@@ -69,6 +69,11 @@ void Parser::ParseData(const std::string& filename, const std::string& data) { | |||
69 | switch (next_token(&state)) { | 69 | switch (next_token(&state)) { |
70 | case T_EOF: | 70 | case T_EOF: |
71 | end_section(); | 71 | end_section(); |
72 | |||
73 | for (const auto& [section_name, section_parser] : section_parsers_) { | ||
74 | section_parser->EndFile(); | ||
75 | } | ||
76 | |||
72 | return; | 77 | return; |
73 | case T_NEWLINE: { | 78 | case T_NEWLINE: { |
74 | state.line++; | 79 | state.line++; |
@@ -118,6 +123,16 @@ void Parser::ParseData(const std::string& filename, const std::string& data) { | |||
118 | } | 123 | } |
119 | } | 124 | } |
120 | 125 | ||
126 | bool Parser::ParseConfigFileInsecure(const std::string& path) { | ||
127 | std::string config_contents; | ||
128 | if (!android::base::ReadFileToString(path, &config_contents)) { | ||
129 | return false; | ||
130 | } | ||
131 | |||
132 | ParseData(path, &config_contents); | ||
133 | return true; | ||
134 | } | ||
135 | |||
121 | bool Parser::ParseConfigFile(const std::string& path) { | 136 | bool Parser::ParseConfigFile(const std::string& path) { |
122 | LOG(INFO) << "Parsing file " << path << "..."; | 137 | LOG(INFO) << "Parsing file " << path << "..."; |
123 | android::base::Timer t; | 138 | android::base::Timer t; |
@@ -127,11 +142,7 @@ bool Parser::ParseConfigFile(const std::string& path) { | |||
127 | return false; | 142 | return false; |
128 | } | 143 | } |
129 | 144 | ||
130 | config_contents->push_back('\n'); // TODO: fix parse_config. | 145 | ParseData(path, &config_contents.value()); |
131 | ParseData(path, *config_contents); | ||
132 | for (const auto& [section_name, section_parser] : section_parsers_) { | ||
133 | section_parser->EndFile(); | ||
134 | } | ||
135 | 146 | ||
136 | LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; | 147 | LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; |
137 | return true; | 148 | return true; |
diff --git a/init/parser.h b/init/parser.h index 3501d8c0b..2454b6a6f 100644 --- a/init/parser.h +++ b/init/parser.h | |||
@@ -75,10 +75,13 @@ class Parser { | |||
75 | void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); | 75 | void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); |
76 | void AddSingleLineParser(const std::string& prefix, LineCallback callback); | 76 | void AddSingleLineParser(const std::string& prefix, LineCallback callback); |
77 | 77 | ||
78 | // Host init verifier check file permissions. | ||
79 | bool ParseConfigFileInsecure(const std::string& path); | ||
80 | |||
78 | size_t parse_error_count() const { return parse_error_count_; } | 81 | size_t parse_error_count() const { return parse_error_count_; } |
79 | 82 | ||
80 | private: | 83 | private: |
81 | void ParseData(const std::string& filename, const std::string& data); | 84 | void ParseData(const std::string& filename, std::string* data); |
82 | bool ParseConfigFile(const std::string& path); | 85 | bool ParseConfigFile(const std::string& path); |
83 | bool ParseConfigDir(const std::string& path); | 86 | bool ParseConfigDir(const std::string& path); |
84 | 87 | ||