diff options
author | sanga@chromium.org <sanga@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-17 16:41:53 +0000 |
---|---|---|
committer | sanga@chromium.org <sanga@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-08-17 16:41:53 +0000 |
commit | 6529b0ec599e083d54f9031cc37150ae93b368a2 (patch) | |
tree | 0056cadfd7a67df328634930b66794959c24add7 /ppapi/tests/test_file_ref.cc | |
parent | 2c144bceae0a0ec69aad3cbabe1f9c3f9692416b (diff) | |
download | chromium_src-6529b0ec599e083d54f9031cc37150ae93b368a2.zip chromium_src-6529b0ec599e083d54f9031cc37150ae93b368a2.tar.gz chromium_src-6529b0ec599e083d54f9031cc37150ae93b368a2.tar.bz2 |
Adding checks against directory traversal.
BUG= http://code.google.com/p/chromium/issues/detail?id=92751
TEST=ui_tests
Review URL: http://codereview.chromium.org/7631007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97144 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_file_ref.cc')
-rw-r--r-- | ppapi/tests/test_file_ref.cc | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/ppapi/tests/test_file_ref.cc b/ppapi/tests/test_file_ref.cc index a753b03..d6b3b36 100644 --- a/ppapi/tests/test_file_ref.cc +++ b/ppapi/tests/test_file_ref.cc @@ -5,6 +5,7 @@ #include "ppapi/tests/test_file_ref.h" #include <stdio.h> +#include <vector> #include "ppapi/c/pp_errors.h" #include "ppapi/c/ppb_file_io.h" @@ -44,6 +45,7 @@ bool TestFileRef::Init() { } void TestFileRef::RunTest() { + RUN_TEST_FORCEASYNC_AND_NOT(Create); RUN_TEST_FORCEASYNC_AND_NOT(GetFileSystemType); RUN_TEST_FORCEASYNC_AND_NOT(GetName); RUN_TEST_FORCEASYNC_AND_NOT(GetPath); @@ -54,6 +56,36 @@ void TestFileRef::RunTest() { RUN_TEST_FORCEASYNC_AND_NOT(RenameFileAndDirectory); } +std::string TestFileRef::TestCreate() { + std::vector<std::string> invalid_paths; + invalid_paths.push_back("invalid_path"); // no '/' at the first character + invalid_paths.push_back(""); // empty path + // The following are directory traversal checks + invalid_paths.push_back(".."); + invalid_paths.push_back("/../invalid_path"); + invalid_paths.push_back("/../../invalid_path"); + invalid_paths.push_back("/invalid/../../path"); + const size_t num_invalid_paths = invalid_paths.size(); + + pp::FileSystem file_system_pers( + instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); + pp::FileSystem file_system_temp( + instance_, PP_FILESYSTEMTYPE_LOCALTEMPORARY); + for (size_t j = 0; j < num_invalid_paths; ++j) { + pp::FileRef file_ref_pers(file_system_pers, invalid_paths[j].c_str()); + if (file_ref_pers.pp_resource() != 0) { + return "file_ref_pers expected to be invalid for path: " + + invalid_paths[j]; + } + pp::FileRef file_ref_temp(file_system_temp, invalid_paths[j].c_str()); + if (file_ref_temp.pp_resource() != 0) { + return "file_ref_temp expected to be invalid for path: " + + invalid_paths[j]; + } + } + PASS(); +} + std::string TestFileRef::TestGetFileSystemType() { pp::FileSystem file_system_pers( instance_, PP_FILESYSTEMTYPE_LOCALPERSISTENT); |