summaryrefslogtreecommitdiff
path: root/src/network/lookup_name.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2020-08-04 14:20:40 -0400
committerRich Felker <dalias@aerifal.cx>2020-08-04 14:20:40 -0400
commit20c6d83f5566590a65895b4fa11bf31fee3dcc44 (patch)
tree92958212e92d7d14dd339d0df445c047958a5092 /src/network/lookup_name.c
parent73cc775bee53300c7cf759f37580220b18ac13d3 (diff)
downloadmusl-20c6d83f5566590a65895b4fa11bf31fee3dcc44.tar.gz
in hosts file lookups, use only first match for canonical name
the existing code clobbered the canonical name already discovered every time another matching line was found, which will necessarily be the case when a hostname has both IPv4 and v6 definitions. patch by Wolf.
Diffstat (limited to 'src/network/lookup_name.c')
-rw-r--r--src/network/lookup_name.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/network/lookup_name.c b/src/network/lookup_name.c
index aae0d95a..04624845 100644
--- a/src/network/lookup_name.c
+++ b/src/network/lookup_name.c
@@ -50,7 +50,7 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
{
char line[512];
size_t l = strlen(name);
- int cnt = 0, badfam = 0;
+ int cnt = 0, badfam = 0, have_canon = 0;
unsigned char _buf[1032];
FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf);
if (!f) switch (errno) {
@@ -83,11 +83,16 @@ static int name_from_hosts(struct address buf[static MAXADDRS], char canon[stati
continue;
}
+ if (have_canon) continue;
+
/* Extract first name as canonical name */
for (; *p && isspace(*p); p++);
for (z=p; *z && !isspace(*z); z++);
*z = 0;
- if (is_valid_hostname(p)) memcpy(canon, p, z-p+1);
+ if (is_valid_hostname(p)) {
+ have_canon = 1;
+ memcpy(canon, p, z-p+1);
+ }
}
__fclose_ca(f);
return cnt ? cnt : badfam;