Subject: Re: Little WIN32 BUG in ares_init()

Re: Little WIN32 BUG in ares_init()

From: Guilherme Balena Versiani <guibv_at_comunip.com.br>
Date: Mon, 06 Nov 2006 18:48:06 -0200

Daniel Stenberg escreveu:
> On Fri, 3 Nov 2006, Guilherme Balena Versiani wrote:
>
>> - When there are no network interface at all, the function
>> ares_init() returns -1, an invalid ares error value.
>>
>> I attached the tiny patch as a suggestion to solve it.
>
> Aha. But even Windows offer name resolves on a hosts file, right? So I
> guess the even better approach would be to allow c-ares to do only
> file-based resolves for this case... Wouldn't it?
>
Right. But I think the user must be notified of this condition. This
condition would inform the application to call ares_init() again on next
resolution process. A better solution could be to implement a test
condition to check if the network parameters has changed; if so, the
ares library updates its internal data.

A possible use case:
 - The application informs user about a name resolution error and a
possible lack of network connectivity. The user fix the network
connectivity, but does not restart the application (a most common case).
If the application does not call ares_init() again, then all following
DNS resolutions will fail. A hint to call ares_init() again, could be an
specific 'status' issued by ares_init() for first time.

The above situation forces me to not reuse the ares channel and call
ares_init() whenever I want to resolve a DNS name. This situation does
not improve the Windows DNS resolution performance (it is worse than
gethostbyname/getaddrinfo 'native' code): whenever I call ares_init(),
the iphlpapi.dll is loaded/unloaded (LoadLibrary/FreeLibrary), and the
Windows registry is opened.

I forgot to send a rational about last BUG report:

- When there are no available network interfaces, the
ares_init.c:get_iphlpapi_dns_info() function gets no DNS servers at all,
then the "if (IS_NT())" code block (ares_init.c, line 459) is executed.
If the Windows is NT platform, then the RegOpenKeyEx() block code, line
466, issues no DNS servers again, and the variable "status" is not
changed. I didn't tested the Windows 98 code block, but inspecting it, I
think the behavior is the same. As that variable is initiated with "-1",
per line 413, then the resulting status is "-1", an invalid ares error
code. Worse, if you try to call ares_strerror() to get more information
about that error, you will read memory out of bounds (-1 is an invalid
index of the errtext variable in ares_strerror() function, at
ares_strerror.c, line 25).

Regards,

Guilherme Balena Versiani.

Received on 2006-11-06