]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: promex: Skip resolvers metrics when there is no resolver section
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 12 Jun 2024 06:42:56 +0000 (08:42 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 12 Jun 2024 06:55:52 +0000 (08:55 +0200)
By default, there is always at least on resolver section, the default one,
based on "/etc/resolv.conf" content. However, it is possible to have no
resolver at all if the file is empty or if any error occurred. Errors are
silently ignored at this stage.

In that case, there was a bug in the Prometheus exporter leading to a crash
because the resolver section list is empty. An invalid resolver entity was
used. To fix the issue we must only take care to not dump resolvers metrics
when there is no resolver.

Thanks to Aurelien to have spotted the offending commit.

This patch should fix the issue #2604. It must be backported to 3.0.

src/resolvers.c

index 47b0cce44d356e7da3d635a2d82444ca6f5e2d8a..640c9c2816e591c9ddef780c96d46f6118822f91 100644 (file)
@@ -3919,8 +3919,12 @@ static int rslv_promex_metric_info(unsigned int id, struct promex_metric *metric
 
 static void *rslv_promex_start_ts(void *unused, unsigned int id)
 {
-       struct resolvers *resolver = LIST_NEXT(&sec_resolvers, struct resolvers *, list);
+       struct resolvers *resolver;
 
+       if (LIST_ISEMPTY(&sec_resolvers))
+               return NULL;
+
+       resolver = LIST_NEXT(&sec_resolvers, struct resolvers *, list);
        return LIST_NEXT(&resolver->nameservers, struct dns_nameserver *, list);
 }