From: Vladimír Čunát Date: Fri, 24 Jun 2022 07:29:38 +0000 (+0200) Subject: hints.add_hosts(): respect comments anywhere in a line X-Git-Tag: v5.5.2~13^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98ef6d78aa9cf2e86408de071101624e139c36cf;p=thirdparty%2Fknot-resolver.git hints.add_hosts(): respect comments anywhere in a line --- diff --git a/NEWS b/NEWS index b0a3b467a..5a9523fb5 100644 --- 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) diff --git a/modules/hints/hints.c b/modules/hints/hints.c index eb79a3d67..7bdcd2ca3 100644 --- a/modules/hints/hints.c +++ b/modules/hints/hints.c @@ -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);