Skip to content
Snippets Groups Projects
Commit ffdd55a9 authored by Vladimír Čunát's avatar Vladimír Čunát
Browse files

hints.add_hosts: error out if a bad entry is encountered

parent 1c189d65
Branches
Tags
1 merge request!309hints: reverse lookup keep name ordering from host file
Pipeline #9128 canceled with stages
in 1 hour, 17 minutes, and 35 seconds
......@@ -12,6 +12,7 @@ Bugfixes
- policy.FORWARD and STUB: use RTT tracking to choose servers (#125, #208)
- dns64: fix CNAME problems (#203) It still won't work with query policies.
- hints: better interpretation of hosts-like files (#204)
also, error out if a bad entry is encountered in the file
Improvements
------------
......
......@@ -342,6 +342,7 @@ static int load_file(struct kr_module *module, const char *path)
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) {
++line_count;
......@@ -352,26 +353,40 @@ static int load_file(struct kr_module *module, const char *path)
}
const char *canonical_name = strtok_r(NULL, " \t\n", &saveptr);
if (canonical_name == NULL) {
ERR_MSG("%s:%zu: invalid syntax\n", path, line_count);
continue;
ret = -1;
goto error;
}
/* Since the last added PTR records takes preference,
* we add canonical name as the last one. */
const char *name_tok;
while ((name_tok = strtok_r(NULL, " \t\n", &saveptr)) != NULL) {
if (add_pair(&data->hints, name_tok, addr) == 0) {
count += 1;
ret = add_pair(&data->hints, name_tok, addr);
if (!ret) {
ret = add_reverse_pair(&data->reverse_hints, name_tok, addr);
}
if (ret) {
ret = -1;
goto error;
}
add_reverse_pair(&data->reverse_hints, name_tok, addr);
}
if (add_pair(&data->hints, canonical_name, addr) == 0) {
count += 1;
}
add_reverse_pair(&data->reverse_hints, canonical_name, addr);
ret = add_pair(&data->hints, canonical_name, addr);
if (!ret) {
ret = add_reverse_pair(&data->reverse_hints, canonical_name, addr);
}
if (ret) {
ret = -1;
goto error;
}
count += 1;
}
error:
if (ret) {
ret = kr_error(ret);
ERR_MSG("%s:%zu: invalid syntax\n", path, line_count);
}
VERBOSE_MSG(NULL, "loaded %zu hints\n", count);
return kr_ok();
return ret;
}
static char* hint_add_hosts(void *env, struct kr_module *module, const char *args)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment