Skip to content

Commit 52ce9c5

Browse files
jpnurmiclaude
andcommitted
revert sentry__ensure_user_id; don't mutate caller-provided user
The helper mutated its user argument, which leaked out through sentry_set_user (caller's value) and sentry__session_sync_user (scope->user). Revert the helper and inline both sites again. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2af7ee3 commit 52ce9c5

4 files changed

Lines changed: 12 additions & 24 deletions

File tree

src/sentry_core.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -856,17 +856,6 @@ sentry__ensure_event_id(sentry_value_t event, sentry_uuid_t *uuid_out)
856856
return event_id;
857857
}
858858

859-
sentry_value_t
860-
sentry__ensure_user_id(sentry_value_t user, const char *installation_id)
861-
{
862-
sentry_value_t user_id = sentry_value_get_by_key(user, "id");
863-
if (sentry_value_is_null(user_id) && installation_id) {
864-
user_id = sentry_value_new_string(installation_id);
865-
sentry_value_set_by_key(user, "id", user_id);
866-
}
867-
return user_id;
868-
}
869-
870859
void
871860
sentry_set_user(sentry_value_t user)
872861
{

src/sentry_core.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,6 @@ sentry_uuid_t sentry__new_event_id(void);
109109
sentry_value_t sentry__ensure_event_id(
110110
sentry_value_t event, sentry_uuid_t *uuid_out);
111111

112-
/**
113-
* This will ensure that the given `user` has an `id`, falling back to
114-
* `installation_id` when the user has no explicit id. Returns the id value
115-
* (existing or newly-set), or a null value if neither is available.
116-
*/
117-
sentry_value_t sentry__ensure_user_id(
118-
sentry_value_t user, const char *installation_id);
119-
120112
/**
121113
* This will return an owned reference to the global options.
122114
*/

src/sentry_scope.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,12 @@ sentry__scope_apply_to_event(const sentry_scope_t *scope,
360360
if (IS_NULL("user")) {
361361
SET("user", sentry__value_clone(scope->user));
362362
}
363+
// patch missing user ID with installation ID
363364
sentry_value_t user = sentry_value_get_by_key(event, "user");
364-
if (sentry_value_get_type(user) == SENTRY_VALUE_TYPE_OBJECT) {
365-
sentry__ensure_user_id(user, options->run->installation_id);
365+
if (sentry_value_get_type(user) == SENTRY_VALUE_TYPE_OBJECT
366+
&& sentry_value_is_null(sentry_value_get_by_key(user, "id"))) {
367+
sentry_value_set_by_key(user, "id",
368+
sentry_value_new_string(options->run->installation_id));
366369
}
367370
} else if (sentry_value_get_length(scope->user) > 0) {
368371
PLACE_VALUE("user", scope->user);

src/sentry_session.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ void
302302
sentry__session_sync_user(
303303
sentry_session_t *session, sentry_value_t user, const char *installation_id)
304304
{
305-
sentry_value_t did = sentry__ensure_user_id(user, installation_id);
305+
sentry_value_t did = sentry_value_get_by_key(user, "id");
306306
sentry_value_decref(session->distinct_id);
307-
sentry_value_incref(did);
308-
session->distinct_id = did;
307+
if (sentry_value_is_null(did) && installation_id) {
308+
session->distinct_id = sentry_value_new_string(installation_id);
309+
} else {
310+
sentry_value_incref(did);
311+
session->distinct_id = did;
312+
}
309313
}

0 commit comments

Comments
 (0)