]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict-backend: dict-ldap - Fix accessing parsed_attributes array
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 3 Feb 2026 15:44:37 +0000 (17:44 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 6 Feb 2026 14:34:18 +0000 (14:34 +0000)
There was ever only one value, so it didn't cause problems yet.

src/lib-dict-backend/dict-ldap-settings.c
src/lib-dict-backend/dict-ldap-settings.h
src/lib-dict-backend/dict-ldap.c

index eaf569b0ed71227e78cc265d87129b178431077b..80d3cdbf599ae3997df333c13173614385bc86fb 100644 (file)
@@ -140,8 +140,10 @@ static int ldap_parse_attributes(struct dict_ldap_map_settings *set,
                                 struct dict_ldap_map_post_settings *post,
                                 const char **error_r)
 {
+       ARRAY_TYPE(const_string) parsed_attributes;
        const char *value;
-       p_array_init(&set->parsed_attributes, set->pool, 2);
+
+       p_array_init(&parsed_attributes, set->pool, 2);
        array_foreach_elem(&post->values, value) {
                struct var_expand_program *prog;
 
@@ -161,10 +163,12 @@ static int ldap_parse_attributes(struct dict_ldap_map_settings *set,
                        /* When we free program, this name would be invalid,
                           so dup it here. */
                        ldap_attr = p_strdup(set->pool, ldap_attr);
-                       array_push_back(&set->parsed_attributes, &ldap_attr);
+                       array_push_back(&parsed_attributes, &ldap_attr);
                }
                var_expand_program_free(&prog);
        }
+       array_append_zero(&parsed_attributes);
+       set->parsed_attributes = array_front(&parsed_attributes);
        return 0;
 }
 
index ffae6e4f16e7f57c4d17469fbc8d6ce968c4d90f..578e0243c120b593b059a0c80a0d79e1e6115035 100644 (file)
@@ -10,7 +10,7 @@ struct dict_ldap_map_settings {
 
        /* parsed */
 
-       ARRAY_TYPE(const_string) parsed_attributes;
+       const char *const *parsed_attributes;
 
        /* attributes sorted by the position in parsed_pattern. */
        ARRAY_TYPE(const_string) parsed_pattern_keys;
index 81eed292cec91f824a596139d4571c7cd0252066..4b0de19dbbd5357988ba9ef43c8659f3aa622d16 100644 (file)
@@ -241,8 +241,8 @@ ldap_dict_lookup_cb_values(const struct ldap_entry *entry, struct dict_ldap_op *
        e_debug(op->event, "got dn %s",
                ldap_entry_dn(entry));
 
-       const char *attribute;
-       array_foreach_elem(&op->map->parsed_attributes, attribute) {
+       for (unsigned int i = 0; op->map->parsed_attributes[i] != NULL; i++) {
+               const char *attribute = op->map->parsed_attributes[i];
                const char *const *values = ldap_entry_get_attribute(entry, attribute);
                bool no_attribute = values == NULL;
                e_debug(op->event, "%s attribute %s",
@@ -478,9 +478,8 @@ void ldap_dict_lookup_async(struct dict *dict,
                input.scope = op->map->parsed_scope;
                /* Guaranteed to be NULL-terminated by
                   dict_ldap_map_settings_postcheck() */
-               input.attributes =
-                       array_is_empty(&op->map->parsed_attributes) ? NULL :
-                       array_front(&op->map->parsed_attributes);
+               input.attributes = op->map->parsed_attributes[0] == NULL ? NULL :
+                       op->map->parsed_attributes;
                ctx->pending++;
                ldap_search_start(ctx->client, &input, ldap_dict_lookup_callback, op);
                settings_free(pre);