cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: Bug in libcurl (7.8.1) under Windows...

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 3 Oct 2001 23:48:28 +0200 (MET DST)

On Wed, 3 Oct 2001, Keith McGuigan wrote:

> I've been working with libcurl and I've come across a bug in the library.
> The problem is with the use of gethostbyname() on the windows platform when
> calling curl_easy_perform() from within a thread. In hostip.c, you call
> gethostbyname() and store the returned 'struct hostent *' into the
> 'connectdata' struct. This struct is then stored in the list of open
> connections to possibly be reused. The problem is, the hostent structure
> pointer returned by gethostbyname() refers to data that is deallocated when
> the thread finishes (under windows anyway... I haven't had any problems under
> Linux yet...).

That problem won't happen on Linux (or any other modern operating system I
know of actually) as the configure script will detect and use the
gethostbyname_r() function instead which doesn't use the static version of
the hostent struct.

> Thus, if you try to reuse this connection from another thread after the
> first thread has finished, the 'hp' member of the connectdata structure
> contains garbage, and chaos ensues.

It will indeed. My compliments on a very fine bug report and a very fine fix
indeed. I've committed your fix to CVS just now.

> A solution is to perform a deep copy on the hostent structure returned by
> gethostbyname(), and then store and use that copy instead. I created a
> pack_hostent() function that will use the existing (but unused) data
> buffer (the 'hostent_buf' in connectdata) to copy the hostent structure
> into.

It makes perfect use of that memory!

> I'll attach a patch of the file hostip.c (feel free to use or ignore it).

Many thanks for this.

> Also, I found the Makefile.vc6 file included in the curl-7.8.1 tarball to
> be a bit inadequate. I've made some (major) edits to enable it to build
> 'debug', 'release', 'debug-ssl', and 'release-ssl' using nmake and cl.
> I'll send it to you if you're interested.

You really should try 7.9 first. But if you have improvements that go beyond
what's in there, we are of course interested. I know people have expressed
that the VC++ makefiles leave a lot to add, but so far no one has stopped
whining and actually made them any better... ;-)

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-10-03