cURL / Mailing Lists / curl-users / Single Mail

curl-users

[ curl-Bugs-696217 ] Result from gethostbyname_r on AIX is not safe for caching

From: SourceForge.net <noreply_at_sourceforge.net>
Date: Sun, 02 Mar 2003 13:46:26 -0800

Bugs item #696217, was opened at 2003-03-02 22:46
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=696217&group_id=976

Category: libcurl
Group: portability problem
Status: Open
Resolution: None
Priority: 5
Submitted By: Troels Walsted Hansen (troels)
Assigned to: Daniel Stenberg (bagder)
Summary: Result from gethostbyname_r on AIX is not safe for caching

Initial Comment:
libcurl provided unreliable operation on AIX 4.3.3 and
5.1, entries in the DNS cache appeared to randomly
point to the wrong host.

After a lot of instrumentation and research, the
problem was found to be gethostbyname_r() in the AIX
standard library.

According to an IBM engineer in the Usenet posting
below, gethostbyname_r() is a wrapper around
gethostbyname().

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3B7BCE0B.DF8D5E4E%40us.noibm.com

It seems that gethostbyname() writes results to a
per-thread allocated area which makes it thread safe.
The gethostbyname_r() wrapper is supposed to copy this
data into the malloc'ed buffer provided by curl. It
seems that it performs a shallow copy, rather than the
deep copy performed by curl's own pack_hostent() function.

This means that pointers in the returned hostent
structure point to the shared gethostbyname() buffer,
and is therefore overwritten by calls to this function.

Witness the below output from the attached program on
AIX 4.3.3 and 5.1. This shows that while the hostent
h_name pointer changes, h_addr_list stays constant and
is overwritten by interleaved gethostbyname() calls.

The fix must be to disable use of gethostbyname_r() on
AIX 4.3.3 and higher. Using gethostbyname() and curl's
own pack_hostent() provides both thread- and cache-safe
DNS lookups.

I don't know anything about earlier AIX versions.

$ ./gethostbyname_r
gethostbyname_r("bigblue.oslo.fast.no", ...)
ret: 0
name: bigblue.oslo.fast.no
name: 0x2001e03d
addr_list: 0x2001df0c

gethostbyname("happy.oslo.fast.no")
he3: 0x2001def8
name: happy.oslo.fast.no
name: 0x2001e03b
addr_list: 0x2001df0c

gethostbyname_r("bluemaster.oslo.fast.no", ...)
ret: 0
name: bluemaster.oslo.fast.no
name: 0x2001e040
addr_list: 0x2001df0c

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=100976&aid=696217&group_id=976

-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf
Received on 2003-03-02