From 3a18dd68cfc6ce03996ff28480a7b667ec8cf836 Mon Sep 17 00:00:00 2001 From: Leander Schulten Date: Mon, 25 Sep 2023 13:14:16 +0200 Subject: [PATCH] Fix crash while parsing malformed manifest files. --- src/vcpkg-test/manifests.cpp | 19 +++++++++++++++++++ src/vcpkg/commands.install.cpp | 1 + src/vcpkg/sourceparagraph.cpp | 9 +++++++-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/vcpkg-test/manifests.cpp b/src/vcpkg-test/manifests.cpp index 696a9fc88e..bf5455573e 100644 --- a/src/vcpkg-test/manifests.cpp +++ b/src/vcpkg-test/manifests.cpp @@ -1091,6 +1091,25 @@ TEST_CASE ("SourceParagraph manifest default feature missing name", "[manifests] REQUIRE(!m_pgh.has_value()); } +TEST_CASE ("SourceParagraph manifest default feature reserved name", "[manifests]") +{ + auto m_pgh = test_parse_port_manifest(R"json({ + "name": "a", + "version-string": "1.0", + "default-features": ["core"] + })json", + PrintErrors::No); + REQUIRE(!m_pgh.has_value()); + + m_pgh = test_parse_port_manifest(R"json({ + "name": "a", + "version-string": "1.0", + "default-features": [{"name": "core", "platform": "!windows"}] + })json", + PrintErrors::No); + REQUIRE(!m_pgh.has_value()); +} + TEST_CASE ("SourceParagraph manifest description paragraph", "[manifests]") { auto m_pgh = test_parse_port_manifest(R"json({ diff --git a/src/vcpkg/commands.install.cpp b/src/vcpkg/commands.install.cpp index 6c333d2c1f..62f213a52a 100644 --- a/src/vcpkg/commands.install.cpp +++ b/src/vcpkg/commands.install.cpp @@ -1105,6 +1105,7 @@ namespace vcpkg if (!maybe_manifest_scf) { print_error_message(maybe_manifest_scf.error()); + msg::println(); msg::println(msgExtendedDocumentationAtUrl, msg::url = docs::manifests_url); Checks::exit_fail(VCPKG_LINE_INFO); } diff --git a/src/vcpkg/sourceparagraph.cpp b/src/vcpkg/sourceparagraph.cpp index 3cab387036..45ad12e40a 100644 --- a/src/vcpkg/sourceparagraph.cpp +++ b/src/vcpkg/sourceparagraph.cpp @@ -510,10 +510,15 @@ namespace vcpkg return t; } + static std::string map_illegal_names(std::string&& name) + { + return Json::IdentifierDeserializer::is_ident(name) ? std::move(name) : ""; + } + Optional visit_string(Json::Reader& r, StringView sv) const override { return Json::IdentifierDeserializer::instance.visit_string(r, sv).map( - [](std::string&& name) { return std::move(name); }); + [](std::string&& name) { return map_illegal_names(std::move(name)); }); } Optional visit_object(Json::Reader& r, const Json::Object& obj) const override @@ -523,7 +528,7 @@ namespace vcpkg r.required_object_field(type_name(), obj, NAME, name, Json::IdentifierDeserializer::instance); r.optional_object_field(obj, PLATFORM, platform, PlatformExprDeserializer::instance); if (name.empty()) return nullopt; - return DependencyRequestedFeature{std::move(name), std::move(platform)}; + return DependencyRequestedFeature{map_illegal_names(std::move(name)), std::move(platform)}; } const static DependencyFeatureDeserializer instance;