Commit 84f268ae authored by Steven Bingler's avatar Steven Bingler Committed by Commit Bot

Reorder cookie DB access statements

The ordering of columns in the SQL access statements was different from
the initial schema. This CL reorders them to match.

While it is possible to omit the column names and only reference them
by number the code is easier to read/confirm correct by using the
names.

Fixed: 1149659
Change-Id: Ia60848f5d3b5940b5f283448911ce426271c7328
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2542943
Commit-Queue: Steven Bingler <bingler@chromium.org>
Reviewed-by: default avatarLily Chen <chlily@chromium.org>
Reviewed-by: default avatarMaksim Orlovich <morlovich@chromium.org>
Cr-Commit-Position: refs/heads/master@{#828855}
parent 7d0d3abd
...@@ -878,24 +878,20 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains( ...@@ -878,24 +878,20 @@ bool SQLitePersistentCookieStore::Backend::LoadCookiesForDomains(
DCHECK(background_task_runner()->RunsTasksInCurrentSequence()); DCHECK(background_task_runner()->RunsTasksInCurrentSequence());
sql::Statement smt, del_smt; sql::Statement smt, del_smt;
// TODO(chlily): These are out of order with respect to the schema
// declaration. Fix this.
if (restore_old_session_cookies_) { if (restore_old_session_cookies_) {
smt.Assign(db()->GetCachedStatement( smt.Assign(db()->GetCachedStatement(
SQL_FROM_HERE, SQL_FROM_HERE,
"SELECT creation_utc, host_key, name, value, encrypted_value, path, " "SELECT creation_utc, host_key, name, value, path, expires_utc, "
"expires_utc, is_secure, is_httponly, samesite, " "is_secure, is_httponly, last_access_utc, has_expires, is_persistent, "
"last_access_utc, has_expires, is_persistent, priority, " "priority, encrypted_value, samesite, source_scheme, source_port, "
"source_scheme, source_port, is_same_party " "is_same_party FROM cookies WHERE host_key = ?"));
"FROM cookies WHERE host_key = ?"));
} else { } else {
smt.Assign(db()->GetCachedStatement( smt.Assign(db()->GetCachedStatement(
SQL_FROM_HERE, SQL_FROM_HERE,
"SELECT creation_utc, host_key, name, value, encrypted_value, path, " "SELECT creation_utc, host_key, name, value, path, expires_utc, "
"expires_utc, is_secure, is_httponly, samesite, last_access_utc, " "is_secure, is_httponly, last_access_utc, has_expires, is_persistent, "
"has_expires, is_persistent, priority, source_scheme, source_port, " "priority, encrypted_value, samesite, source_scheme, source_port, "
"is_same_party " "is_same_party FROM cookies WHERE host_key = ? AND is_persistent = 1"));
"FROM cookies WHERE host_key = ? AND is_persistent = 1"));
} }
del_smt.Assign(db()->GetCachedStatement( del_smt.Assign(db()->GetCachedStatement(
SQL_FROM_HERE, "DELETE FROM cookies WHERE host_key = ?")); SQL_FROM_HERE, "DELETE FROM cookies WHERE host_key = ?"));
...@@ -946,7 +942,7 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement( ...@@ -946,7 +942,7 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
bool ok = true; bool ok = true;
while (smt.Step()) { while (smt.Step()) {
std::string value; std::string value;
std::string encrypted_value = smt.ColumnString(4); std::string encrypted_value = smt.ColumnString(12);
if (!encrypted_value.empty() && crypto_) { if (!encrypted_value.empty() && crypto_) {
scoped_refptr<TimeoutTracker> timeout_tracker = scoped_refptr<TimeoutTracker> timeout_tracker =
TimeoutTracker::Begin(client_task_runner()); TimeoutTracker::Begin(client_task_runner());
...@@ -965,16 +961,16 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement( ...@@ -965,16 +961,16 @@ bool SQLitePersistentCookieStore::Backend::MakeCookiesFromSQLStatement(
smt.ColumnString(2), // name smt.ColumnString(2), // name
value, // value value, // value
smt.ColumnString(1), // domain smt.ColumnString(1), // domain
smt.ColumnString(5), // path smt.ColumnString(4), // path
Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc Time::FromInternalValue(smt.ColumnInt64(0)), // creation_utc
Time::FromInternalValue(smt.ColumnInt64(6)), // expires_utc Time::FromInternalValue(smt.ColumnInt64(5)), // expires_utc
Time::FromInternalValue(smt.ColumnInt64(10)), // last_access_utc Time::FromInternalValue(smt.ColumnInt64(8)), // last_access_utc
smt.ColumnBool(7), // secure smt.ColumnBool(6), // secure
smt.ColumnBool(8), // http_only smt.ColumnBool(7), // http_only
DBCookieSameSiteToCookieSameSite( DBCookieSameSiteToCookieSameSite(
static_cast<DBCookieSameSite>(smt.ColumnInt(9))), // samesite static_cast<DBCookieSameSite>(smt.ColumnInt(13))), // samesite
DBCookiePriorityToCookiePriority( DBCookiePriorityToCookiePriority(
static_cast<DBCookiePriority>(smt.ColumnInt(13))), // priority static_cast<DBCookiePriority>(smt.ColumnInt(11))), // priority
smt.ColumnBool(16), // is_same_party smt.ColumnBool(16), // is_same_party
DBToCookieSourceScheme(smt.ColumnInt(14)), // source_scheme DBToCookieSourceScheme(smt.ColumnInt(14)), // source_scheme
smt.ColumnInt(15)); // source_port smt.ColumnInt(15)); // source_port
...@@ -1236,12 +1232,10 @@ void SQLitePersistentCookieStore::Backend::DoCommit() { ...@@ -1236,12 +1232,10 @@ void SQLitePersistentCookieStore::Backend::DoCommit() {
sql::Statement add_smt(db()->GetCachedStatement( sql::Statement add_smt(db()->GetCachedStatement(
SQL_FROM_HERE, SQL_FROM_HERE,
// TODO(chlily): These are out of order with respect to the schema "INSERT INTO cookies (creation_utc, host_key, name, value, path, "
// declaration. Fix this. "expires_utc, is_secure, is_httponly, last_access_utc, has_expires, "
"INSERT INTO cookies (creation_utc, host_key, name, value, " "is_persistent, priority, encrypted_value, samesite, source_scheme, "
"encrypted_value, path, expires_utc, is_secure, is_httponly, " "source_port, is_same_party) "
"samesite, last_access_utc, has_expires, is_persistent, priority,"
"source_scheme, source_port, is_same_party) "
"VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)")); "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"));
if (!add_smt.is_valid()) if (!add_smt.is_valid())
return; return;
...@@ -1283,23 +1277,24 @@ void SQLitePersistentCookieStore::Backend::DoCommit() { ...@@ -1283,23 +1277,24 @@ void SQLitePersistentCookieStore::Backend::DoCommit() {
} }
add_smt.BindCString(3, ""); // value add_smt.BindCString(3, ""); // value
// BindBlob() immediately makes an internal copy of the data. // BindBlob() immediately makes an internal copy of the data.
add_smt.BindBlob(4, encrypted_value.data(), add_smt.BindBlob(12, encrypted_value.data(),
static_cast<int>(encrypted_value.length())); static_cast<int>(encrypted_value.length()));
} else { } else {
add_smt.BindString(3, po->cc().Value()); add_smt.BindString(3, po->cc().Value());
add_smt.BindBlob(4, "", 0); // encrypted_value add_smt.BindBlob(12, "", 0); // encrypted_value
} }
add_smt.BindString(5, po->cc().Path()); add_smt.BindString(4, po->cc().Path());
add_smt.BindInt64(6, po->cc().ExpiryDate().ToInternalValue()); add_smt.BindInt64(5, po->cc().ExpiryDate().ToInternalValue());
add_smt.BindBool(7, po->cc().IsSecure()); add_smt.BindBool(6, po->cc().IsSecure());
add_smt.BindBool(8, po->cc().IsHttpOnly()); add_smt.BindBool(7, po->cc().IsHttpOnly());
add_smt.BindInt64(8, po->cc().LastAccessDate().ToInternalValue());
add_smt.BindBool(9, po->cc().IsPersistent());
add_smt.BindBool(10, po->cc().IsPersistent());
add_smt.BindInt( add_smt.BindInt(
9, CookieSameSiteToDBCookieSameSite(po->cc().SameSite())); 11, CookiePriorityToDBCookiePriority(po->cc().Priority()));
add_smt.BindInt64(10, po->cc().LastAccessDate().ToInternalValue()); // 12, encrypted_value, inserted above.
add_smt.BindBool(11, po->cc().IsPersistent());
add_smt.BindBool(12, po->cc().IsPersistent());
add_smt.BindInt( add_smt.BindInt(
13, CookiePriorityToDBCookiePriority(po->cc().Priority())); 13, CookieSameSiteToDBCookieSameSite(po->cc().SameSite()));
add_smt.BindInt(14, static_cast<int>(po->cc().SourceScheme())); add_smt.BindInt(14, static_cast<int>(po->cc().SourceScheme()));
add_smt.BindInt(15, po->cc().SourcePort()); add_smt.BindInt(15, po->cc().SourcePort());
add_smt.BindBool(16, po->cc().IsSameParty()); add_smt.BindBool(16, po->cc().IsSameParty());
......
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