Skip to content
Open
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
23 changes: 13 additions & 10 deletions src/lib-oauth2/oauth2-jwt.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,11 @@ oauth2_jwt_copy_fields(ARRAY_TYPE(oauth2_field) *fields,
root->root = json_tree_get_root_const(tree);

while (array_count(&nodes) > 0) {
const struct jwt_node *subroot = array_front(&nodes);
const struct json_tree_node *tnode = subroot->root;
/* Take a local copy: array_append_space() below grows the
nodes buffer, which may move it via realloc and leave any
pointer into the old slot dangling. */
const struct jwt_node subroot = *array_front(&nodes);
const struct json_tree_node *tnode = subroot.root;

while (tnode != NULL) {
const struct json_node *jnode =
Expand All @@ -390,21 +393,21 @@ oauth2_jwt_copy_fields(ARRAY_TYPE(oauth2_field) *fields,
root->root = json_tree_node_get_child(tnode);
root->array = json_node_is_array(jnode);
if (jnode->name == NULL)
root->prefix = subroot->prefix;
else if (*subroot->prefix != '\0')
root->prefix = t_strconcat(subroot->prefix, jnode->name, "_", NULL);
root->prefix = subroot.prefix;
else if (*subroot.prefix != '\0')
root->prefix = t_strconcat(subroot.prefix, jnode->name, "_", NULL);
else
root->prefix = t_strconcat(jnode->name, "_", NULL);
} else {
struct oauth2_field *field = NULL, *field_iter;
const char *name;

if (subroot->array) {
name = strrchr(subroot->prefix, '_');
if (subroot.array) {
name = strrchr(subroot.prefix, '_');
if (name != NULL)
name = t_strdup_until(subroot->prefix, name);
name = t_strdup_until(subroot.prefix, name);
else
name = subroot->prefix;
name = subroot.prefix;
array_foreach_modifiable(fields, field_iter) {
if (strcmp(field_iter->name, name) == 0) {
field = field_iter;
Expand All @@ -417,7 +420,7 @@ oauth2_jwt_copy_fields(ARRAY_TYPE(oauth2_field) *fields,
}
} else {
field = array_append_space(fields);
field->name = p_strconcat(pool, subroot->prefix, jnode->name, NULL);
field->name = p_strconcat(pool, subroot.prefix, jnode->name, NULL);
}

const char *value = str_tabescape(json_node_as_str(jnode));
Expand Down