This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: getaddrinfo : Non-recoverable failure in name resolution


Hi Marco,

On Jun 23 13:41, Marco Atzeri wrote:
> Hi,
> the attached two test programs should perform exactly the same call
> to getaddrinfo for 127.0.0.1
> 
> however on 32 bit
> CYGWIN_NT-6.1-WOW64 1.7.30(0.272/5/3) 2014-05-23 10:36 i686 Cygwin
> 
>  32 $ ./getaddrinfo_test-1_32
> 127.0.0.1 ai_addr
> 02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00
> 
>  32 $ ./getaddrinfo_test-2_32
> 127.0.0.1 ai_addr
> 02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00
> 
> while on 64 bit
> CYGWIN_NT-6.1 1.7.30(0.272/5/3) 2014-05-23 10:36 x86_64 Cygwin
> 
> 64 $ ./getaddrinfo_test-1_64
> 127.0.0.1 ai_addr
> 02 00 00 00 7f 00 00 01 00 00 00 00 00 00 00 00
> 
> 64 $ ./getaddrinfo_test-2_64
> getaddrinfo: Non-recoverable failure in name resolution
> 
> 
> Am I missing something ?
> The second way is currently used on postgresql in several places,
> but it seems to fail only for "127.0.0.1"

I don't know why this only fails for "127.0.0.1".  But this is clearly a
problem in the 64 bit Cygwin DLL.

What happens is that the field ai_addrlen is defined as socklen_t in
POSIX, but as size_t in the W32 API.  On 64 bit, socklen_t is 4 bytes
while size_t is 8 bytes.  Setting all the hintp members manually (in
contrast to calloc'ing it or memset'ing it to 0) leaves the 4 upper
bytes of the ai_addrlen untouched.  This in turn leads to a high
probability that ai_addrlen has an invalid value when entering Winsock's
getsockopt.

I'm really surprised this hasn't been hit before.  I'm going to fix that
in Cygwin by setting the upper 4 bytes of ai_addrlen to 0 explicitely.

For the time being, you might prepend

  memset (&hintp, 0, sizeof hintp);

to the code, prior to setting the elements manually.


Thanks for the testcase.  Much appreciated,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

Attachment: pgpYFA_Pnak5u.pgp
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]