]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: server: set rid default value in new_server()
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 7 Jul 2023 13:19:36 +0000 (15:19 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 10 Jul 2023 16:28:08 +0000 (18:28 +0200)
srv->rid default value is set in _srv_parse_init() after the server is
succesfully allocated using new_server().

This is wrong because new_server() can be used independently so rid value
assignment would be skipped in this case.

Hopefully new_server() allocates server data using calloc() so srv->rid
is already set to 0 in practise. But if calloc() is replaced by malloc()
or other memory allocating function that doesn't zero-initialize srv
members, this could lead to rid being uninitialized in some cases.

This should be backported in 2.8 with 61e3894dfe ("MINOR: server: add
srv->rid (revision id) value")

src/server.c

index fc6df63e7380d8d25ae888cd1204de1dfdf5d93d..8ccb45be264408911947b7c3cc7c2db4dd304789 100644 (file)
@@ -2430,6 +2430,7 @@ struct server *new_server(struct proxy *proxy)
        LIST_INIT(&srv->ip_rec_item);
        MT_LIST_INIT(&srv->prev_deleted);
        event_hdl_sub_list_init(&srv->e_subs);
+       srv->rid = 0; /* rid defaults to 0 */
 
        srv->next_state = SRV_ST_RUNNING; /* early server setup */
        srv->last_change = ns_to_sec(now_ns);
@@ -2764,9 +2765,6 @@ static int _srv_parse_init(struct server **srv, char **args, int *cur_arg,
                else
                        newsrv->tmpl_info.prefix = strdup(args[1]);
 
-               /* revision defaults to 0 */
-               newsrv->rid = 0;
-
                /* several ways to check the port component :
                 *  - IP    => port=+0, relative (IPv4 only)
                 *  - IP:   => port=+0, relative