Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Unified Diff: webkit/fileapi/file_system_directory_database.cc

Issue 11308360: Merge 170159 (Closed) Base URL: svn://svn.chromium.org/chrome/branches/1312/src/
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/fileapi/file_system_directory_database.h ('k') | webkit/fileapi/sandbox_mount_point_provider.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/fileapi/file_system_directory_database.cc
===================================================================
--- webkit/fileapi/file_system_directory_database.cc (revision 171066)
+++ webkit/fileapi/file_system_directory_database.cc (working copy)
@@ -369,6 +369,27 @@
num_hierarchy_links_in_db_ == visited_links;
}
+// Returns true if the given |data_path| contains no parent references ("..")
+// and does not refer to special system files.
+// This is called in GetFileInfo, AddFileInfo and UpdateFileInfo to
+// ensure we're only dealing with valid data paths.
+bool VerifyDataPath(const FilePath& data_path) {
+ // |data_path| should not contain any ".." and should be a relative path
+ // (to the filesystem_data_directory_).
+ if (data_path.ReferencesParent() || data_path.IsAbsolute())
+ return false;
+ // See if it's not pointing to the special system paths.
+ const FilePath kExcludes[] = {
+ FilePath(kDirectoryDatabaseName),
+ FilePath(fileapi::FileSystemUsageCache::kUsageFileName),
+ };
+ for (size_t i = 0; i < arraysize(kExcludes); ++i) {
+ if (data_path == kExcludes[i] || kExcludes[i].IsParent(data_path))
+ return false;
+ }
+ return true;
+}
+
} // namespace
namespace fileapi {
@@ -461,8 +482,16 @@
leveldb::Status status =
db_->Get(leveldb::ReadOptions(), file_key, &file_data_string);
if (status.ok()) {
- return FileInfoFromPickle(
+ bool success = FileInfoFromPickle(
Pickle(file_data_string.data(), file_data_string.length()), info);
+ if (!success)
+ return false;
+ if (!VerifyDataPath(info->data_path)) {
+ LOG(ERROR) << "Resolved data path is invalid: "
+ << info->data_path.value();
+ return false;
+ }
+ return true;
}
// Special-case the root, for databases that haven't been initialized yet.
// Without this, a query for the root's file info, made before creating the
@@ -821,6 +850,10 @@
// This does very few safety checks!
bool FileSystemDirectoryDatabase::AddFileInfoHelper(
const FileInfo& info, FileId file_id, leveldb::WriteBatch* batch) {
+ if (!VerifyDataPath(info.data_path)) {
+ LOG(ERROR) << "Invalid data path is given: " << info.data_path.value();
+ return false;
+ }
std::string id_string = GetFileLookupKey(file_id);
if (!file_id) {
// The root directory doesn't need to be looked up by path from its parent.
« no previous file with comments | « webkit/fileapi/file_system_directory_database.h ('k') | webkit/fileapi/sandbox_mount_point_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698