Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
- Prevent database cleanup from following symlinks in run and cache directories. ([#1751](https://github.com/getsentry/sentry-native/pull/1751))
- Structured logs: respect printf argument widths when extracting log parameters to avoid stack-data disclosure and corrupted attributes on 32-bit platforms. ([#1752](https://github.com/getsentry/sentry-native/pull/1752))
- Fix TOCTOU races in transaction/span refcounting by switching to the atomic decref return value. ([#1763](https://github.com/getsentry/sentry-native/pull/1763))
- Fix signed-to-unsigned cast in rate-limit parsing to prevent permanent event suppression. ([#1790](https://github.com/getsentry/sentry-native/pull/1790))
- Fix a potential out-of-bounds read when parsing non-NUL-terminated `sentry-trace` headers. ([#1749](https://github.com/getsentry/sentry-native/pull/1749))
- Harden ELF note parsing against overflow and OOB reads. ([#1773](https://github.com/getsentry/sentry-native/pull/1773))
- Fix division by zero when breadcrumbs are disabled. ([#1767](https://github.com/getsentry/sentry-native/pull/1767))
Expand Down
7 changes: 4 additions & 3 deletions src/sentry_slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ sentry__slice_consume_uint64(sentry_slice_t *a, uint64_t *num_out)
memcpy(buf, a->ptr, a->len);
buf[a->len] = 0;
char *end;
*num_out = (uint64_t)strtoll(buf, &end, 10);
if (end != buf) {
size_t diff = (uintptr_t)end - (uintptr_t)buf;
unsigned long long val = strtoull(buf, &end, 10);
size_t diff = (uintptr_t)end - (uintptr_t)buf;
if (end != buf && !memchr(buf, '-', diff)) {
*num_out = (uint64_t)val;
a->len -= diff;
a->ptr += diff;
rv = true;
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_slice.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,29 @@ SENTRY_TEST(slice)
TEST_CHECK_STRING_EQUAL(owned, "string");
sentry_free(owned);
}

SENTRY_TEST(slice_consume_uint64)
{
uint64_t value = 0;

sentry_slice_t zero = sentry__slice_from_str("0:foo-bar");
value = 0;
TEST_CHECK(sentry__slice_consume_uint64(&zero, &value));
TEST_CHECK_UINT64_EQUAL(value, 0);
TEST_CHECK_UINT64_EQUAL(zero.len, 8);
TEST_CHECK_STRING_EQUAL(zero.ptr, ":foo-bar");

sentry_slice_t max = sentry__slice_from_str("18446744073709551615:foo-bar");
value = 0;
TEST_CHECK(sentry__slice_consume_uint64(&max, &value));
TEST_CHECK_UINT64_EQUAL(value, UINT64_MAX);
TEST_CHECK_UINT64_EQUAL(max.len, 8);
TEST_CHECK_STRING_EQUAL(max.ptr, ":foo-bar");

sentry_slice_t negative = sentry__slice_from_str("-1:foo-bar");
value = 0;
TEST_CHECK(!sentry__slice_consume_uint64(&negative, &value));
TEST_CHECK_UINT64_EQUAL(value, 0);
TEST_CHECK_UINT64_EQUAL(negative.len, 10);
TEST_CHECK_STRING_EQUAL(negative.ptr, "-1:foo-bar");
}
1 change: 1 addition & 0 deletions tests/unit/tests.inc
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ XX(set_trace_id_with_txn)
XX(set_trace_rebuilds_dsc_sample_rand)
XX(set_trace_update_from_header)
XX(slice)
XX(slice_consume_uint64)
XX(span_data)
XX(span_data_n)
XX(span_tagging)
Expand Down
Loading