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

Side by Side Diff: util/win/exception_handler_server.cc

Issue 1451793002: Add RandomString() and its test, and use it everywhere it makes sense (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Fix tpyo Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « util/util_test.gyp ('k') | util/win/process_info_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Crashpad Authors. All rights reserved. 1 // Copyright 2015 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/win/exception_handler_server.h" 15 #include "util/win/exception_handler_server.h"
16 16
17 #include <sddl.h> 17 #include <sddl.h>
18 #include <string.h> 18 #include <string.h>
19 19
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/numerics/safe_conversions.h" 21 #include "base/numerics/safe_conversions.h"
22 #include "base/rand_util.h" 22 #include "base/rand_util.h"
23 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
24 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
25 #include "minidump/minidump_file_writer.h" 25 #include "minidump/minidump_file_writer.h"
26 #include "snapshot/crashpad_info_client_options.h" 26 #include "snapshot/crashpad_info_client_options.h"
27 #include "snapshot/win/process_snapshot_win.h" 27 #include "snapshot/win/process_snapshot_win.h"
28 #include "util/file/file_writer.h" 28 #include "util/file/file_writer.h"
29 #include "util/misc/random_string.h"
29 #include "util/misc/tri_state.h" 30 #include "util/misc/tri_state.h"
30 #include "util/misc/uuid.h" 31 #include "util/misc/uuid.h"
31 #include "util/win/get_function.h" 32 #include "util/win/get_function.h"
32 #include "util/win/handle.h" 33 #include "util/win/handle.h"
33 #include "util/win/registration_protocol_win.h" 34 #include "util/win/registration_protocol_win.h"
34 #include "util/win/scoped_local_alloc.h" 35 #include "util/win/scoped_local_alloc.h"
35 #include "util/win/xp_compat.h" 36 #include "util/win/xp_compat.h"
36 37
37 namespace crashpad { 38 namespace crashpad {
38 39
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 312 }
312 313
313 std::wstring ExceptionHandlerServer::CreatePipe() { 314 std::wstring ExceptionHandlerServer::CreatePipe() {
314 DCHECK(!first_pipe_instance_.is_valid()); 315 DCHECK(!first_pipe_instance_.is_valid());
315 316
316 int tries = 5; 317 int tries = 5;
317 std::string pipe_name_base = 318 std::string pipe_name_base =
318 base::StringPrintf("\\\\.\\pipe\\crashpad_%d_", GetCurrentProcessId()); 319 base::StringPrintf("\\\\.\\pipe\\crashpad_%d_", GetCurrentProcessId());
319 std::wstring pipe_name; 320 std::wstring pipe_name;
320 do { 321 do {
321 pipe_name = base::UTF8ToUTF16(pipe_name_base); 322 pipe_name = base::UTF8ToUTF16(pipe_name_base + RandomString());
322 for (int index = 0; index < 16; ++index) {
323 pipe_name.append(1, static_cast<wchar_t>(base::RandInt('A', 'Z')));
324 }
325 323
326 first_pipe_instance_.reset(CreateNamedPipeInstance(pipe_name, true)); 324 first_pipe_instance_.reset(CreateNamedPipeInstance(pipe_name, true));
327 325
328 // CreateNamedPipe() is documented as setting the error to 326 // CreateNamedPipe() is documented as setting the error to
329 // ERROR_ACCESS_DENIED if FILE_FLAG_FIRST_PIPE_INSTANCE is specified and the 327 // ERROR_ACCESS_DENIED if FILE_FLAG_FIRST_PIPE_INSTANCE is specified and the
330 // pipe name is already in use. However it may set the error to other codes 328 // pipe name is already in use. However it may set the error to other codes
331 // such as ERROR_PIPE_BUSY (if the pipe already exists and has reached its 329 // such as ERROR_PIPE_BUSY (if the pipe already exists and has reached its
332 // maximum instance count) or ERROR_INVALID_PARAMETER (if the pipe already 330 // maximum instance count) or ERROR_INVALID_PARAMETER (if the pipe already
333 // exists and its attributes differ from those specified to 331 // exists and its attributes differ from those specified to
334 // CreateNamedPipe()). Some of these errors may be ambiguous: for example, 332 // CreateNamedPipe()). Some of these errors may be ambiguous: for example,
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { 592 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) {
595 // This function is executed on the thread pool. 593 // This function is executed on the thread pool.
596 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); 594 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx);
597 base::AutoLock lock(*client->lock()); 595 base::AutoLock lock(*client->lock());
598 596
599 // Post back to the main thread to have it delete this client record. 597 // Post back to the main thread to have it delete this client record.
600 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); 598 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr);
601 } 599 }
602 600
603 } // namespace crashpad 601 } // namespace crashpad
OLDNEW
« no previous file with comments | « util/util_test.gyp ('k') | util/win/process_info_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698