summaryrefslogtreecommitdiffstats
path: root/init
diff options
context:
space:
mode:
authorTom Cherry2018-06-20 12:06:11 -0500
committerGerrit Code Review2018-06-20 12:06:11 -0500
commit81101cb216c9009a60edf4e3fa6709b0c6437f2e (patch)
tree8d3632b957d5f1331716ed97de222424bda39e81 /init
parent08839ff904051bfb07a44a8052fd4e4949cd9625 (diff)
parentd72432de930b329dd0cf14b62a67618e11e8e7cb (diff)
downloadplatform-system-core-81101cb216c9009a60edf4e3fa6709b0c6437f2e.tar.gz
platform-system-core-81101cb216c9009a60edf4e3fa6709b0c6437f2e.tar.xz
platform-system-core-81101cb216c9009a60edf4e3fa6709b0c6437f2e.zip
Merge "Don't check permissions bits on init scripts for host_init_verifier"
Diffstat (limited to 'init')
-rw-r--r--init/host_init_verifier.cpp2
-rw-r--r--init/parser.cpp31
-rw-r--r--init/parser.h5
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
42void Parser::ParseData(const std::string& filename, const std::string& data) { 43void 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
126bool 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
121bool Parser::ParseConfigFile(const std::string& path) { 136bool 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