cURL / Mailing Lists / curl-users / Single Mail

curl-users

Bug in libcurl (7.8.1) under Windows...

From: Keith McGuigan <keith.mcguigan_at_ecora.com>
Date: Wed, 3 Oct 2001 17:14:10 -0400

Hello,

  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...). 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.

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.

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

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.

Other than that - great tool so far! :)

-- 
- Keith
Received on 2001-10-03