public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* getaddrinfo : Non-recoverable failure in name resolution
@ 2014-06-23 11:42 Marco Atzeri
  2014-06-23 12:25 ` Corinna Vinschen
  0 siblings, 1 reply; 6+ messages in thread
From: Marco Atzeri @ 2014-06-23 11:42 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 795 bytes --]

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"

Regards
Marco

[-- Attachment #2: getaddrinfo_test-1.c --]
[-- Type: text/plain, Size: 909 bytes --]


#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int rc,i,l;
const char *hostname="127.0.0.1";
const char *servname="";
struct addrinfo *hintp;
/* struct addrinfo *resultp; */
struct addrinfo **result;

char *addr;

hintp=calloc(1,sizeof(struct addrinfo ));
/*
resultp=calloc(1,sizeof(struct addrinfo ));
result=&resultp;
*/
hintp->ai_flags = 4;
hintp->ai_family = 0;
hintp->ai_socktype = 0;
hintp->ai_protocol = 0;
hintp->ai_addrlen = 0;
hintp->ai_canonname = 0x0;
hintp->ai_addr = 0x0;
hintp->ai_next = 0x0;

rc = getaddrinfo(hostname, servname, hintp, result);

if (!rc)
	{ 
	printf("127.0.0.1 ai_addr\n");
	l=(*result)->ai_addrlen;
	addr=(char*)(*result)->ai_addr;
	for(i=0;i<l;i++)
		printf("%2.2x ",addr[i]);
	printf("\n");
	}
else
	{
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rc));
        exit(EXIT_FAILURE);
	}
}


[-- Attachment #3: getaddrinfo_test-2.c --]
[-- Type: text/plain, Size: 902 bytes --]


#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
int rc,i,l;
const char *hostname="127.0.0.1";
const char *servname="";
struct addrinfo hintp;
/* struct addrinfo *resultp; */
struct addrinfo *result=NULL;

char *addr;

/*
hintp=calloc(1,sizeof(struct addrinfo ));
resultp=calloc(1,sizeof(struct addrinfo ));
result=&resultp;
*/

hintp.ai_flags = 4;
hintp.ai_family = 0;
hintp.ai_socktype = 0;
hintp.ai_protocol = 0;
hintp.ai_addrlen = 0;
hintp.ai_canonname = 0x0;
hintp.ai_addr = 0x0;
hintp.ai_next = 0x0;

rc = getaddrinfo(hostname, servname, &hintp, &result);

if (!rc)
	{ 
	printf("127.0.0.1 ai_addr\n");
	l=result->ai_addrlen;
	addr=(char*)result->ai_addr;
	for(i=0;i<l;i++)
		printf("%2.2x ",addr[i]);
	printf("\n");
	}
else
	{
        fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rc));
        exit(EXIT_FAILURE);
	}
}



[-- Attachment #4: Type: text/plain, Size: 218 bytes --]

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getaddrinfo : Non-recoverable failure in name resolution
  2014-06-23 11:42 getaddrinfo : Non-recoverable failure in name resolution Marco Atzeri
@ 2014-06-23 12:25 ` Corinna Vinschen
  2014-06-23 13:07   ` Marco Atzeri
  0 siblings, 1 reply; 6+ messages in thread
From: Corinna Vinschen @ 2014-06-23 12:25 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1954 bytes --]

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 #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getaddrinfo : Non-recoverable failure in name resolution
  2014-06-23 12:25 ` Corinna Vinschen
@ 2014-06-23 13:07   ` Marco Atzeri
  2014-06-23 13:44     ` Corinna Vinschen
  2014-06-23 16:16     ` Ken Brown
  0 siblings, 2 replies; 6+ messages in thread
From: Marco Atzeri @ 2014-06-23 13:07 UTC (permalink / raw)
  To: cygwin


On 23/06/2014 14:25, Corinna Vinschen wrote:
> Hi Marco,
>
> On Jun 23 13:41, Marco Atzeri wrote:

>>
>> 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.

Probably we have seen already but not identified.

> For the time being, you might prepend
>
>    memset (&hintp, 0, sizeof hintp);
>
> to the code, prior to setting the elements manually.

I will wait next snapshot.
PostgreSQL 9.4 is still on Beta 1, so I am not in a hurry to release
a new version


> Thanks for the testcase.  Much appreciated,
> Corinna

Thanks for the solution
Marco

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getaddrinfo : Non-recoverable failure in name resolution
  2014-06-23 13:07   ` Marco Atzeri
@ 2014-06-23 13:44     ` Corinna Vinschen
  2014-06-23 16:16     ` Ken Brown
  1 sibling, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2014-06-23 13:44 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1582 bytes --]

On Jun 23 15:07, Marco Atzeri wrote:
> 
> On 23/06/2014 14:25, Corinna Vinschen wrote:
> >Hi Marco,
> >
> >On Jun 23 13:41, Marco Atzeri wrote:
> 
> >>
> >>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.
> 
> Probably we have seen already but not identified.
> 
> >For the time being, you might prepend
> >
> >   memset (&hintp, 0, sizeof hintp);
> >
> >to the code, prior to setting the elements manually.
> 
> I will wait next snapshot.

Generated.


Thanks,
Corinna

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

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getaddrinfo : Non-recoverable failure in name resolution
  2014-06-23 13:07   ` Marco Atzeri
  2014-06-23 13:44     ` Corinna Vinschen
@ 2014-06-23 16:16     ` Ken Brown
  2014-06-23 16:24       ` Corinna Vinschen
  1 sibling, 1 reply; 6+ messages in thread
From: Ken Brown @ 2014-06-23 16:16 UTC (permalink / raw)
  To: cygwin

On 6/23/2014 9:07 AM, Marco Atzeri wrote:
>
> On 23/06/2014 14:25, Corinna Vinschen wrote:
>> Hi Marco,
>>
>> On Jun 23 13:41, Marco Atzeri wrote:
>
>>>
>>> 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.
>
> Probably we have seen already but not identified.

I wonder if this could explain the mysterious emacs crashes that have 
been reported on 64-bit Cygwin.  The emacs code does set the hintp 
members manually in some places.

The crashes seem to occur randomly, and the backtraces often don't make 
sense.

Ken

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: getaddrinfo : Non-recoverable failure in name resolution
  2014-06-23 16:16     ` Ken Brown
@ 2014-06-23 16:24       ` Corinna Vinschen
  0 siblings, 0 replies; 6+ messages in thread
From: Corinna Vinschen @ 2014-06-23 16:24 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 1780 bytes --]

On Jun 23 12:15, Ken Brown wrote:
> On 6/23/2014 9:07 AM, Marco Atzeri wrote:
> >
> >On 23/06/2014 14:25, Corinna Vinschen wrote:
> >>Hi Marco,
> >>
> >>On Jun 23 13:41, Marco Atzeri wrote:
> >
> >>>
> >>>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.
> >
> >Probably we have seen already but not identified.
> 
> I wonder if this could explain the mysterious emacs crashes that have been
> reported on 64-bit Cygwin.  The emacs code does set the hintp members
> manually in some places.
> 
> The crashes seem to occur randomly, and the backtraces often don't make
> sense.

A crash shouldn't occur, only getaddrinfo returning EAI_FAIL.


Corinna

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

[-- Attachment #2: Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-06-23 16:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-23 11:42 getaddrinfo : Non-recoverable failure in name resolution Marco Atzeri
2014-06-23 12:25 ` Corinna Vinschen
2014-06-23 13:07   ` Marco Atzeri
2014-06-23 13:44     ` Corinna Vinschen
2014-06-23 16:16     ` Ken Brown
2014-06-23 16:24       ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).