mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
LibWeb: Check weak pointer liveness in Database::for_key_and_name()
The database map stores GC::Weak<Database> entries. When the GC collects a Database, the weak pointer goes null but the map entry remains. The old code dereferenced the weak pointer without checking liveness, causing a null reference binding (UBSan). Fix this by checking ptr() before dereferencing, and cleaning up the stale map entry if the database was collected.
This commit is contained in:
committed by
Shannon Booth
parent
0c0250451a
commit
f6e755506d
Notes:
github-actions[bot]
2026-03-08 10:41:52 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/f6e755506d7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8319
@@ -86,8 +86,12 @@ RequestList& ConnectionQueueHandler::for_key_and_name(StorageAPI::StorageKey con
|
||||
Optional<Database&> Database::for_key_and_name(StorageAPI::StorageKey const& key, String const& name)
|
||||
{
|
||||
auto database_mapping = m_databases.ensure(key, [] { return HashMap<String, GC::Weak<Database>>(); });
|
||||
if (auto maybe_database = database_mapping.get(name); maybe_database.has_value())
|
||||
return *maybe_database.value();
|
||||
if (auto maybe_database = database_mapping.get(name); maybe_database.has_value()) {
|
||||
if (auto database = maybe_database.value().ptr())
|
||||
return *database;
|
||||
database_mapping.remove(name);
|
||||
m_databases.set(key, database_mapping);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user