mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 18:28:25 +00:00
Fix line counting when reading /etc/hosts.
This commit is contained in:
@@ -17,6 +17,10 @@ version 2.81
|
||||
combinatorial explosion of compile-time options. Thanks to
|
||||
Kevin Darbyshire-Bryant for the patch.
|
||||
|
||||
Fix line-counting when reading /etc/hosts and friends; for
|
||||
correct error messages. Thanks to Christian Rosentreter
|
||||
for reporting this.
|
||||
|
||||
|
||||
version 2.80
|
||||
Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method
|
||||
|
||||
16
src/cache.c
16
src/cache.c
@@ -1062,7 +1062,7 @@ static int eatspace(FILE *f)
|
||||
}
|
||||
|
||||
if (c == '\n')
|
||||
nl = 1;
|
||||
nl++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1073,7 +1073,7 @@ static int gettok(FILE *f, char *token)
|
||||
while (1)
|
||||
{
|
||||
if ((c = getc(f)) == EOF)
|
||||
return (count == 0) ? EOF : 1;
|
||||
return (count == 0) ? -1 : 1;
|
||||
|
||||
if (isspace(c) || c == '#')
|
||||
{
|
||||
@@ -1093,7 +1093,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
|
||||
{
|
||||
FILE *f = fopen(filename, "r");
|
||||
char *token = daemon->namebuff, *domain_suffix = NULL;
|
||||
int addr_count = 0, name_count = cache_size, lineno = 0;
|
||||
int addr_count = 0, name_count = cache_size, lineno = 1;
|
||||
unsigned int flags = 0;
|
||||
union all_addr addr;
|
||||
int atnl, addrlen = 0;
|
||||
@@ -1104,12 +1104,10 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
|
||||
return cache_size;
|
||||
}
|
||||
|
||||
eatspace(f);
|
||||
lineno += eatspace(f);
|
||||
|
||||
while ((atnl = gettok(f, token)) != EOF)
|
||||
while ((atnl = gettok(f, token)) != -1)
|
||||
{
|
||||
lineno++;
|
||||
|
||||
if (inet_pton(AF_INET, token, &addr) > 0)
|
||||
{
|
||||
flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
|
||||
@@ -1145,7 +1143,7 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
|
||||
int fqdn, nomem;
|
||||
char *canon;
|
||||
|
||||
if ((atnl = gettok(f, token)) == EOF)
|
||||
if ((atnl = gettok(f, token)) == -1)
|
||||
break;
|
||||
|
||||
fqdn = !!strchr(token, '.');
|
||||
@@ -1178,6 +1176,8 @@ int read_hostsfile(char *filename, unsigned int index, int cache_size, struct cr
|
||||
else if (!nomem)
|
||||
my_syslog(LOG_ERR, _("bad name at %s line %d"), filename, lineno);
|
||||
}
|
||||
|
||||
lineno += atnl;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
Reference in New Issue
Block a user