Skip to content

Commit 649cd94

Browse files
jpnurmicodex
andauthored
fix: leak in sentry__session_from_json (#1789)
* fix: leak in `sentry__session_from_json` Release parsed session JSON values on early parse failures to avoid leaking malformed cached session files. Co-Authored-By: OpenAI Codex <noreply@openai.com> * Update CHANGELOG.md --------- Co-authored-by: OpenAI Codex <noreply@openai.com>
1 parent 7a7af4d commit 649cd94

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- Fix signed-to-unsigned cast in rate-limit parsing to prevent permanent event suppression. ([#1790](https://github.com/getsentry/sentry-native/pull/1790))
4242
- Fix a potential out-of-bounds read when parsing non-NUL-terminated `sentry-trace` headers. ([#1749](https://github.com/getsentry/sentry-native/pull/1749))
4343
- Harden ELF note parsing against overflow and OOB reads. ([#1773](https://github.com/getsentry/sentry-native/pull/1773))
44+
- Fix memory leak in session deserialization on malformed cached files. ([#1789](https://github.com/getsentry/sentry-native/pull/1789))
4445
- Fix division by zero when breadcrumbs are disabled. ([#1767](https://github.com/getsentry/sentry-native/pull/1767))
4546
- Native: escape JSON attachments. ([#1771](https://github.com/getsentry/sentry-native/pull/1771))
4647
- Handle memory allocation failures during JSON serialization to prevent truncated output. ([#1772](https://github.com/getsentry/sentry-native/pull/1772))

src/sentry_session.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,20 @@ sentry__session_from_json(const char *buf, size_t buflen)
151151

152152
sentry_value_t attrs = sentry_value_get_by_key(value, "attrs");
153153
if (sentry_value_is_null(attrs)) {
154+
sentry_value_decref(value);
154155
return NULL;
155156
}
156157
char *release = sentry__string_clone(
157158
sentry_value_as_string(sentry_value_get_by_key(attrs, "release")));
158159
if (!release) {
160+
sentry_value_decref(value);
159161
return NULL;
160162
}
161163

162164
sentry_session_t *rv = SENTRY_MAKE(sentry_session_t);
163165
if (!rv) {
164166
sentry_free(release);
167+
sentry_value_decref(value);
165168
return NULL;
166169
}
167170
rv->session_id

0 commit comments

Comments
 (0)