Add ICU message format support
[chromium-blink-merge.git] / sandbox / win / src / named_pipe_dispatcher.cc
blob6bf982a9424e8b15657ba26ff12f35dc03ec4880
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "sandbox/win/src/named_pipe_dispatcher.h"
7 #include "base/basictypes.h"
8 #include "base/strings/string_split.h"
10 #include "sandbox/win/src/crosscall_client.h"
11 #include "sandbox/win/src/interception.h"
12 #include "sandbox/win/src/interceptors.h"
13 #include "sandbox/win/src/ipc_tags.h"
14 #include "sandbox/win/src/named_pipe_interception.h"
15 #include "sandbox/win/src/named_pipe_policy.h"
16 #include "sandbox/win/src/policy_broker.h"
17 #include "sandbox/win/src/policy_params.h"
18 #include "sandbox/win/src/sandbox.h"
21 namespace sandbox {
23 NamedPipeDispatcher::NamedPipeDispatcher(PolicyBase* policy_base)
24 : policy_base_(policy_base) {
25 static const IPCCall create_params = {
26 {IPC_CREATENAMEDPIPEW_TAG,
27 {WCHAR_TYPE,
28 UINT32_TYPE,
29 UINT32_TYPE,
30 UINT32_TYPE,
31 UINT32_TYPE,
32 UINT32_TYPE,
33 UINT32_TYPE}},
34 reinterpret_cast<CallbackGeneric>(&NamedPipeDispatcher::CreateNamedPipe)};
36 ipc_calls_.push_back(create_params);
39 bool NamedPipeDispatcher::SetupService(InterceptionManager* manager,
40 int service) {
41 if (IPC_CREATENAMEDPIPEW_TAG == service)
42 return INTERCEPT_EAT(manager, kKerneldllName, CreateNamedPipeW,
43 CREATE_NAMED_PIPE_ID, 36);
45 return false;
48 bool NamedPipeDispatcher::CreateNamedPipe(IPCInfo* ipc,
49 base::string16* name,
50 uint32 open_mode,
51 uint32 pipe_mode,
52 uint32 max_instances,
53 uint32 out_buffer_size,
54 uint32 in_buffer_size,
55 uint32 default_timeout) {
56 ipc->return_info.win32_result = ERROR_ACCESS_DENIED;
57 ipc->return_info.handle = INVALID_HANDLE_VALUE;
59 std::vector<base::string16> paths;
60 std::vector<base::string16> innerpaths;
61 base::SplitString(*name, '/', &paths);
63 for (std::vector<base::string16>::const_iterator iter = paths.begin();
64 iter != paths.end(); ++iter) {
65 base::SplitString(*iter, '\\', &innerpaths);
66 for (std::vector<base::string16>::const_iterator iter2 = innerpaths.begin();
67 iter2 != innerpaths.end(); ++iter2) {
68 if (*iter2 == L"..")
69 return true;
73 const wchar_t* pipe_name = name->c_str();
74 CountedParameterSet<NameBased> params;
75 params[NameBased::NAME] = ParamPickerMake(pipe_name);
77 EvalResult eval = policy_base_->EvalPolicy(IPC_CREATENAMEDPIPEW_TAG,
78 params.GetBase());
80 // "For file I/O, the "\\?\" prefix to a path string tells the Windows APIs to
81 // disable all string parsing and to send the string that follows it straight
82 // to the file system."
83 // http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx
84 // This ensures even if there is a path traversal in the pipe name, and it is
85 // able to get past the checks above, it will still not be allowed to escape
86 // our whitelisted namespace.
87 if (name->compare(0, 4, L"\\\\.\\") == 0)
88 name->replace(0, 4, L"\\\\\?\\");
90 HANDLE pipe;
91 DWORD ret = NamedPipePolicy::CreateNamedPipeAction(eval, *ipc->client_info,
92 *name, open_mode,
93 pipe_mode, max_instances,
94 out_buffer_size,
95 in_buffer_size,
96 default_timeout, &pipe);
98 ipc->return_info.win32_result = ret;
99 ipc->return_info.handle = pipe;
100 return true;
103 } // namespace sandbox