summaryrefslogtreecommitdiffstats
path: root/base/file_util.cc
diff options
context:
space:
mode:
authorcevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 20:38:07 +0000
committercevans@chromium.org <cevans@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-06 20:38:07 +0000
commit3cd2c1c88d2646a3338cfa7888f06fe321061053 (patch)
tree679393e48439e0e302a9d6cc72ed57ba72cfd32c /base/file_util.cc
parent08fd501dabd531cc77f2bf458e6f7c3cdc2d8856 (diff)
downloadchromium_src-3cd2c1c88d2646a3338cfa7888f06fe321061053.zip
chromium_src-3cd2c1c88d2646a3338cfa7888f06fe321061053.tar.gz
chromium_src-3cd2c1c88d2646a3338cfa7888f06fe321061053.tar.bz2
Add path traversal protection to Move and CopyFile too.
These functions are used a lot in IPC receivers to manage storage. See http://src.chromium.org/viewvc/chrome?view=rev&revision=175642 Review URL: https://codereview.chromium.org/12223014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181045 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util.cc')
-rw-r--r--base/file_util.cc12
1 files changed, 12 insertions, 0 deletions
diff --git a/base/file_util.cc b/base/file_util.cc
index 7efb22b..07f2771 100644
--- a/base/file_util.cc
+++ b/base/file_util.cc
@@ -77,6 +77,18 @@ void InsertBeforeExtension(FilePath* path, const FilePath::StringType& suffix) {
value.insert(last_dot, suffix);
}
+bool Move(const FilePath& from_path, const FilePath& to_path) {
+ if (from_path.ReferencesParent() || to_path.ReferencesParent())
+ return false;
+ return MoveUnsafe(from_path, to_path);
+}
+
+bool CopyFile(const FilePath& from_path, const FilePath& to_path) {
+ if (from_path.ReferencesParent() || to_path.ReferencesParent())
+ return false;
+ return CopyFileUnsafe(from_path, to_path);
+}
+
bool ContentsEqual(const FilePath& filename1, const FilePath& filename2) {
// We open the file in binary format even if they are text files because
// we are just comparing that bytes are exactly same in both files and not