Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit db976aa5 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Create a host side checker for property info file correctness"

parents 2af1be4c 919458c3
Loading
Loading
Loading
Loading
+8 −30
Original line number Diff line number Diff line
@@ -58,7 +58,6 @@

#include "init.h"
#include "persistent_properties.h"
#include "space_tokenizer.h"
#include "util.h"

using android::base::ReadFileToString;
@@ -69,6 +68,7 @@ using android::base::Timer;
using android::base::Trim;
using android::base::WriteStringToFile;
using android::properties::BuildTrie;
using android::properties::ParsePropertyInfoFile;
using android::properties::PropertyInfoAreaFile;
using android::properties::PropertyInfoEntry;

@@ -728,22 +728,6 @@ static int SelinuxAuditCallback(void* data, security_class_t /*cls*/, char* buf,
    return 0;
}

Result<PropertyInfoEntry> ParsePropertyInfoLine(const std::string& line) {
    auto tokenizer = SpaceTokenizer(line);

    auto property = tokenizer.GetNext();
    if (property.empty()) return Error() << "Did not find a property entry in '" << line << "'";

    auto context = tokenizer.GetNext();
    if (context.empty()) return Error() << "Did not find a context entry in '" << line << "'";

    // It is not an error to not find these, as older files will not contain them.
    auto exact_match = tokenizer.GetNext();
    auto schema = tokenizer.GetRemaining();

    return {property, context, schema, exact_match == "exact"};
}

bool LoadPropertyInfoFromFile(const std::string& filename,
                              std::vector<PropertyInfoEntry>* property_infos) {
    auto file_contents = std::string();
@@ -752,20 +736,14 @@ bool LoadPropertyInfoFromFile(const std::string& filename,
        return false;
    }

    for (const auto& line : Split(file_contents, "\n")) {
        auto trimmed_line = Trim(line);
        if (trimmed_line.empty() || StartsWith(trimmed_line, "#")) {
            continue;
    auto errors = std::vector<std::string>{};
    ParsePropertyInfoFile(file_contents, property_infos, &errors);
    // Individual parsing errors are reported but do not cause a failed boot, which is what
    // returning false would do here.
    for (const auto& error : errors) {
        LOG(ERROR) << "Could not read line from '" << filename << "': " << error;
    }

        auto property_info = ParsePropertyInfoLine(line);
        if (!property_info) {
            LOG(ERROR) << "Could not read line from '" << filename << "': " << property_info.error();
            continue;
        }

        property_infos->emplace_back(*property_info);
    }
    return true;
}

+1 −0
Original line number Diff line number Diff line
cc_library_static {
    name: "libpropertyinfoparser",
    host_supported: true,
    srcs: ["property_info_parser.cpp"],

    cpp_std: "experimental",
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#define PROPERTY_INFO_PARSER_H

#include <stdint.h>
#include <stdlib.h>

namespace android {
namespace properties {
+2 −0
Original line number Diff line number Diff line
cc_defaults {
    name: "propertyinfoserializer_defaults",
    host_supported: true,
    cpp_std: "experimental",
    sanitize: {
        misc_undefined: ["signed-integer-overflow"],
@@ -19,6 +20,7 @@ cc_library_static {
    name: "libpropertyinfoserializer",
    defaults: ["propertyinfoserializer_defaults"],
    srcs: [
        "property_info_file.cpp",
        "property_info_serializer.cpp",
        "trie_builder.cpp",
        "trie_serializer.cpp",
+4 −0
Original line number Diff line number Diff line
@@ -41,6 +41,10 @@ bool BuildTrie(const std::vector<PropertyInfoEntry>& property_info,
               const std::string& default_context, const std::string& default_schema,
               std::string* serialized_trie, std::string* error);

void ParsePropertyInfoFile(const std::string& file_contents,
                           std::vector<PropertyInfoEntry>* property_infos,
                           std::vector<std::string>* errors);

}  // namespace properties
}  // namespace android

Loading