Opened 6 years ago

Closed 6 years ago

#548 closed defect (wontfix)

A wrong server config in upstream get an error ip addr

Reported by: leo liu Owned by:
Priority: minor Milestone:
Component: nginx-core Version: 1.4.x
Keywords: Cc:
uname -a: Linux 3.5.0-44-generic #67~precise1-Ubuntu SMP Wed Nov 13 16:16:57 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
nginx -V: nginx version: nginx/1.4.4
built by gcc 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
TLS SNI support enabled
configure arguments: --with-debug

Description

in an upstream config like :
upstream test{

server 1181;
keepalive 256;

}

then nginx get an backend address 0.0.4.157

(gdb) n
1100 h = gethostbyname((char *) host);
(gdb) p host
$17 = (u_char *) 0x1021cd0 "1181"
(gdb) n
1102 ngx_free(host);
(gdb) p h
$18 = (struct hostent *) 0x7ffff66c0f00
(gdb) p *h
$19 = {h_name = 0x1028a18 "1181", h_aliases = 0x1028a10, h_addrtype = 2, h_length = 4, h_addr_list = 0x1028a00}
(gdb) p h->h_addr_list[0]
$20 = 0x10289f0 ""
(gdb) x/10c (h->h_addr_list[0])
0x10289f0: 0 '\000' 0 '\000' 4 '\004' -99 '\235' 0 '\000' 0 '\000' 0 '\000' 0 '\000'
...
(gdb)
1129 sin->sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);

Here nginx get the ip address 0.0.4.157.

Problem is gethostbyname return an empty string,not NULL。Maybe test "if (h == NULL
h->h_addr_list[0] == NULL)" at line 926 is wrong!

Change History (1)

comment:1 by Ruslan Ermilov, 6 years ago

Resolution: wontfix
Status: newclosed

1181 is 4*256+157, that is 0.0.4.157 IPv4 address as per inet_addr(3). Both gethostbyname(3) and getaddrinfo(3) understand this format as well. You can verify this with "ping 1181" or "telnet 1181".

Note: See TracTickets for help on using tickets.