Skip to content

Commit 216b3cd

Browse files
committed
More fixes
1 parent 842c1e3 commit 216b3cd

4 files changed

Lines changed: 91 additions & 33 deletions

File tree

src/backends/native/minidump/sentry_minidump_windows.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# include "sentry.h"
1010
# include "sentry_logger.h"
1111
# include "sentry_minidump_writer.h"
12+
# include "sentry_string.h"
1213

1314
# pragma comment(lib, "dbghelp.lib")
1415

@@ -22,14 +23,22 @@ sentry__write_minidump(
2223
{
2324
SENTRY_DEBUGF("writing minidump to %s", output_path);
2425

25-
// Open output file
26-
HANDLE file_handle = CreateFileA(output_path, GENERIC_WRITE, 0, NULL,
26+
// Open output file - use wide character API for proper UTF-8 path support
27+
wchar_t *woutput_path = sentry__string_to_wstr(output_path);
28+
if (!woutput_path) {
29+
SENTRY_WARN("failed to convert minidump path to wide string");
30+
return -1;
31+
}
32+
33+
HANDLE file_handle = CreateFileW(woutput_path, GENERIC_WRITE, 0, NULL,
2734
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
2835

2936
if (file_handle == INVALID_HANDLE_VALUE) {
3037
SENTRY_WARNF("failed to create minidump file: %lu", GetLastError());
38+
sentry_free(woutput_path);
3139
return -1;
3240
}
41+
sentry_free(woutput_path);
3342

3443
// Open crashed process
3544
HANDLE process_handle
@@ -39,7 +48,11 @@ sentry__write_minidump(
3948
SENTRY_WARNF("failed to open process %lu: %lu", ctx->crashed_pid,
4049
GetLastError());
4150
CloseHandle(file_handle);
42-
DeleteFileA(output_path);
51+
wchar_t *wdelete_path = sentry__string_to_wstr(output_path);
52+
if (wdelete_path) {
53+
DeleteFileW(wdelete_path);
54+
sentry_free(wdelete_path);
55+
}
4356
return -1;
4457
}
4558

@@ -86,7 +99,11 @@ sentry__write_minidump(
8699

87100
if (!success) {
88101
SENTRY_WARNF("MiniDumpWriteDump failed: %lu", error);
89-
DeleteFileA(output_path);
102+
wchar_t *wdelete_path2 = sentry__string_to_wstr(output_path);
103+
if (wdelete_path2) {
104+
DeleteFileW(wdelete_path2);
105+
sentry_free(wdelete_path2);
106+
}
90107
return -1;
91108
}
92109

src/backends/native/sentry_crash_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ typedef DWORD pid_t;
112112
10000 // 10 seconds max wait for daemon to finish
113113
#endif
114114
#define SENTRY_CRASH_TRANSPORT_SHUTDOWN_TIMEOUT_MS \
115-
2000 // 2 seconds for transport shutdown
115+
10000 // 10 seconds for transport shutdown (increased for TSAN/ASAN builds)
116116

117117
/**
118118
* Crash state machine for atomic coordination between app and daemon

src/backends/native/sentry_crash_daemon.c

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/backends/native/sentry_crash_handler.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,19 +496,24 @@ crash_signal_handler(int signum, siginfo_t *info, void *context)
496496
int fd = open(log_path, O_RDONLY);
497497
if (fd >= 0) {
498498
const char *header = "\n========== Daemon Log (";
499-
write(STDERR_FILENO, header, strlen(header));
500-
write(STDERR_FILENO, shm_id, strlen(shm_id));
501-
write(STDERR_FILENO, ") ==========\n", 13);
499+
ssize_t rv = write(STDERR_FILENO, header, strlen(header));
500+
(void)rv; // Ignore write errors in signal handler
501+
rv = write(STDERR_FILENO, shm_id, strlen(shm_id));
502+
(void)rv;
503+
rv = write(STDERR_FILENO, ") ==========\n", 13);
504+
(void)rv;
502505

503506
char buf[1024];
504507
ssize_t n;
505508
while ((n = read(fd, buf, sizeof(buf))) > 0) {
506-
write(STDERR_FILENO, buf, n);
509+
rv = write(STDERR_FILENO, buf, n);
510+
(void)rv;
507511
}
508512

509513
const char *footer
510514
= "=========================================\n\n";
511-
write(STDERR_FILENO, footer, strlen(footer));
515+
rv = write(STDERR_FILENO, footer, strlen(footer));
516+
(void)rv;
512517
close(fd);
513518
}
514519
}

0 commit comments

Comments
 (0)