From 7c807fc0d4561d178b7c2d8b8d532f48e78ab1bc Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Fri, 30 Jan 2015 17:21:56 +0100 Subject: [PATCH] Escape encoded character in URLs in manifest Change-Id: I30667246ca44bd66ca80953ac9f54555a2564c34 --- src/signature/signature_parser.cc | 29 +++-------------------------- src/utils/string_util.cc | 27 +++++++++++++++++++++++++++ src/utils/string_util.h | 2 ++ src/widget-manifest-parser/manifest_util.cc | 16 +++++----------- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/signature/signature_parser.cc b/src/signature/signature_parser.cc index cf3bdf6..06fcd48 100644 --- a/src/signature/signature_parser.cc +++ b/src/signature/signature_parser.cc @@ -23,6 +23,7 @@ #include "utils/logging.h" #include "utils/macros.h" +#include "utils/string_util.h" namespace { const char kExpectedXmlns[] = "http://www.w3.org/2000/09/xmldsig#"; @@ -122,31 +123,6 @@ std::string XmlStringToStdString(const xmlChar* xmlstring) { return ""; } -std::string DecodeProcent(const std::string& path) { - std::vector input(path.begin(), path.end()); - std::vector output; - int i = 0; - while (i < input.size()) { - if ('%' == input[i]) { - if (i + 2 >= input.size()) - return std::string(); - char str[3] = {"\0",}; - str[0] = input[i + 1]; - str[1] = input[i + 2]; - int result = strtol(str, NULL, 16); - // RFC 1738 - octets 80 to FF are not allowed - if (result >= 128) - return std::string(); - output.push_back(static_cast(result)); - i += 3; - } else { - output.push_back(static_cast(input[i])); - ++i; - } - } - return std::string(output.begin(), output.end()); -} - } // namespace namespace common_installer { @@ -201,7 +177,8 @@ bool ParseSignedInfoElement( LOG(ERROR) << "Missing URI attribute."; return false; } - std::string decoded_uri = DecodeProcent(uri); + std::string decoded_uri = + common_installer::utils::DecodePercentEscapedCharacter(uri); if (!decoded_uri.empty()) { uri = decoded_uri; } else { diff --git a/src/utils/string_util.cc b/src/utils/string_util.cc index f11e608..a072c65 100644 --- a/src/utils/string_util.cc +++ b/src/utils/string_util.cc @@ -5,7 +5,9 @@ #include "utils/string_util.h" +#include #include +#include namespace { @@ -183,5 +185,30 @@ std::string GetDirTextUTF8(const std::string& text, const std::string& dir) { return text; } +std::string DecodePercentEscapedCharacter(const std::string& path) { + std::vector input(path.begin(), path.end()); + std::vector output; + unsigned i = 0; + while (i < input.size()) { + if ('%' == input[i]) { + if (i + 2 >= input.size()) + return std::string(); + char str[3] = {"\0",}; + str[0] = input[i + 1]; + str[1] = input[i + 2]; + int result = strtol(str, NULL, 16); + // RFC 1738 - octets 80 to FF are not allowed + if (result >= 128) + return std::string(); + output.push_back(static_cast(result)); + i += 3; + } else { + output.push_back(static_cast(input[i])); + ++i; + } + } + return std::string(output.begin(), output.end()); +} + } // namespace utils } // namespace common_installer diff --git a/src/utils/string_util.h b/src/utils/string_util.h index d0a57fd..10a97ce 100644 --- a/src/utils/string_util.h +++ b/src/utils/string_util.h @@ -16,6 +16,8 @@ std::string CollapseWhitespaceUTF8(const std::string& text, std::string StripWrappingBidiControlCharactersUTF8(const std::string& text); std::string GetDirTextUTF8(const std::string& text, const std::string& dir); +std::string DecodePercentEscapedCharacter(const std::string& path); + } // namespace utils } // namespace common_installer diff --git a/src/widget-manifest-parser/manifest_util.cc b/src/widget-manifest-parser/manifest_util.cc index abba8d2..a2978e6 100644 --- a/src/widget-manifest-parser/manifest_util.cc +++ b/src/widget-manifest-parser/manifest_util.cc @@ -339,17 +339,11 @@ bf::path ApplicationURLToRelativeFilePath(const std::string& url) { if (url_path.empty() || url_path[0] != '/') return bf::path(); - // TODO(jizydorczyk): - // We need to unescappe %-encoded UTF8 chars here - // for now its left undone - // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8. -// std::string file_path = net::UnescapeURLComponent(url_path, -// net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS); -// size_t skip = file_path.find_first_not_of("/\\"); -// if (skip != file_path.npos) -// file_path = file_path.substr(skip); - - std::string file_path = url_path; + std::string file_path = + common_installer::utils::DecodePercentEscapedCharacter(url_path); + if (file_path.empty()) + return bf::path(); + bf::path path(file_path); // It's still possible for someone to construct an annoying URL whose path -- 2.7.4