diff options
author | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-23 21:57:10 +0000 |
---|---|---|
committer | nsylvain@chromium.org <nsylvain@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-23 21:57:10 +0000 |
commit | e26092ee0313c209ecfc13adf4015d55a4eb38db (patch) | |
tree | 7d339472915c816af4b06096ba35eb6d5f1bbd2b /sandbox/src | |
parent | 3b296845029d75743c4c434486cc55e5df196687 (diff) | |
download | chromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.zip chromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.tar.gz chromium_src-e26092ee0313c209ecfc13adf4015d55a4eb38db.tar.bz2 |
Move a function from controller.cc to sandbox_utils.cc in
preparation for the refactoring.
Review URL: http://codereview.chromium.org/16225
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/src')
-rw-r--r-- | sandbox/src/Wow64.cc | 1 | ||||
-rw-r--r-- | sandbox/src/broker_services.cc | 3 | ||||
-rw-r--r-- | sandbox/src/file_policy_test.cc | 2 | ||||
-rw-r--r-- | sandbox/src/filesystem_policy.cc | 2 | ||||
-rw-r--r-- | sandbox/src/process_policy_test.cc | 37 | ||||
-rw-r--r-- | sandbox/src/registry_dispatcher.cc | 2 | ||||
-rw-r--r-- | sandbox/src/registry_policy.cc | 2 | ||||
-rw-r--r-- | sandbox/src/registry_policy_test.cc | 2 | ||||
-rw-r--r-- | sandbox/src/restricted_token_utils.cc | 2 | ||||
-rw-r--r-- | sandbox/src/sandbox_utils.cc | 17 | ||||
-rw-r--r-- | sandbox/src/sandbox_utils.h | 14 | ||||
-rw-r--r-- | sandbox/src/service_resolver.cc | 1 | ||||
-rw-r--r-- | sandbox/src/sharedmem_ipc_server.cc | 3 | ||||
-rw-r--r-- | sandbox/src/sync_policy_test.cc | 2 | ||||
-rw-r--r-- | sandbox/src/unload_dll_test.cc | 2 |
15 files changed, 49 insertions, 43 deletions
diff --git a/sandbox/src/Wow64.cc b/sandbox/src/Wow64.cc index c8a605a..ce2c5a7 100644 --- a/sandbox/src/Wow64.cc +++ b/sandbox/src/Wow64.cc @@ -7,6 +7,7 @@ #include <sstream> #include "base/logging.h" +#include "base/scoped_ptr.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/target_process.h" diff --git a/sandbox/src/broker_services.cc b/sandbox/src/broker_services.cc index ab8bdd6..7f07ade 100644 --- a/sandbox/src/broker_services.cc +++ b/sandbox/src/broker_services.cc @@ -90,7 +90,8 @@ BrokerServicesBase::~BrokerServicesBase() { ::CloseHandle(job_port_); if (WAIT_TIMEOUT == ::WaitForSingleObject(job_thread_, 1000)) { - NOTREACHED() << "Cannot clean broker services"; + // Cannot clean broker services. + NOTREACHED(); return; } diff --git a/sandbox/src/file_policy_test.cc b/sandbox/src/file_policy_test.cc index e4d1985..aee0285 100644 --- a/sandbox/src/file_policy_test.cc +++ b/sandbox/src/file_policy_test.cc @@ -7,7 +7,7 @@ #include <windows.h> #include <winioctl.h> -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "testing/gtest/include/gtest/gtest.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_factory.h" diff --git a/sandbox/src/filesystem_policy.cc b/sandbox/src/filesystem_policy.cc index fa8e53c..7915084 100644 --- a/sandbox/src/filesystem_policy.cc +++ b/sandbox/src/filesystem_policy.cc @@ -7,7 +7,7 @@ #include "sandbox/src/filesystem_policy.h" #include "base/logging.h" -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "sandbox/src/ipc_tags.h" #include "sandbox/src/policy_engine_opcodes.h" #include "sandbox/src/policy_params.h" diff --git a/sandbox/src/process_policy_test.cc b/sandbox/src/process_policy_test.cc index a156c6e..f3011b7 100644 --- a/sandbox/src/process_policy_test.cc +++ b/sandbox/src/process_policy_test.cc @@ -5,44 +5,16 @@ #include <string> #include <memory> -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "testing/gtest/include/gtest/gtest.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_policy.h" #include "sandbox/src/sandbox_factory.h" +#include "sandbox/src/sandbox_utils.h" #include "sandbox/tests/common/controller.h" namespace { -// The next 2 functions are copied from base\string_util.h and have been -// slighty modified because we don't want to depend on ICU. -template <class char_type> -inline char_type* WriteInto( - std::basic_string<char_type, std::char_traits<char_type>, - std::allocator<char_type> >* str, - size_t length_including_null) { - str->reserve(length_including_null); - str->resize(length_including_null - 1); - return &((*str)[0]); -} - -std::string WideToMultiByte(const std::wstring& wide) { - if (wide.length() == 0) - return std::string(); - - // compute the length of the buffer we'll need - int charcount = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, - NULL, 0, NULL, NULL); - if (charcount == 0) - return std::string(); - - std::string mb; - WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, - WriteInto(&mb, charcount), charcount, NULL, NULL); - - return mb; -} - // While the shell API provides better calls than this home brew function // we use GetSystemWindowsDirectoryW which does not query the registry so // it is safe to use after revert. @@ -93,9 +65,10 @@ sandbox::SboxTestResult CreateProcessHelper(const std::wstring &exe, STARTUPINFOA sia = {sizeof(sia)}; sandbox::SboxTestResult ret2 = sandbox::SBOX_TEST_FAILED; + std::string narrow_cmd_line = sandbox::WideToMultiByte(cmd_line); if (!::CreateProcessA( - exe_name ? WideToMultiByte(exe_name).c_str() : NULL, - cmd_line ? const_cast<char*>(WideToMultiByte(cmd_line).c_str()) : NULL, + exe_name ? sandbox::WideToMultiByte(exe_name).c_str() : NULL, + cmd_line ? const_cast<char*>(narrow_cmd_line.c_str()) : NULL, NULL, NULL, FALSE, 0, NULL, NULL, &sia, &pi)) { DWORD last_error = GetLastError(); if ((ERROR_NOT_ENOUGH_QUOTA == last_error) || diff --git a/sandbox/src/registry_dispatcher.cc b/sandbox/src/registry_dispatcher.cc index c941d25..babf455 100644 --- a/sandbox/src/registry_dispatcher.cc +++ b/sandbox/src/registry_dispatcher.cc @@ -5,7 +5,7 @@ #include "sandbox/src/registry_dispatcher.h" #include "base/logging.h" -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "sandbox/src/crosscall_client.h" #include "sandbox/src/interception.h" #include "sandbox/src/ipc_tags.h" diff --git a/sandbox/src/registry_policy.cc b/sandbox/src/registry_policy.cc index 425ceed..f884ad3 100644 --- a/sandbox/src/registry_policy.cc +++ b/sandbox/src/registry_policy.cc @@ -7,7 +7,7 @@ #include "sandbox/src/registry_policy.h" #include "base/logging.h" -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "sandbox/src/ipc_tags.h" #include "sandbox/src/policy_engine_opcodes.h" #include "sandbox/src/policy_params.h" diff --git a/sandbox/src/registry_policy_test.cc b/sandbox/src/registry_policy_test.cc index 5282633..6331481 100644 --- a/sandbox/src/registry_policy_test.cc +++ b/sandbox/src/registry_policy_test.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/scoped_handle.h" - #include <shlobj.h> #include "testing/gtest/include/gtest/gtest.h" diff --git a/sandbox/src/restricted_token_utils.cc b/sandbox/src/restricted_token_utils.cc index 97c8630..8d77f75 100644 --- a/sandbox/src/restricted_token_utils.cc +++ b/sandbox/src/restricted_token_utils.cc @@ -9,7 +9,7 @@ #include "sandbox/src/restricted_token_utils.h" #include "base/logging.h" -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "base/win_util.h" #include "sandbox/src/job.h" #include "sandbox/src/restricted_token.h" diff --git a/sandbox/src/sandbox_utils.cc b/sandbox/src/sandbox_utils.cc index 315ba62..5c2688e 100644 --- a/sandbox/src/sandbox_utils.cc +++ b/sandbox/src/sandbox_utils.cc @@ -98,5 +98,22 @@ void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, InitializeObjectAttributes(obj_attr, uni_name, attributes, root, NULL); } +std::string WideToMultiByte(const std::wstring& wide) { + if (wide.length() == 0) + return std::string(); + + // compute the length of the buffer we'll need + int charcount = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, + NULL, 0, NULL, NULL); + if (charcount == 0) + return std::string(); + + std::string mb; + WideCharToMultiByte(CP_UTF8, 0, wide.c_str(), -1, + WriteInto(&mb, charcount), charcount, NULL, NULL); + + return mb; +} + }; // namespace sandbox diff --git a/sandbox/src/sandbox_utils.h b/sandbox/src/sandbox_utils.h index ad158bf..ffb5c3d 100644 --- a/sandbox/src/sandbox_utils.h +++ b/sandbox/src/sandbox_utils.h @@ -33,6 +33,20 @@ bool IsXPSP2OrLater(); void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, OBJECT_ATTRIBUTES* obj_attr, UNICODE_STRING* uni_name); +// The next 2 functions are copied from base\string_util.h and have been +// slighty modified because we don't want to depend on ICU. +template <class char_type> +inline char_type* WriteInto( + std::basic_string<char_type, std::char_traits<char_type>, + std::allocator<char_type> >* str, + size_t length_including_null) { + str->reserve(length_including_null); + str->resize(length_including_null - 1); + return &((*str)[0]); +} + +std::string WideToMultiByte(const std::wstring& wide); + }; // namespace sandbox #endif // SANDBOX_SRC_SANDBOX_UTILS_H__ diff --git a/sandbox/src/service_resolver.cc b/sandbox/src/service_resolver.cc index 6491138..c7ebb58 100644 --- a/sandbox/src/service_resolver.cc +++ b/sandbox/src/service_resolver.cc @@ -5,6 +5,7 @@ #include "sandbox/src/service_resolver.h" #include "base/logging.h" +#include "base/scoped_ptr.h" #include "sandbox/src/pe_image.h" #include "sandbox/src/sandbox_types.h" #include "sandbox/src/sandbox_utils.h" diff --git a/sandbox/src/sharedmem_ipc_server.cc b/sandbox/src/sharedmem_ipc_server.cc index 6434132..a6ede86 100644 --- a/sandbox/src/sharedmem_ipc_server.cc +++ b/sandbox/src/sharedmem_ipc_server.cc @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "base/logging.h" +#include "base/scoped_ptr.h" #include "sandbox/src/sharedmem_ipc_server.h" #include "sandbox/src/sharedmem_ipc_client.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_types.h" #include "sandbox/src/crosscall_params.h" #include "sandbox/src/crosscall_server.h" -#include "base/logging.h" namespace sandbox { diff --git a/sandbox/src/sync_policy_test.cc b/sandbox/src/sync_policy_test.cc index 6411c31..b6b3c14 100644 --- a/sandbox/src/sync_policy_test.cc +++ b/sandbox/src/sync_policy_test.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "testing/gtest/include/gtest/gtest.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_policy.h" diff --git a/sandbox/src/unload_dll_test.cc b/sandbox/src/unload_dll_test.cc index 19097fd..55994b7 100644 --- a/sandbox/src/unload_dll_test.cc +++ b/sandbox/src/unload_dll_test.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/scoped_handle.h" +#include "base/scoped_handle_win.h" #include "testing/gtest/include/gtest/gtest.h" #include "sandbox/src/sandbox.h" #include "sandbox/src/sandbox_factory.h" |