Remove invalid "suffix" assumption from CreateSortKey
Currently, CreateSortKey in password_manager_presenter.cc assumes that domain and registry name obtained from a hostname string is always a suffix of the hostname string. This is true for ASCII-based examples like this: hostname: subdomain.example.com domain and registry: example.com But it is not true for non-ASCII-based examples like this: hostname: žřč.com domain and registry: xn--bea5m6d.com The reason is that to obtain the domain and registry, the hostname is being canonicalized. The domain and registry is used to create a sort key for a credential with the given hostname. The idea is to start with the domain and registry part, and then append the remaining subdomains (reversed). The remaining subdomains were computed by taking the prefix of hostname of the length of the difference of the length of the hostname minus the length of the domain and registry part. This number may overflow in case the domain and registry is not a suffix of the hostname. This CL fixes the issue by appending the whole hostname to the domain and registry part. The results look like this: hostname: subdomain.example.com old key: example.com.subdomain new key: example.com.com.example.subdomain hostname: žřč.com old key: undefined new key: xn--bea5m6d.com.com.žřč This is safe (no assumptions about suffixes) and preserves the sorting order of any two credentials before and after this change. It is potentially duplicating the domain and registry part. An alternative solution could just canonicalize the hostname before composing the key, but the code would be more complex for an unclear benefit. The CL also uses a more efficient call to GetDomainAndRegistry (avoiding redoing the canonicalization of a known URL). It also introduces a test and removes an unnecessary call to ASCIIToUTF16. BUG=655949 Review-Url: https://codereview.chromium.org/2439953004 Cr-Commit-Position: refs/heads/master@{#427051}
Showing
Please register or sign in to comment