Subject: Re: [PATCH] Fix lookup with HOSTALIASES set.

Re: [PATCH] Fix lookup with HOSTALIASES set.

From: Tommie Gannert <tommie_at_spotify.com>
Date: Thu, 23 Sep 2010 19:11:33 +0200

Mike Crowe wrote:
> ares__read_line returns ARES_EOF when it reaches the end of the
> file. This will happen every time when reading to the end of the
> HOSTALIASES file. Unfortunately single_domain treats this error as
> being fatal.
>
It looks to me you are right. ares__read_line() returns ARES_EOF
when fgets() returns NULL.

> Signed-off-by: Mike Crowe <mac_at_mcrowe.com>
> ---
> ares_search.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/ares_search.c b/ares_search.c
> index aa233dd..608cb15 100644
> --- a/ares_search.c
> +++ b/ares_search.c
> @@ -287,7 +287,7 @@ static int single_domain(ares_channel channel, const char *name, char **s)
> }
> free(line);
> fclose(fp);
> - if (status != ARES_SUCCESS)
> + if (status != ARES_SUCCESS && status != ARES_EOF)
> return status;
> }
> else
>
There are no breaks in the ares__read_line() loop, so the ARES_SUCCESS will
never happen there. But it's probably wrong to return ARES_SUCCESS there
in the future, so I suggest going with the above patch.

Checking other files using ares__read_line:

ares__get_hostent.c: while ((status = ares__read_line(fp, &line,
&linesize)) == ARES_SUCCESS)

The function will return ARES_EOF if no match was found. Should be fine,
but maybe
not the nicest error. gethostent(3glibc) returns HOST_NOT_FOUND.

ares_init.c: while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS)
ares_init.c: while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS)
ares_init.c: while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS)
ares_init.c: while ((status = ares__read_line(fp, &line, &linesize)) ==
ARES_SUCCESS)

ARES_EOF explicitly handled.

-- 
Tommie Gannert
Team Lead, Backend Engineering
Spotify
This e-mail (including any attachments) may contain information that is
confidential and/or privileged. It is intended only for the recipient(s).
If you have reason to believe that you are not the intended recipient of
this e-mail, please contact the sender immediately and delete the e-mail
from your computer.

Received on 2010-09-23