Skip to content

Commit

Permalink
[Minor] Rdns: Fix parsing of nameserver lines
Browse files Browse the repository at this point in the history
Issue: #2762
Closes: #2762
  • Loading branch information
vstakhov committed Feb 22, 2019
1 parent 43c67de commit bbf92ed
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions contrib/librdns/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,16 +537,17 @@ rdns_resolver_conf_process_line (struct rdns_resolver *resolver,
const char *line, rdns_resolv_conf_cb cb, void *ud)
{
const char *p, *c, *end;
bool has_obrace = false;
bool has_obrace = false, ret;
unsigned int port = dns_port;
char *cpy_buf;

end = line + strlen (line);

if (end - line > sizeof ("nameserver") - 1 &&
strncmp (line, "nameserver", sizeof ("nameserver") - 1) == 0) {
p = line + sizeof ("nameserver") - 1;
/* Skip spaces */
while (*p == ' ' || *p == '\t') {
while (isspace (*p)) {
p ++;
}

Expand Down Expand Up @@ -578,14 +579,23 @@ rdns_resolver_conf_process_line (struct rdns_resolver *resolver,
}
}

cpy_buf = malloc (p - c + 1);
assert (cpy_buf != NULL);
memcpy (cpy_buf, c, p - c);
cpy_buf[p - c] = '\0';

if (cb == NULL) {
return rdns_resolver_add_server (resolver, c, port, 0,
ret = rdns_resolver_add_server (resolver, cpy_buf, port, 0,
default_io_cnt) != NULL;
}
else {
return cb (resolver, c, port, 0,
ret = cb (resolver, cpy_buf, port, 0,
default_io_cnt, ud);
}

free (cpy_buf);

return ret;
}
else {
return false;
Expand Down

0 comments on commit bbf92ed

Please sign in to comment.