Bug 691 - gethostbyname() fails if DNS server returns 30 addresses
Summary: gethostbyname() fails if DNS server returns 30 addresses
Status: RESOLVED FIXED
Alias: None
Product: uClibc
Classification: Unclassified
Component: Networking (show other bugs)
Version: 0.9.30.1
Hardware: All Linux
: P3 normal
Target Milestone: 0.9.31
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-11-04 19:49 UTC by Leonid
Modified: 2010-03-17 12:22 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
Proposed patch (1.97 KB, patch)
2009-11-04 19:49 UTC, Leonid
Details
Proposed patch - 2 (4.68 KB, patch)
2009-11-07 15:11 UTC, Leonid
Details
smallish example (1.34 KB, text/plain)
2010-03-17 12:21 UTC, Bernhard Reutner-Fischer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leonid 2009-11-04 19:49:33 UTC
Created attachment 713 [details]
Proposed patch

I discover that an old 1468 issue (http://lists.busybox.net/pipermail/uclibc-cvs/2007-August/024363.html) which probably lost in bugzilla, was not fixed completely in commit http://git.uclibc.org/uClibc/commit/?id=f09a1461fe8f3511750ad91f164b2769225858f5

In my case, DNS returned 30 records, which fits in 512 bytes buffer successfully, but later can't be decoded in gethostbyname_r() - internal error is ERANGE ("buffer too small for all addresses").

Sample ISP host used - unlim.is74.ru

Proposed patch increases static buffer in gethostbyname() up to required value and saves 0.5k static buffer space in case of IPv6 turned on.
Comment 1 Leonid 2009-11-07 15:11:48 UTC
Created attachment 723 [details]
Proposed patch - 2

Improved resolv-fix-2.patch use common shared buffer, allocated by __uc_malloc(), for gethostbyname, gethostbyname2, gethostbyaddr, gethostent non-reentrant functions. This saves approx. 1.5k of static space in .bss
Comment 2 Bernhard Reutner-Fischer 2010-03-17 12:21:24 UTC
Created attachment 1309 [details]
smallish example

works fine on current master.

$ ./xgcc.sh -DNAME2 -Os -o gethostbyname2 gethostbyname.c 
$ ./gethostbyname2 unlim.is74.ru
name   : unlim.is74.ru
fam    : 2
addrlen: 4
addr   : 78.29.3.115
addr   : 78.29.3.116
addr   : 78.29.3.117
addr   : 78.29.3.118
addr   : 78.29.3.119
addr   : 78.29.3.122
addr   : 78.29.3.124
addr   : 78.29.3.3
addr   : 78.29.3.4
addr   : 78.29.3.7
addr   : 78.29.3.9
addr   : 78.29.3.10
addr   : 78.29.3.11
addr   : 78.29.3.12
addr   : 78.29.3.13
addr   : 78.29.3.14
addr   : 78.29.3.16
addr   : 78.29.3.18
addr   : 78.29.3.19
addr   : 78.29.3.21
addr   : 78.29.3.27
addr   : 78.29.3.33
addr   : 78.29.3.35
addr   : 78.29.3.37
addr   : 78.29.3.41
addr   : 78.29.3.42
addr   : 78.29.3.44
addr   : 78.29.3.45
addr   : 78.29.3.46
addr   : 78.29.3.47
total 30 addresses
aliases: unlim.is74.ru
$ ./xgcc.sh -Os -o gethostbyname gethostbyname.c 
/tmp/ccY6ZTg9.o: In function `main':
gethostbyname.c:(.text+0x4c): warning: gethostbyname_r is obsolescent, use getnameinfo() instead.
$ ./gethostbyname unlim.is74.ru
name   : unlim.is74.ru
fam    : 2
addrlen: 4
addr   : 78.29.3.110
addr   : 78.29.3.115
addr   : 78.29.3.116
addr   : 78.29.3.117
addr   : 78.29.3.118
addr   : 78.29.3.119
addr   : 78.29.3.122
addr   : 78.29.3.124
addr   : 78.29.3.3
addr   : 78.29.3.4
addr   : 78.29.3.7
addr   : 78.29.3.9
addr   : 78.29.3.10
addr   : 78.29.3.11
addr   : 78.29.3.12
addr   : 78.29.3.13
addr   : 78.29.3.14
addr   : 78.29.3.16
addr   : 78.29.3.18
addr   : 78.29.3.19
addr   : 78.29.3.21
addr   : 78.29.3.27
addr   : 78.29.3.33
addr   : 78.29.3.35
addr   : 78.29.3.37
addr   : 78.29.3.41
addr   : 78.29.3.42
addr   : 78.29.3.44
addr   : 78.29.3.45
addr   : 78.29.3.46
total 30 addresses
aliases: unlim.is74.ru