@@ -432,9 +432,12 @@ sentry__process_crash(const sentry_options_t *options, sentry_crash_ipc_t *ipc)
432432 strncpy_s (ctx -> minidump_path , sizeof (ctx -> minidump_path ), minidump_path ,
433433 _TRUNCATE );
434434#else
435- strncpy (
436- ctx -> minidump_path , minidump_path , sizeof (ctx -> minidump_path ) - 1 );
437- ctx -> minidump_path [sizeof (ctx -> minidump_path ) - 1 ] = '\0' ;
435+ size_t path_len = strlen (minidump_path );
436+ size_t copy_len = path_len < sizeof (ctx -> minidump_path ) - 1
437+ ? path_len
438+ : sizeof (ctx -> minidump_path ) - 1 ;
439+ memcpy (ctx -> minidump_path , minidump_path , copy_len );
440+ ctx -> minidump_path [copy_len ] = '\0' ;
438441#endif
439442
440443 // Get event file path from context
@@ -509,13 +512,25 @@ sentry__process_crash(const sentry_options_t *options, sentry_crash_ipc_t *ipc)
509512 SENTRY_DEBUG ("Reading envelope file back" );
510513
511514 // Check if file exists and get size
515+ #if defined(SENTRY_PLATFORM_WINDOWS )
516+ wchar_t * wenvelope_path = sentry__string_to_wstr (envelope_path );
517+ struct _stat64 st ;
518+ if (wenvelope_path && _wstat64 (wenvelope_path , & st ) == 0 ) {
519+ SENTRY_DEBUGF (
520+ "Envelope file exists, size=%lld bytes" , (long long )st .st_size );
521+ } else {
522+ SENTRY_WARNF ("Envelope file stat failed: %s" , strerror (errno ));
523+ }
524+ sentry_free (wenvelope_path );
525+ #else
512526 struct stat st ;
513527 if (stat (envelope_path , & st ) == 0 ) {
514528 SENTRY_DEBUGF (
515529 "Envelope file exists, size=%ld bytes" , (long )st .st_size );
516530 } else {
517531 SENTRY_WARNF ("Envelope file stat failed: %s" , strerror (errno ));
518532 }
533+ #endif
519534
520535 sentry_path_t * env_path = sentry__path_from_str (envelope_path );
521536 if (!env_path ) {
@@ -548,7 +563,11 @@ sentry__process_crash(const sentry_options_t *options, sentry_crash_ipc_t *ipc)
548563#if defined(SENTRY_PLATFORM_UNIX )
549564 unlink (envelope_path );
550565#elif defined(SENTRY_PLATFORM_WINDOWS )
551- _unlink (envelope_path );
566+ wchar_t * wenvelope_unlink = sentry__string_to_wstr (envelope_path );
567+ if (wenvelope_unlink ) {
568+ _wunlink (wenvelope_unlink );
569+ sentry_free (wenvelope_unlink );
570+ }
552571#endif
553572
554573 cleanup :
@@ -709,30 +728,47 @@ sentry__crash_daemon_main(pid_t app_pid, uint64_t app_tid, HANDLE event_handle,
709728 char log_path [SENTRY_CRASH_MAX_PATH ];
710729 FILE * log_file = NULL ;
711730 uint32_t id = (uint32_t )((app_pid ^ (app_tid & 0xFFFFFFFF )) & 0xFFFFFFFF );
731+
732+ #if defined(SENTRY_PLATFORM_WINDOWS )
733+ // On Windows, convert UTF-8 path to wide characters for proper file
734+ // handling
735+ int log_path_len = snprintf (log_path , sizeof (log_path ),
736+ "%s\\sentry-daemon-%08x.log" , ipc -> shmem -> database_path , id );
737+
738+ if (log_path_len > 0 && log_path_len < (int )sizeof (log_path )) {
739+ wchar_t * wlog_path = sentry__string_to_wstr (log_path );
740+ if (wlog_path ) {
741+ log_file = _wfopen (wlog_path , L"w" );
742+ sentry_free (wlog_path );
743+ }
744+ }
745+ #else
712746 int log_path_len = snprintf (log_path , sizeof (log_path ),
713747 "%s/sentry-daemon-%08x.log" , ipc -> shmem -> database_path , id );
714748
715749 if (log_path_len > 0 && log_path_len < (int )sizeof (log_path )) {
716750 log_file = fopen (log_path , "w" );
717- if (log_file ) {
718- // Disable buffering for immediate writes
719- setvbuf (log_file , NULL , _IONBF , 0 );
720-
721- // Set up Sentry logger to write to file
722- // Use log level from parent's debug setting
723- sentry_level_t log_level = ipc -> shmem -> debug_enabled
724- ? SENTRY_LEVEL_DEBUG
725- : SENTRY_LEVEL_INFO ;
726- sentry_logger_t file_logger = { .logger_func = daemon_file_logger ,
727- .logger_data = log_file ,
728- .logger_level = log_level };
729- sentry__logger_set_global (file_logger );
730- sentry__logger_enable ();
731-
732- SENTRY_DEBUG ("=== Daemon starting ===" );
733- SENTRY_DEBUGF ("App PID: %lu" , (unsigned long )app_pid );
734- SENTRY_DEBUGF ("Database path: %s" , ipc -> shmem -> database_path );
735- }
751+ }
752+ #endif
753+
754+ if (log_file ) {
755+ // Disable buffering for immediate writes
756+ setvbuf (log_file , NULL , _IONBF , 0 );
757+
758+ // Set up Sentry logger to write to file
759+ // Use log level from parent's debug setting
760+ sentry_level_t log_level = ipc -> shmem -> debug_enabled
761+ ? SENTRY_LEVEL_DEBUG
762+ : SENTRY_LEVEL_INFO ;
763+ sentry_logger_t file_logger = { .logger_func = daemon_file_logger ,
764+ .logger_data = log_file ,
765+ .logger_level = log_level };
766+ sentry__logger_set_global (file_logger );
767+ sentry__logger_enable ();
768+
769+ SENTRY_DEBUG ("=== Daemon starting ===" );
770+ SENTRY_DEBUGF ("App PID: %lu" , (unsigned long )app_pid );
771+ SENTRY_DEBUGF ("Database path: %s" , ipc -> shmem -> database_path );
736772 }
737773
738774#if defined(SENTRY_PLATFORM_UNIX )
0 commit comments