18b176837d3cd38549edc52302c4e57e1078478b
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 0033-Fix-line-counting-when-reading-etc-hosts.patch
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.
5
6 Signed-off-by: Kevin Darbyshire-Bryant <ldir@darbyshire-bryant.me.uk>
7 ---
8 CHANGELOG | 4 ++++
9 src/cache.c | 16 ++++++++--------
10 2 files changed, 12 insertions(+), 8 deletions(-)
11
12 --- a/CHANGELOG
13 +++ b/CHANGELOG
14 @@ -17,6 +17,10 @@ version 2.81
15 combinatorial explosion of compile-time options. Thanks to
16 Kevin Darbyshire-Bryant for the patch.
17
18 + Fix line-counting when reading /etc/hosts and friends; for
19 + correct error messages. Thanks to Christian Rosentreter
20 + for reporting this.
21 +
22
23 version 2.80
24 Add support for RFC 4039 DHCP rapid commit. Thanks to Ashram Method
25 --- a/src/cache.c
26 +++ b/src/cache.c
27 @@ -1062,7 +1062,7 @@ static int eatspace(FILE *f)
28 }
29
30 if (c == '\n')
31 - nl = 1;
32 + nl++;
33 }
34 }
35
36 @@ -1073,7 +1073,7 @@ static int gettok(FILE *f, char *token)
37 while (1)
38 {
39 if ((c = getc(f)) == EOF)
40 - return (count == 0) ? EOF : 1;
41 + return (count == 0) ? -1 : 1;
42
43 if (isspace(c) || c == '#')
44 {
45 @@ -1093,7 +1093,7 @@ int read_hostsfile(char *filename, unsig
46 {
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;
52 union all_addr addr;
53 int atnl, addrlen = 0;
54 @@ -1104,12 +1104,10 @@ int read_hostsfile(char *filename, unsig
55 return cache_size;
56 }
57
58 - eatspace(f);
59 + lineno += eatspace(f);
60
61 - while ((atnl = gettok(f, token)) != EOF)
62 + while ((atnl = gettok(f, token)) != -1)
63 {
64 - lineno++;
65 -
66 if (inet_pton(AF_INET, token, &addr) > 0)
67 {
68 flags = F_HOSTS | F_IMMORTAL | F_FORWARD | F_REVERSE | F_IPV4;
69 @@ -1145,7 +1143,7 @@ int read_hostsfile(char *filename, unsig
70 int fqdn, nomem;
71 char *canon;
72
73 - if ((atnl = gettok(f, token)) == EOF)
74 + if ((atnl = gettok(f, token)) == -1)
75 break;
76
77 fqdn = !!strchr(token, '.');
78 @@ -1178,6 +1176,8 @@ int read_hostsfile(char *filename, unsig
79 else if (!nomem)
80 my_syslog(LOG_ERR, _("bad name at %s line %d"), filename, lineno);
81 }
82 +
83 + lineno += atnl;
84 }
85
86 fclose(f);