Skip to content

Commit

Permalink
update_client: Check string length before calling front().
Browse files Browse the repository at this point in the history
(cherry picked from commit 6581c6b)

Fixed: 1486316
Change-Id: I7be04ea0c8e040b5a67364925fc06d4ee9167242
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4892838
Commit-Queue: Joshua Pawlicki <waffles@chromium.org>
Auto-Submit: Joshua Pawlicki <waffles@chromium.org>
Reviewed-by: Sorin Jianu <sorin@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1201617}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4902697
Cr-Commit-Position: refs/branch-heads/5993@{#978}
Cr-Branched-From: 5113507-refs/heads/main@{#1192594}
  • Loading branch information
Joshua Pawlicki authored and Chromium LUCI CQ committed Sep 29, 2023
1 parent 31e39e7 commit f218b4f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components/update_client/protocol_parser_json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ bool ParseUpdateCheck(const base::Value& updatecheck_node_val,
const base::Value::Dict& updatecheck_node = updatecheck_node_val.GetDict();

for (auto kv : updatecheck_node) {
if (kv.first.front() == '_' && kv.second.is_string()) {
if (!kv.first.empty() && kv.first.front() == '_' && kv.second.is_string()) {
result->custom_attributes[kv.first] = kv.second.GetString();
}
}
Expand Down
9 changes: 9 additions & 0 deletions components/update_client/protocol_parser_json_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ const char* kJSONCustomAttributes = R"()]}'
]
}})";

const char* kBadJSONBadAppIdNoNewlinesBadUCKey =
R"()]}'{"response":{"app":[{"appid":";","updatecheck":{"":1}}],)"
R"("protocol":"3.1"}})";

TEST(UpdateClientProtocolParserJSONTest, Parse) {
const auto parser = std::make_unique<ProtocolParserJSON>();

Expand Down Expand Up @@ -610,4 +614,9 @@ TEST(UpdateClientProtocolParserJSONTest, ParseAttrs) {
}
}

TEST(UpdateClientProtocolParserJSONTest, ParseBadJSONNoCrash) {
const auto parser = std::make_unique<ProtocolParserJSON>();
EXPECT_TRUE(parser->Parse(kBadJSONBadAppIdNoNewlinesBadUCKey));
}

} // namespace update_client

0 comments on commit f218b4f

Please sign in to comment.