1 From 4219adeeef8a3d5447af4c9bd1e4e7c05b3112fd Mon Sep 17 00:00:00 2001
2 From: Simon Kelley <simon@thekelleys.org.uk>
3 Date: Wed, 27 Feb 2019 20:30:21 +0000
4 Subject: [PATCH 33/57] Fix line counting when reading /etc/hosts.
6 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
9 src/cache.c | 16 ++++++++--------
10 2 files changed, 12 insertions(+), 8 deletions(-)
14 @@ -17,6 +17,10 @@ version 2.81
15 combinatorial explosion of compile-time options. Thanks to
16 Kevin Darbyshire-Bryant for the patch.
18 + Fix line-counting when reading /etc/hosts and friends; for
19 + correct error messages. Thanks to Christian Rosentreter
24 Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method
27 @@ -1062,7 +1062,7 @@ static int eatspace(FILE *f)
36 @@ -1073,7 +1073,7 @@ static int gettok(FILE *f, char *token)
39 if ((c = getc(f)) == EOF)
40 - return (count == 0) ? EOF : 1;
41 + return (count == 0) ? -1 : 1;
43 if (isspace(c) || c == '#')
45 @@ -1093,7 +1093,7 @@ int read_hostsfile(char *filename, unsig
47 FILE *f = fopen(filename, "r");
48 char *token = daemon->namebuff, *domain_suffix = NULL;
49 - int addr_count = 0, name_count = cache_size, lineno = 0;
50 + int addr_count = 0, name_count = cache_size, lineno = 1;
51 unsigned int flags = 0;
53 int atnl, addrlen = 0;
54 @@ -1104,12 +1104,10 @@ int read_hostsfile(char *filename, unsig
59 + lineno += eatspace(f);
61 - while ((atnl = gettok(f, token)) != EOF)
62 + while ((atnl = gettok(f, token)) != -1)
66 if (inet_pton(AF_INET, token, &addr) > 0)
68 flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
69 @@ -1145,7 +1143,7 @@ int read_hostsfile(char *filename, unsig
73 - if ((atnl = gettok(f, token)) == EOF)
74 + if ((atnl = gettok(f, token)) == -1)
77 fqdn = !!strchr(token, '.');
78 @@ -1178,6 +1176,8 @@ int read_hostsfile(char *filename, unsig
80 my_syslog(LOG_ERR, _("bad name at %s line %d"), filename, lineno);