src/tools.c: ha_freearray() does not free the array, leaking it when domains/ips is repeated in ckch_conf_parse()
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- Menos de una hora
- Aptitud para principiantes
- 78/100
Línea de trabajo
Lee ha_freearray() en src/tools.c e inspecciona su llamador, ckch_conf_parse(), para confirmar cómo se asigna y se libera el array. El issue incluye un reproductor que usa las palabras clave repetidas domains o ips e informa de una fuga de LeakSanitizer; reprodúcela con la configuración proporcionada y luego verifica que la fuga haya desaparecido después de liberar el array.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Detailed Description of the Problem
ha_freearray() in src/tools.c frees each string of a NULL-terminated array, but never frees the array itself:
void ha_freearray(char ***array)
{
int i;
char **r = *array;
for (i = 0; r && r[i]; i++) {
ha_free(&r[i]);
}
*array = NULL; /* the array is lost here */
}
Its only caller is ckch_conf_parse(), which calls it to release the previous value when a PARSE_TYPE_ARRAY_SUBSTR keyword (domains, ips) is given twice on the same crt-store (or crt-list) line. The first array is then leaked. The impact is small: a few bytes per duplicated keyword at parsing time, and HAProxy already warns about the duplicate.
Expected Behavior
The previous value is fully freed when the keyword is overwritten.
Steps to Reproduce the Behavior
- Build with
ARCH_FLAGS="-fsanitize=address". - Run
ASAN_OPTIONS=detect_leaks=1 ./haproxy -c -d -f dup.cfgwith the configuration below.-dis needed: without it,-ccloses stderr before LeakSanitizer prints its report. - The same happens with
ips "10.0.0.1,10.0.0.2" ips "10.0.0.3". Withdomainsgiven only once, there is no leak.
Do you have any idea what may have caused this?
ha_freearray() sets the array pointer to NULL instead of freeing it. It was added by 96b1f1fd2 ("MINOR: tools: ha_freearray() frees an array of string") and first used by 9c0c05b7b ("BUG/MINOR: ssl/ckch: always ha_freearray() the previous entry during parsing"), both in 3.2-dev16, so 3.2 and later are affected.
Do you have an idea how to solve the issue?
Free the array with ha_free(), which also resets the pointer. Patch in git format below, against master 63d25783f. With it, the same runs with repeated domains or ips report no leak.
From c54f2e1578a069b265d1eb0ba94acc5c37717704 Mon Sep 17 00:00:00 2001
From: Alexandre Laroche <[email protected]>
Date: Tue, 10 Nov 2026 20:57:09 -0500
Subject: [PATCH] BUG/MINOR: tools: ha_freearray() must also free the array
ha_freearray() frees each string of a NULL-terminated array and then
sets the array pointer to NULL, but never frees the array itself.
Its only caller is ckch_conf_parse(), which uses it to release the
previous value when a PARSE_TYPE_ARRAY_SUBSTR keyword ("domains", "ips")
is specified twice on the same line, as in:
crt-store s
load crt site.pem domains "a.example,b.example" domains "c.example"
The strings are freed but the array of the first value is leaked
(24 bytes here, reported by LeakSanitizer with "haproxy -c -d" on a
build with -fsanitize=address). The leak only happens when parsing a
line with a duplicated keyword, which also emits an "already specified,
overwriting" warning, so the impact is minimal.
Fix it by freeing the array with ha_free(), which also sets the pointer
to NULL as before. With the patch, the same configuration with either
"domains" or "ips" repeated reports no leak.
This was introduced by commit 96b1f1fd2 ("MINOR: tools: ha_freearray()
frees an array of string") together with its use in commit 9c0c05b7b
("BUG/MINOR: ssl/ckch: always ha_freearray() the previous entry during
parsing"), both in 3.2-dev16, so this must be backported to 3.2.
---
src/tools.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/tools.c b/src/tools.c
index 7e4f7b4ea..4912714f9 100644
--- a/src/tools.c
+++ b/src/tools.c
@@ -7783,7 +7783,7 @@ void ha_freearray(char ***array)
for (i = 0; r && r[i]; i++) {
ha_free(&r[i]);
}
- *array = NULL;
+ ha_free(array);
}
/*
--
2.43.0
What is your configuration?
global
log stderr local0
crt-store s
load crt site.pem domains "a.example,b.example" domains "c.example,d.example"
defaults
mode http
timeout client 1s
timeout server 1s
timeout connect 1s
frontend f
bind 127.0.0.1:18443 ssl crt "@s/site.pem"
Output of haproxy -vv
HAProxy version 3.5-dev11-63d257-85 2026/11/11 - https://haproxy.org/
Status: development branch - not safe for use in production.
Known bugs: https://github.com/haproxy/haproxy/issues?q=is:issue+is:open
Running on: Linux 7.0.0-38-generic #38~24.04.4-Ubuntu SMP PREEMPT_DYNAMIC Mon Sep 14 16:37:11 UTC 2 x86_64
Build options :
TARGET = linux-glibc
CC = cc
CFLAGS = -O2 -fsanitize=address -O1 -g -fno-omit-frame-pointer -fwrapv -fvect-cost-model=very-cheap
OPTIONS = USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE2=1
DEBUG =
Feature list : -51DEGREES +ACCEPT4 +ACME +BACKTRACE -CLOSEFROM +CPU_AFFINITY +CRYPT_H -DEVICEATLAS +DL -ECH -ENGINE +EPOLL -EVPORTS +FCGI +GETADDRINFO +H2 +HAVE_TCP_MD5SIG -KQUEUE +KTLS -LIBATOMIC +LIBCRYPT +LINUX_CAP +LINUX_SPLICE +LINUX_TPROXY -LUA -MATH -MEMORY_PROFILING +MINIDEBUG +NETFILTER +NS -OBSOLETE_LINKER +OPENSSL -OPENSSL_AWSLC -OPENSSL_WOLFSSL -PCRE +PCRE2 -PCRE2_JIT -PCRE_JIT +POLL +PRCTL -PROCCTL -PROMEX -PTHREAD_EMULATION -QUIC -QUIC_OPENSSL_COMPAT +RT +SHM_OPEN -SLZ +SPOE +SSL -STATIC_PCRE -STATIC_PCRE2 +TFO +THREAD +THREAD_DUMP +TPROXY +TRACE -WURFL +ZLIB
Detected feature list : +HAVE_WORKING_TCP_MD5SIG
Default settings :
bufsize = 16384, maxrewrite = 1024, maxpollevents = 200
Built with multi-threading support (MAX_TGROUPS=32, MAX_THREADS=1024, default=4).
Built with SSL library version : OpenSSL 3.0.13 30 Jan 2024
Running on SSL library version : OpenSSL 3.0.13 30 Jan 2024
SSL library supports TLS extensions : yes
SSL library supports SNI : yes
SSL library FIPS mode : no
SSL library default verify directory : /usr/lib/ssl/certs
SSL library supports : TLSv1.0 TLSv1.1 TLSv1.2 TLSv1.3
OpenSSL providers loaded : default
Built with network namespace support.
Running with a replaced memory allocator (e.g. via LD_PRELOAD).
Built with zlib version : 1.3
Running on zlib version : 1.3
Compression algorithms supported : identity("identity"), deflate("deflate"), raw-deflate("deflate"), gzip("gzip")
Built with transparent proxy support using: IP_TRANSPARENT IPV6_TRANSPARENT IP_FREEBIND
Built with PCRE2 version : 10.42 2022-12-11
PCRE2 library supports JIT : no (USE_PCRE2_JIT not set)
Encrypted password support via crypt(3): yes
Built with gcc compiler version 13.3.0 with address sanitizer
Available polling systems :
epoll : pref=300, test result OK
poll : pref=200, test result OK
select : pref=150, test result OK
Total: 3 (3 usable), will use epoll.
Available multiplexer protocols :
(protocols marked as <default> cannot be specified using 'proto' keyword)
h2 : mode=HTTP side=FE|BE mux=H2 flags=HTX|HOL_RISK|NO_UPG
fcgi : mode=HTTP side=BE mux=FCGI flags=HTX|HOL_RISK|NO_UPG
<default> : mode=SPOP side=BE mux=SPOP flags=HOL_RISK|NO_UPG
spop : mode=SPOP side=BE mux=SPOP flags=HOL_RISK|NO_UPG
<default> : mode=HTTP side=FE|BE mux=H1 flags=HTX
h1 : mode=HTTP side=FE|BE mux=H1 flags=HTX|NO_UPG
<default> : mode=TCP side=FE|BE mux=PASS flags=
none : mode=TCP side=FE|BE mux=PASS flags=NO_UPG
Available services : none
Available filter classes :
trace, cache-store, decomp-req, decomp-res, spoe, http-comp-req, http-comp-res, bwlim-in, bwlim-out, fcgi
Last Outputs and Backtraces
[WARNING] : config : parsing [dup.cfg:4] : 'domains' already specified, overwriting.
Direct leak of 24 byte(s) in 1 object(s) allocated from:
#0 in realloc
#1 in ckch_conf_parse
#2 in crtstore_parse_load
#3 in cfg_parse_crtstore
#4 in parse_cfg
#5 in read_cfg
#6 in main
SUMMARY: AddressSanitizer: 24 byte(s) leaked in 1 allocation(s).
Additional Information
Noticed while preparing the patch for #3561 (same function, ckch_conf_parse()). The analysis and this report were prepared with AI assistance (Claude), and every step above was run and checked.
- Lenguaje dominante
- C
- Estrellas
- 6.9k
- Forks
- 976
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de haproxy/haproxy
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 80/100
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
3.2 3.3 3.4 status: fixed
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
-
2.8 3.0 3.2 3.3 3.4 status: fixed type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 86/100
Todos los issues de haproxy/haproxy
Issues similares
-
polish
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
ChupathingyCE/chupathingyce#1366 ·
Los mantenedores suelen responder en 1 día
-
slice track:dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 64/100
Life-Framework/Life-Framework#1831 ·
Los mantenedores suelen responder en 1 día
-
bug intrinsic low priority wrong result
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día