]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: resolvers: do not duplicate the hostname_dn field
authorWilly Tarreau <w@1wt.eu>
Mon, 7 Jul 2025 14:57:24 +0000 (16:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 Jul 2025 05:54:45 +0000 (07:54 +0200)
The hostdn.key field in the server contains a pure copy of the hostname_dn
since commit 3406766d57 ("MEDIUM: resolvers: add a ref between servers and
srv request or used SRV record") which wanted to lowercase it. Since it's
not necessary, let's drop this useless copy. In addition, the return from
strdup() was not tested, so it could theoretically crash the process under
heavy memory contention.

src/resolvers.c
src/server_state.c

index cafae8e2b558cf0aff7e83e7e891e2aa5234bd06..c788cd43705564f8b4f7e5df2779c81632b578bf 100644 (file)
@@ -741,6 +741,10 @@ static void resolv_srvrq_cleanup_srv(struct server *srv)
        _resolv_unlink_resolution(srv->resolv_requester);
        HA_SPIN_LOCK(SERVER_LOCK, &srv->lock);
        srvrq_set_srv_down(srv);
+
+       ebpt_delete(&srv->host_dn);
+       srv->host_dn.key = NULL;
+
        ha_free(&srv->hostname);
        ha_free(&srv->hostname_dn);
        srv->hostname_dn_len = 0;
@@ -749,9 +753,6 @@ static void resolv_srvrq_cleanup_srv(struct server *srv)
        server_set_inetaddr(srv, &srv_addr, SERVER_INETADDR_UPDATER_NONE, NULL);
        srv->flags |= SRV_F_NO_RESOLUTION;
 
-       ebpt_delete(&srv->host_dn);
-       ha_free(&srv->host_dn.key);
-
        HA_SPIN_UNLOCK(SERVER_LOCK, &srv->lock);
        LIST_DEL_INIT(&srv->srv_rec_item);
        LIST_APPEND(&srv->srvrq->attached_servers, &srv->srv_rec_item);
@@ -873,7 +874,7 @@ static void resolv_check_response(struct resolv_resolution *res)
                                                if (srv->svc_port == item->port) {
                                                        /* server found, we remove it from tree */
                                                        ebpt_delete(node);
-                                                       ha_free(&srv->host_dn.key);
+                                                       srv->host_dn.key = NULL;
                                                        goto srv_found;
                                                }
 
index 21170f8d295f0fe4cc88dc833f8a097cfb48953c..1d38f068b2fe46ebd15d8d4fcb8f3fdce9dc03e2 100644 (file)
@@ -415,7 +415,7 @@ static void srv_state_srv_update(struct server *srv, int version, char **params)
                 * since this server has an hostname
                 */
                LIST_DEL_INIT(&srv->srv_rec_item);
-               srv->host_dn.key = strdup(srv->hostname_dn);
+               srv->host_dn.key = srv->hostname_dn;
 
                /* insert in tree and set the srvrq expiration date */
                ebis_insert(&srv->srvrq->named_servers, &srv->host_dn);