Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,25 @@ else()
message(FATAL_ERROR "SENTRY_TRANSPORT must be one of: ${_SUPPORTED_TRANSPORTS}")
endif()

if(WIN32)
set(_SUPPORTED_SCREENSHOTS "windows, none, or custom")
set(SENTRY_SCREENSHOT "windows" CACHE STRING
"The screenshot implementation that sentry uses, can be one of: ${_SUPPORTED_SCREENSHOTS}.")
else()
set(_SUPPORTED_SCREENSHOTS "none or custom")
set(SENTRY_SCREENSHOT "none" CACHE STRING
"The screenshot implementation that sentry uses, can be one of: ${_SUPPORTED_SCREENSHOTS}.")
endif()

if(SENTRY_SCREENSHOT STREQUAL "windows")
set(SENTRY_SCREENSHOT_WINDOWS TRUE)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing WIN32 guard for windows screenshot option

Low Severity

The SENTRY_SCREENSHOT "windows" branch doesn't validate that it's actually running on WIN32, unlike the analogous SENTRY_TRANSPORT "winhttp" check which includes if(NOT WIN32) message(FATAL_ERROR ...). If a user explicitly passes -DSENTRY_SCREENSHOT=windows on a non-Windows platform, it would attempt to compile sentry_screenshot_windows.c with Windows-specific APIs, leading to confusing compilation errors rather than a clear configuration-time error.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7083f91. Configure here.

elseif(SENTRY_SCREENSHOT STREQUAL "custom")
set(SENTRY_SCREENSHOT_CUSTOM TRUE)
elseif(SENTRY_SCREENSHOT STREQUAL "none")
set(SENTRY_SCREENSHOT_NONE TRUE)
else()
message(FATAL_ERROR "SENTRY_SCREENSHOT must be one of: ${_SUPPORTED_SCREENSHOTS}")
endif()
Comment thread
cursor[bot] marked this conversation as resolved.

if(SENTRY_BUILD_TESTS OR SENTRY_BUILD_EXAMPLES)
enable_testing()
Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,16 @@ if(SENTRY_INTEGRATION_QT)
endif()

# screenshot
if(WIN32)
if(SENTRY_SCREENSHOT_WINDOWS)
target_compile_definitions(sentry PRIVATE SENTRY_SCREENSHOT_WINDOWS)
sentry_target_sources_cwd(sentry
screenshot/sentry_screenshot_windows.c
)
else()
elseif(SENTRY_SCREENSHOT_NONE)
target_compile_definitions(sentry PRIVATE SENTRY_SCREENSHOT_NONE)
sentry_target_sources_cwd(sentry
screenshot/sentry_screenshot_none.c
)
elseif(SENTRY_SCREENSHOT_CUSTOM)
target_compile_definitions(sentry PRIVATE SENTRY_SCREENSHOT_CUSTOM)
endif()
2 changes: 1 addition & 1 deletion src/backends/native/sentry_crash_daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2905,7 +2905,7 @@ sentry__process_crash(const sentry_options_t *options, sentry_crash_ipc_t *ipc)
// Capture screenshot if enabled (Windows only)
// This is done in the daemon process (out-of-process) because
// screenshot capture is NOT signal-safe (uses LoadLibrary, GDI+, etc.)
#if defined(SENTRY_PLATFORM_WINDOWS)
#if !defined(SENTRY_SCREENSHOT_NONE)
if (ctx->attach_screenshot && run_folder) {
SENTRY_DEBUG("Capturing screenshot");
sentry_path_t *screenshot_path
Expand Down
2 changes: 1 addition & 1 deletion src/backends/sentry_backend_breakpad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ breakpad_backend_callback(const google_breakpad::MinidumpDescriptor &descriptor,

if (should_handle) {
bool capture_screenshot = options->attach_screenshot;
#ifdef SENTRY_PLATFORM_WINDOWS
#ifndef SENTRY_SCREENSHOT_NONE
if (capture_screenshot && options->before_screenshot_func) {
SENTRY_SIGNAL_SAFE_LOG(
"DEBUG invoking `before_screenshot` hook");
Expand Down
2 changes: 1 addition & 1 deletion src/backends/sentry_backend_inproc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ process_ucontext_deferred(const sentry_ucontext_t *uctx,
TEST_CRASH_POINT("before_capture");
if (should_handle) {
bool capture_screenshot = options->attach_screenshot;
#ifdef SENTRY_PLATFORM_WINDOWS
#ifndef SENTRY_SCREENSHOT_NONE
if (capture_screenshot && options->before_screenshot_func) {
SENTRY_DEBUG("invoking `before_screenshot` hook");
capture_screenshot = options->before_screenshot_func(
Expand Down
3 changes: 3 additions & 0 deletions src/backends/sentry_backend_native.c
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,9 @@ native_backend_except(sentry_backend_t *backend, const sentry_ucontext_t *uctx)
# endif
sentry_value_set_by_key(contexts, "device", device_context);

#endif

#ifndef SENTRY_SCREENSHOT_NONE
// The screenshot is captured by the daemon out-of-process, so
// we invoke the hook here (in the crashing process, where
// user callbacks can run) and communicate the decision to the
Expand Down
Loading