Skip to content

Commit

Permalink
fix: check file-writer construction when writing envelope to path (#1036
Browse files Browse the repository at this point in the history
)

* fix: check file-writer construction when writing envelope to path

* update changelog.

* clang-format

* add a powershell convenience test-runner

* clarify platform support for `sentry_handle_exception()`
  • Loading branch information
supervacuus authored Aug 28, 2024
1 parent a762b23 commit 58c3286
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 3 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Changelog

## Unreleased

**Fixes**:

- Check file-writer construction when writing envelope to path. ([#1036](https://github.com/getsentry/sentry-native/pull/1036))

## 0.7.8

**Features**:

- Let the envelope serialization stream directly to the file. ([#1021](https://github.com/getsentry/sentry-native/pull/1021))
- Support 16kb page sizes on Android 15 ([#1028](https://github.com/getsentry/sentry-native/pull/1028))
- Support 16kb page sizes on Android 15. ([#1028](https://github.com/getsentry/sentry-native/pull/1028))

## 0.7.7

Expand Down
3 changes: 3 additions & 0 deletions include/sentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,9 @@ SENTRY_API sentry_uuid_t sentry_capture_event(sentry_value_t event);
* Captures an exception to be handled by the backend.
*
* This is safe to be called from a crashing thread and may not return.
*
* Note: The `crashpad` client currently supports this only on Windows. `inproc`
* and `breakpad` support it on all platforms.
*/
SENTRY_EXPERIMENTAL_API void sentry_handle_exception(
const sentry_ucontext_t *uctx);
Expand Down
40 changes: 40 additions & 0 deletions scripts/run_tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
param (
[switch]$Unit = $false,
[switch]$Clean = $false,
[string]$Keyword = "",
[int]$Parallelism = 1,
[switch]$WithoutCrashpadWer = $false
)

$update_test_discovery = Join-Path -Path $PSScriptRoot -ChildPath "update_test_discovery.ps1"
& $update_test_discovery

if ($Clean -or -not (Test-Path .\.venv))
{
Remove-Item -Recurse -Force .\.venv\ -ErrorAction SilentlyContinue
python3.exe -m venv .venv
.\.venv\Scripts\pip.exe install --upgrade --requirement .\tests\requirements.txt
}

$pytestCommand = ".\.venv\Scripts\pytest.exe .\tests\ --verbose"

if ($Parallelism -gt 1)
{
$pytestCommand += " -n $Parallelism"
}

if (-not $WithoutCrashpadWer -and -not $Unit)
{
$pytestCommand += " --with_crashpad_wer"
}

if ($Keyword)
{
$pytestCommand += " -k `"$Keyword`""
}
elseif ($Unit)
{
$pytestCommand += " -k `"unit`""
}

Invoke-Expression $pytestCommand
7 changes: 7 additions & 0 deletions scripts/update_test_discovery.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Get-ChildItem -Path 'tests/unit/*.c' | ForEach-Object {
Get-Content $_.FullName | ForEach-Object {
if ($_ -match 'SENTRY_TEST\(([^)]+)\)') {
$_ -replace 'SENTRY_TEST\(([^)]+)\)', 'XX($1)'
}
}
} | Sort-Object | Where-Object { $_ -notmatch 'define' } | Get-Unique | Set-Content 'tests/unit/tests.inc'
10 changes: 8 additions & 2 deletions src/path/sentry_path_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ bool
sentry__path_filename_matches(const sentry_path_t *path, const char *filename)
{
sentry_path_t *fn = sentry__path_from_str(filename);
if (!fn) {
return false;
}
bool matches = _wcsicmp(sentry__path_filename(path), fn->path) == 0;
sentry__path_free(fn);
return matches;
Expand All @@ -282,6 +285,9 @@ bool
sentry__path_ends_with(const sentry_path_t *path, const char *suffix)
{
sentry_path_t *s = sentry__path_from_str(suffix);
if (!s) {
return false;
}
size_t pathlen = wcslen(path->path);
size_t suffixlen = wcslen(s->path);
if (suffixlen > pathlen) {
Expand Down Expand Up @@ -604,9 +610,9 @@ sentry__filewriter_write(
}
while (buf_len > 0) {
size_t n = fwrite(buf, 1, buf_len, filewriter->f);
if (n < 0 && (errno == EAGAIN || errno == EINTR)) {
if (n == 0 && errno == EINVAL) {
continue;
} else if (n <= 0) {
} else if (n < buf_len) {
break;
}
filewriter->byte_count += n;
Expand Down
3 changes: 3 additions & 0 deletions src/sentry_envelope.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ sentry_envelope_write_to_path(
const sentry_envelope_t *envelope, const sentry_path_t *path)
{
sentry_filewriter_t *fw = sentry__filewriter_new(path);
if (!fw) {
return 1;
}

if (envelope->is_raw) {
return envelope->contents.raw.payload_len
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_envelopes.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,19 @@ SENTRY_TEST(write_envelope_to_file_null)

sentry_envelope_free(empty_envelope);
}

SENTRY_TEST(write_envelope_to_invalid_path)
{
sentry_envelope_t *envelope = create_test_envelope();
const char *test_file_str
= "./directory_that_does_not_exist/sentry_test_envelope";
sentry_path_t *test_file_path = sentry__path_from_str(test_file_str);

int rv = sentry_envelope_write_to_file(envelope, test_file_str);
TEST_CHECK_INT_EQUAL(rv, 1);

sentry__path_remove(test_file_path);
sentry__path_free(test_file_path);
sentry_envelope_free(envelope);
sentry_close();
}
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,4 @@ XX(value_string_n)
XX(value_unicode)
XX(value_wrong_type)
XX(write_envelope_to_file_null)
XX(write_envelope_to_invalid_path)

0 comments on commit 58c3286

Please sign in to comment.