Commit 1d8faa9c authored by huangs's avatar huangs Committed by Commit bot

[Top Sites] Validating URLs for "redirects"

Redirects field in TopSitesDatabase is encoded as a space-seprated list
of URLs. But data URLS like "data:text/plain,this text  has space" adds
extra space, so that when decoded, non-URLs like "text" and "has" would
trigger DCHECK in URL() downstream, and crash debug Chrome.

This CL validates redirects URLs when they are read. It is not foolproof
(e.g., "data:text/plan,hidden http://extra.url"), but now we can ponder
how to best fix the root cause, without keeping the crashing bug around.

BUG=358034

Review URL: https://codereview.chromium.org/562993002

Cr-Commit-Position: refs/heads/master@{#296232}
parent 34687555
...@@ -90,8 +90,11 @@ std::string GetRedirects(const history::MostVisitedURL& url) { ...@@ -90,8 +90,11 @@ std::string GetRedirects(const history::MostVisitedURL& url) {
void SetRedirects(const std::string& redirects, history::MostVisitedURL* url) { void SetRedirects(const std::string& redirects, history::MostVisitedURL* url) {
std::vector<std::string> redirects_vector; std::vector<std::string> redirects_vector;
base::SplitStringAlongWhitespace(redirects, &redirects_vector); base::SplitStringAlongWhitespace(redirects, &redirects_vector);
for (size_t i = 0; i < redirects_vector.size(); ++i) for (size_t i = 0; i < redirects_vector.size(); ++i) {
url->redirects.push_back(GURL(redirects_vector[i])); GURL redirects_url(redirects_vector[i]);
if (redirects_url.is_valid())
url->redirects.push_back(redirects_url);
}
} }
// Track various failure (and success) cases in recovery code. // Track various failure (and success) cases in recovery code.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment