]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: resolvers: shut off the warning for the default resolvers
authorWilliam Lallemand <wlallemand@haproxy.org>
Mon, 18 Jul 2022 12:12:17 +0000 (14:12 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Mon, 18 Jul 2022 12:39:36 +0000 (14:39 +0200)
When the resolv.conf file is empty or there is no resolv.conf file, an
empty resolvers will be created, which emits a warning during the
postparsing step.

This patch fixes the problem by freeing the resolvers section if the
parsing failed or if the nameserver list is empty.

Must be backported in 2.6, the previous patch which introduces
resolvers_destroy() is also required.

src/resolvers.c

index ce08479317eeb811654e976299bdf616cac638bc..c7267aafca015f882ec4d65439442af0369a2abc 100644 (file)
@@ -3671,13 +3671,31 @@ int resolvers_create_default()
 {
        int err_code = 0;
 
+       /* if the section already exists, do nothing */
        if (find_resolvers_by_id("default"))
                return 0;
 
+       curr_resolvers = NULL;
        err_code |= resolvers_new(&curr_resolvers, "default", "<internal>", 0);
-       if (!(err_code & ERR_CODE))
-               err_code |= parse_resolve_conf(NULL, NULL);
+       if (err_code & ERR_CODE)
+               goto err;
+       err_code |= parse_resolve_conf(NULL, NULL);
+       if (err_code & ERR_CODE)
+               goto err;
+       /* check if there was any nameserver in the resolvconf file */
+       if (LIST_ISEMPTY(&curr_resolvers->nameservers)) {
+               err_code |= ERR_FATAL;
+               goto err;
+       }
+
+err:
+       if (err_code & ERR_CODE) {
+               resolvers_destroy(curr_resolvers);
+               curr_resolvers = NULL;
+       }
 
+       /* we never return an error there, we only try to create this section
+        * if that's possible */
        return 0;
 }