From f643b354fefea310981afcd524832e9c52039826 Mon Sep 17 00:00:00 2001 From: Jingwen Chen Date: Thu, 16 Mar 2023 16:22:25 +0000 Subject: [PATCH] Make the host_init_verifier init.rc parser follow symlinks. Bazel's intermediates/inputs are symlinks in its execution root, unlike Soong. e.g. $ file $(readlink -f out/bazel/output/execroot/__main__/packages/modules/adb/apex/adbd.rc) /usr/local/google/home/jingwen/aosp/master-with-phones/packages/modules/adb/apex/adbd.rc: ASCII text Test: presubmits Change-Id: I3977a37ee989e07bee56abb019a21055b8cef567 --- init/fuzzer/init_parser_fuzzer.cpp | 2 +- init/host_init_verifier.cpp | 4 +++- init/parser.cpp | 4 ++-- init/parser.h | 2 +- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/init/fuzzer/init_parser_fuzzer.cpp b/init/fuzzer/init_parser_fuzzer.cpp index e6a78a2c4..dc764650a 100644 --- a/init/fuzzer/init_parser_fuzzer.cpp +++ b/init/fuzzer/init_parser_fuzzer.cpp @@ -125,7 +125,7 @@ void InitParserFuzzer::InvokeParser() { std::string path = fdp_.ConsumeBool() ? fdp_.PickValueInArray(kValidPaths) : fdp_.ConsumeRandomLengthString(kMaxBytes); parser.ParseConfig(path); - parser.ParseConfigFileInsecure(path); + parser.ParseConfigFileInsecure(path, false /* follow_symlinks */); } void InitParserFuzzer::Process() { diff --git a/init/host_init_verifier.cpp b/init/host_init_verifier.cpp index db127d3f2..f070776ec 100644 --- a/init/host_init_verifier.cpp +++ b/init/host_init_verifier.cpp @@ -326,7 +326,9 @@ int main(int argc, char** argv) { } } } else { - if (!parser.ParseConfigFileInsecure(*argv)) { + if (!parser.ParseConfigFileInsecure(*argv, true /* follow_symlinks */)) { + // Follow symlinks as inputs during build execution in Bazel's + // execution root are symlinks, unlike Soong or Make. LOG(ERROR) << "Failed to open init rc script '" << *argv << "'"; return EXIT_FAILURE; } diff --git a/init/parser.cpp b/init/parser.cpp index adb41add1..8c0bb2b68 100644 --- a/init/parser.cpp +++ b/init/parser.cpp @@ -131,9 +131,9 @@ void Parser::ParseData(const std::string& filename, std::string* data) { } } -bool Parser::ParseConfigFileInsecure(const std::string& path) { +bool Parser::ParseConfigFileInsecure(const std::string& path, bool follow_symlinks = false) { std::string config_contents; - if (!android::base::ReadFileToString(path, &config_contents)) { + if (!android::base::ReadFileToString(path, &config_contents, follow_symlinks)) { return false; } diff --git a/init/parser.h b/init/parser.h index 980ae0ccb..8e5bca773 100644 --- a/init/parser.h +++ b/init/parser.h @@ -77,7 +77,7 @@ class Parser { void AddSingleLineParser(const std::string& prefix, LineCallback callback); // Host init verifier check file permissions. - bool ParseConfigFileInsecure(const std::string& path); + bool ParseConfigFileInsecure(const std::string& path, bool follow_symlinks); size_t parse_error_count() const { return parse_error_count_; }