Skip to content
Permalink
Browse files
Add null checks for connection in UniqueIDBDatabaseTransaction and Un…
…iqueIDBDatabase

https://bugs.webkit.org/show_bug.cgi?id=241792
rdar://95011134

Reviewed by Youenn Fablet.

* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.cpp:
(WebCore::IDBServer::UniqueIDBDatabase::startVersionChangeTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::clearTransactionsOnConnection):
(WebCore::IDBServer::UniqueIDBDatabase::openDBRequestCancelled):
(WebCore::IDBServer::UniqueIDBDatabase::commitTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::abortTransaction):
(WebCore::IDBServer::UniqueIDBDatabase::immediateClose):
* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.cpp:
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::UniqueIDBDatabaseTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::~UniqueIDBDatabaseTransaction):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::databaseConnection const):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::abort):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::abortWithoutCallback):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::database const):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::commit):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::createObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::renameObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::clearObjectStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::createIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::renameIndex):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::putOrAdd):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getRecord):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getAllRecords):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::getCount):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::deleteRecord):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::openCursor):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::iterateCursor):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::objectStoreIdentifiers):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::didActivateInBackingStore):
(WebCore::IDBServer::UniqueIDBDatabaseTransaction::databaseConnection): Deleted.
* Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabaseTransaction.h:
* Source/WebCore/Modules/indexeddb/shared/IDBResultData.cpp:
(WebCore::IDBResultData::openDatabaseUpgradeNeeded):
* Source/WebCore/Modules/indexeddb/shared/IDBResultData.h:

Canonical link: https://commits.webkit.org/251705@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295700 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
szewai committed Jun 21, 2022
1 parent 35d7fb2 commit 0ea60aca3e447b5a223bdad51370480ad4d149e5
Showing 5 changed files with 188 additions and 108 deletions.
@@ -446,7 +446,7 @@ void UniqueIDBDatabase::startVersionChangeTransaction()
if (error.isNull()) {
addOpenDatabaseConnection(*m_versionChangeDatabaseConnection);
m_databaseInfo->setVersion(versionChangeTransactionInfo.newVersion());
result = IDBResultData::openDatabaseUpgradeNeeded(operation->requestData().requestIdentifier(), *m_versionChangeTransaction);
result = IDBResultData::openDatabaseUpgradeNeeded(operation->requestData().requestIdentifier(), *m_versionChangeTransaction, *m_versionChangeDatabaseConnection);
operation->connection().didOpenDatabase(result);
} else {
m_versionChangeDatabaseConnection->abortTransactionWithoutCallback(*m_versionChangeTransaction);
@@ -512,7 +512,7 @@ void UniqueIDBDatabase::clearTransactionsOnConnection(UniqueIDBDatabaseConnectio
Deque<RefPtr<UniqueIDBDatabaseTransaction>> pendingTransactions;
while (!m_pendingTransactions.isEmpty()) {
auto transaction = m_pendingTransactions.takeFirst();
if (&transaction->databaseConnection() != &connection)
if (transaction->databaseConnection() != &connection)
pendingTransactions.append(WTFMove(transaction));
else
connection.deleteTransaction(*transaction);
@@ -522,7 +522,7 @@ void UniqueIDBDatabase::clearTransactionsOnConnection(UniqueIDBDatabaseConnectio

Deque<RefPtr<UniqueIDBDatabaseTransaction>> transactionsToAbort;
for (auto& transaction : m_inProgressTransactions.values()) {
if (&transaction->databaseConnection() == &connection)
if (transaction->databaseConnection() == &connection)
transactionsToAbort.append(transaction);
}
for (auto& transaction : transactionsToAbort)
@@ -557,8 +557,7 @@ void UniqueIDBDatabase::openDBRequestCancelled(const IDBResourceIdentifier& requ
m_currentOpenDBRequest = nullptr;

if (m_versionChangeDatabaseConnection && m_versionChangeDatabaseConnection->openRequestIdentifier() == requestIdentifier) {
ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->databaseConnection().openRequestIdentifier() == requestIdentifier);
ASSERT(!m_versionChangeTransaction || &m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
ASSERT(!m_versionChangeTransaction || m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);

connectionClosedFromClient(*m_versionChangeDatabaseConnection);
}
@@ -1135,14 +1134,14 @@ void UniqueIDBDatabase::commitTransaction(UniqueIDBDatabaseTransaction& transact
}

ASSERT(spaceCheckResult == SpaceCheckResult::Pass);
ASSERT(transaction.databaseConnection().database() == this);
ASSERT(transaction.database() == this);

if (!m_backingStore)
return callback(IDBError { InvalidStateError, "Backing store is closed"_s });

auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier());
if (!takenTransaction) {
if (!m_openDatabaseConnections.contains(&transaction.databaseConnection()))
if (transaction.databaseConnection() && !m_openDatabaseConnections.contains(transaction.databaseConnection()))
return;

callback(IDBError { UnknownError, "Attempt to commit transaction that is not running"_s });
@@ -1174,11 +1173,11 @@ void UniqueIDBDatabase::abortTransaction(UniqueIDBDatabaseTransaction& transacti
}

ASSERT(spaceCheckResult == SpaceCheckResult::Pass);
ASSERT(transaction.databaseConnection().database() == this);
ASSERT(transaction.database() == this);

auto takenTransaction = m_inProgressTransactions.take(transaction.info().identifier());
if (!takenTransaction) {
if (!m_openDatabaseConnections.contains(&transaction.databaseConnection()))
if (!m_openDatabaseConnections.contains(transaction.databaseConnection()))
return;

callback(IDBError { UnknownError, "Attempt to abort transaction that is not running"_s });
@@ -1195,7 +1194,7 @@ void UniqueIDBDatabase::abortTransaction(UniqueIDBDatabaseTransaction& transacti
auto transactionIdentifier = transaction.info().identifier();
if (m_versionChangeTransaction && m_versionChangeTransaction->info().identifier() == transactionIdentifier) {
ASSERT(m_versionChangeTransaction == &transaction);
ASSERT(!m_versionChangeDatabaseConnection || &m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
ASSERT(!m_versionChangeDatabaseConnection || m_versionChangeTransaction->databaseConnection() == m_versionChangeDatabaseConnection);
ASSERT(m_versionChangeTransaction->originalDatabaseInfo());
m_databaseInfo = makeUnique<IDBDatabaseInfo>(*m_versionChangeTransaction->originalDatabaseInfo());
}
@@ -1428,8 +1427,10 @@ void UniqueIDBDatabase::immediateClose()
// Error out all transactions.
// Pending transactions must be cleared before in-progress transactions,
// or they may get started right away after aborting in-progress transactions.
for (auto& transaction : m_pendingTransactions)
transaction->databaseConnection().deleteTransaction(*transaction);
for (auto& transaction : m_pendingTransactions) {
if (auto* databaseConnection = transaction->databaseConnection())
databaseConnection->deleteTransaction(*transaction);
}
m_pendingTransactions.clear();

for (auto& identifier : copyToVector(m_inProgressTransactions.keys()))

0 comments on commit 0ea60ac

Please sign in to comment.