]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
hints.add_hosts(): respect comments anywhere in a line
authorVladimír Čunát <vladimir.cunat@nic.cz>
Fri, 24 Jun 2022 07:29:38 +0000 (09:29 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Thu, 7 Jul 2022 17:12:49 +0000 (19:12 +0200)
NEWS
modules/hints/hints.c

diff --git a/NEWS b/NEWS
index b0a3b467ae2f59591335a4ff2097cd661d232593..5a9523fb532a103a69983ccdc08bdbc005230be1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Bugfixes
 --------
 - daemon/http: improved URI checks to fix some proxies (#746, !1311)
 - daemon/tls: fixed a double-free for some cases of policy.TLS_FORWARD (!1314)
+- hints module: improve parsing comments in hosts files (!1315)
 
 
 Knot Resolver 5.5.1 (2022-06-14)
index eb79a3d67e37744c4f88cc7613bd2c0da3ab3162..7bdcd2ca3f42e603c5e0eec57d87f8f812f94c9d 100644 (file)
@@ -322,17 +322,23 @@ static int load_file(struct kr_module *module, const char *path)
 
        /* Load file to map */
        struct hints_data *data = module->data;
-       size_t line_len = 0;
+       size_t line_len_unused = 0;
        size_t count = 0;
        size_t line_count = 0;
        auto_free char *line = NULL;
        int ret = kr_ok();
 
-       while (getline(&line, &line_len, fp) > 0) {
+       while (getline(&line, &line_len_unused, fp) > 0) {
                ++line_count;
+               /* Ingore #comments as described in man hosts.5 */
+               char *comm = strchr(line, '#');
+               if (comm) {
+                       *comm = '\0';
+               }
+
                char *saveptr = NULL;
                const char *addr = strtok_r(line, " \t\n", &saveptr);
-               if (addr == NULL || strchr(addr, '#') || strlen(addr) == 0) {
+               if (addr == NULL || strlen(addr) == 0) {
                        continue;
                }
                const char *canonical_name = strtok_r(NULL, " \t\n", &saveptr);