1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00

resolv: Move __res_context_hostalias into its own file and into libc

And reformat it to GNU style.  Remove the unecessary setbuf call.
Use __fgets_unlocked for PLT avoidance; no locking is required here.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
Florian Weimer
2021-07-19 07:55:27 +02:00
parent 7131727c6b
commit be5773e166
5 changed files with 135 additions and 42 deletions

View File

@@ -635,46 +635,6 @@ res_querydomain (const char *name, const char *domain, int class, int type,
(__resolv_context_get (), name, domain, class, type, answer, anslen);
}
const char *
__res_context_hostalias (struct resolv_context *ctx,
const char *name, char *dst, size_t siz)
{
char *file, *cp1, *cp2;
char buf[BUFSIZ];
FILE *fp;
if (ctx->resp->options & RES_NOALIASES)
return (NULL);
file = getenv("HOSTALIASES");
if (file == NULL || (fp = fopen(file, "rce")) == NULL)
return (NULL);
setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';
while (fgets(buf, sizeof(buf), fp)) {
for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
;
if (!*cp1)
break;
*cp1 = '\0';
if (__libc_ns_samename(buf, name) == 1) {
while (isspace(*++cp1))
;
if (!*cp1)
break;
for (cp2 = cp1 + 1; *cp2 && !isspace(*cp2); ++cp2)
;
*cp2 = '\0';
strncpy(dst, cp1, siz - 1);
dst[siz - 1] = '\0';
fclose(fp);
return (dst);
}
}
fclose(fp);
return (NULL);
}
libresolv_hidden_def (__res_context_hostalias)
/* Common part of res_hostalias and hostalias. */
static const char *
context_hostalias_common (struct resolv_context *ctx,