Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
use a heap-allocated 32K buffer for symbol paths
  • Loading branch information
supervacuus authored Oct 1, 2025
commit d67abba8cfcd24d563b367ce8100edec61b7ca36
15 changes: 12 additions & 3 deletions src/symbolizer/sentry_symbolizer_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <dbghelp.h>
#include <malloc.h>

// follow the maximum path length documented here:
// https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
#define MAX_PATH_BUFFER_SIZE 32768

bool
sentry__symbolize(
void *addr, void (*func)(const sentry_frame_info_t *, void *), void *data)
Expand All @@ -31,10 +35,14 @@ sentry__symbolize(
return false;
}

WCHAR mod_path_w[MAX_PATH];
wchar_t *mod_path_w = sentry_malloc(sizeof(wchar_t) * MAX_PATH_BUFFER_SIZE);
if (!mod_path_w) {
return false;
}
const DWORD n = GetModuleFileNameW(
(HMODULE)(uintptr_t)symbol_info->ModBase, mod_path_w, MAX_PATH);
if (n == 0 || n >= MAX_PATH) {
(HMODULE)(uintptr_t)symbol_info->ModBase, mod_path_w, MAX_PATH_BUFFER_SIZE);
if (n == 0 || n >= MAX_PATH_BUFFER_SIZE) {
sentry_free(mod_path_w);
return false;
}

Expand All @@ -51,6 +59,7 @@ sentry__symbolize(

sentry_free(mod_path);
sentry_free(symbol_name);
Copy link

Choose a reason for hiding this comment

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

Bug: String Conversion and Memory Management Issues

The sentry__string_from_wstr calls for mod_path and symbol_name introduce two issues. If these conversions fail, the callback receives NULL pointers for frame_info.object_name and frame_info.symbol. If successful, the heap-allocated strings are freed immediately, causing use-after-free if the callback stores these pointers. Both can lead to crashes or unexpected behavior.

Fix in Cursor Fix in Web

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is a sensible warning, but intentional in the current code:

  • All items of the frame info are nullable and thus must be checked. This allows partially populated frames in the serialization instead of empty ones because a single property is missing.
  • The callback only borrows the frame info and must clone items if the lifetime must be extended. Freeing after its invocation is a lifetime contract.

sentry_free(mod_path_w);
#endif // SENTRY_PLATFORM_XBOX

return true;
Expand Down
Loading