0

sqlite: Add NULL check for db file path

In Database::DbPath(), sometimes crash happens due to NULL pointer
being cast to base::StringPiece. According to the SQL documentation
for sqlite3_db_filename, db path can be NULL. So there should be
a NULL check to prevent this crash scenario. This CL adds the
null check.

Bug: 1275513
Change-Id: I5e549d04969a32b0892f4e31db77cf3db413c08f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3308486
Reviewed-by: Chris Mumford <cmumford@google.com>
Commit-Queue: Aditi Singh <a20.singh@samsung.com>
Cr-Commit-Position: refs/heads/main@{#949941}
This commit is contained in:
a20.singh
2021-12-09 05:47:24 +00:00
committed by Chromium LUCI CQ
parent c9a3bec6c5
commit 0325ddce2b

@ -452,6 +452,8 @@ base::FilePath Database::DbPath() const {
return base::FilePath();
const char* path = sqlite3_db_filename(db_, "main");
if (!path)
return base::FilePath();
const base::StringPiece db_path(path);
#if defined(OS_WIN)
return base::FilePath(base::UTF8ToWide(db_path));