Bug 4916

Summary: gethostbyname fails with Segmentation fault in special conditions
Product: uClibc Reporter: perfectflow
Component: NetworkingAssignee: Bernhard Reutner-Fischer <aldot>
Status: RESOLVED FIXED    
Severity: major CC: uclibc-cvs
Priority: P5    
Version: 0.9.32.1   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Host: Target:
Build:

Description perfectflow 2012-03-13 21:31:25 UTC
Buildroot with uClibc 0.9.33, i386/i586, optimized by size, gcc 4.4.6

How to reproduce:
1) add long string into /etc/hosts. For example:
##############################################################################

2) compile and run this test:
--------------------------------------
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include <netdb.h>
       
int main(void)
{
	int i;
	struct hostent *h;

	for(i=1;i<100;i++)
	{
		printf("i=%i\n",i);
		h = gethostbyname( "aaaaaaaaaaaaaaaaaaaaa.com");
	}	

}
--------------------------------------

3) Run it, usually it fails with:

i=1
i=2
Segmentation fault
Comment 1 perfectflow 2012-03-14 07:24:50 UTC
> How to reproduce:
> 1) add long string into /etc/hosts. For example:
> ##############################################################################
sorry, I mistaken here, line for /etc/hosts which causes error is:

1.1.1.1	a aa aaa aaaa aaaaa

Segmentation fault appeares if IP in /etc/hosts has more than 4 aliases
Comment 2 Bernhard Reutner-Fischer 2012-04-17 16:50:55 UTC
Should be fixed on master in dcb6ac13546486099fd1c5fb83771cb69f2a16b7
Please confirm.

Note that we default to a maximum of 4 aliases.
So
1.1.1.1  canonname1 alias1 alias2 alias3 aaaaaaaaaaaaaaaaaaaaa.com concated7
will be seen as "aaaaaaaaaaaaaaaaaaaaa.com concated7" and thus go to a remote server (and fail there).

Perhaps we should either raise that to, let's say, 8 or make it configurable more easily..