@@ -295,9 +295,14 @@ void ExceptionHandlerServer::InitializeWithInheritedDataForInitialClient(
295295
296296 first_pipe_instance_.reset (initial_client_data.first_pipe_instance ());
297297
298- // TODO(scottmg): Vista+. Might need to pass through or possibly find an Nt*.
299- auto data = base::HeapArray<uint8_t >::Uninit (sizeof (wchar_t ) * _MAX_PATH +
300- sizeof (FILE_NAME_INFO));
298+ // Allocate buffer for FILE_NAME_INFO with maximum pipe name length.
299+ // According to Windows documentation, pipe name strings are limited to 256
300+ // characters: https://learn.microsoft.com/en-us/windows/win32/ipc/pipe-names
301+ // FILE_NAME_INFO has a flexible array member (FileName) and provides an
302+ // explicit FileNameLength field, so no null terminator is needed.
303+ constexpr size_t kMaxPipeNameChars = 256 ;
304+ auto data = base::HeapArray<uint8_t >::Uninit (
305+ sizeof (FILE_NAME_INFO) + sizeof (wchar_t ) * kMaxPipeNameChars );
301306 if (!GetFileInformationByHandleEx (first_pipe_instance_.get (),
302307 FileNameInfo,
303308 data.data (),
@@ -414,6 +419,70 @@ void ExceptionHandlerServer::Stop() {
414419 PostQueuedCompletionStatus (port_.get (), 0 , 0 , nullptr );
415420}
416421
422+ static void HandleAddAttachmentV2 (
423+ const internal::PipeServiceContext& service_context,
424+ const ClientToServerMessage& message) {
425+ const uint32_t path_length_bytes = message.attachment_v2 .path_length_bytes ;
426+
427+ if (path_length_bytes == 0 || path_length_bytes > kMaxPathBytes ) {
428+ LOG (ERROR) << " Invalid path length: " << path_length_bytes;
429+ return ;
430+ }
431+
432+ if (path_length_bytes % sizeof (wchar_t ) != 0 ) {
433+ LOG (ERROR) << " Invalid path length: not aligned to wchar_t boundary" ;
434+ return ;
435+ }
436+
437+ auto path_buffer =
438+ base::HeapArray<wchar_t >::Uninit (path_length_bytes / sizeof (wchar_t ));
439+
440+ if (!LoggingReadFileExactly (
441+ service_context.pipe (), path_buffer.data (), path_length_bytes)) {
442+ LOG (ERROR) << " Failed to read attachment path" ;
443+ return ;
444+ }
445+
446+ path_buffer[path_buffer.size () - 1 ] = L' \0 ' ;
447+
448+ ServerToClientMessage response = {};
449+ service_context.delegate ()->ExceptionHandlerServerAttachmentAdded (
450+ base::FilePath (std::wstring (path_buffer.data ())));
451+ LoggingWriteFile (service_context.pipe (), &response, sizeof (response));
452+ }
453+
454+ static void HandleRemoveAttachmentV2 (
455+ const internal::PipeServiceContext& service_context,
456+ const ClientToServerMessage& message) {
457+ const uint32_t path_length_bytes = message.attachment_v2 .path_length_bytes ;
458+
459+ if (path_length_bytes == 0 || path_length_bytes > kMaxPathBytes ) {
460+ LOG (ERROR) << " Invalid path length: " << path_length_bytes;
461+ return ;
462+ }
463+
464+ if (path_length_bytes % sizeof (wchar_t ) != 0 ) {
465+ LOG (ERROR) << " Invalid path length: not aligned to wchar_t boundary" ;
466+ return ;
467+ }
468+
469+ auto path_buffer =
470+ base::HeapArray<wchar_t >::Uninit (path_length_bytes / sizeof (wchar_t ));
471+
472+ if (!LoggingReadFileExactly (
473+ service_context.pipe (), path_buffer.data (), path_length_bytes)) {
474+ LOG (ERROR) << " Failed to read attachment path" ;
475+ return ;
476+ }
477+
478+ path_buffer[path_buffer.size () - 1 ] = L' \0 ' ;
479+
480+ ServerToClientMessage response = {};
481+ service_context.delegate ()->ExceptionHandlerServerAttachmentRemoved (
482+ base::FilePath (std::wstring (path_buffer.data ())));
483+ LoggingWriteFile (service_context.pipe (), &response, sizeof (response));
484+ }
485+
417486// This function must be called with service_context.pipe() already connected to
418487// a client pipe. It exchanges data with the client and adds a ClientData record
419488// to service_context->clients().
@@ -475,6 +544,16 @@ bool ExceptionHandlerServer::ServiceClientConnection(
475544 return false ;
476545 }
477546
547+ case ClientToServerMessage::kAddAttachmentV2 : {
548+ HandleAddAttachmentV2 (service_context, message);
549+ return false ;
550+ }
551+
552+ case ClientToServerMessage::kRemoveAttachmentV2 : {
553+ HandleRemoveAttachmentV2 (service_context, message);
554+ return false ;
555+ }
556+
478557 default :
479558 LOG (ERROR) << " unhandled message type: " << message.type ;
480559 return false ;
0 commit comments