php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38393 Segmentation Fault when using curl_close in an object context
Submitted: 2006-08-09 05:49 UTC Modified: 2006-12-30 06:16 UTC
Votes:5
Avg. Score:5.0 ± 0.0
Reproduced:5 of 5 (100.0%)
Same Version:3 (60.0%)
Same OS:2 (40.0%)
From: asubstitute at gmail dot com Assigned:
Status: No Feedback Package: cURL related
PHP Version: 5.1.4 OS: RHEL4
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-08-09 05:49 UTC] asubstitute at gmail dot com
Description:
------------
When I run "php /www/curltest.php" I see a Segmentation Fault. If I put "echo $this->responseData" before the call to curl_close, I see the response data. If I remove the call to curl_close, the script segfaults at the end, due to curl_close being called automatically.

cURL was compiled from the newest tarball. This bug exists in the 5.2 snapshot too.

php -v : PHP 5.1.4 (cgi-fcgi) (built: Aug  9 2006 00:24:52)

Reproduce code:
---------------
class curlTest {
	function __construct($url) {
		$this->responseData = null;
		$this->responseError = false;
		$this->curl = curl_init();
		curl_setopt($this->curl, CURLOPT_URL, $url);		
	}
	function makeRequest() {
		$this->responseData = curl_exec($this->curl);
		curl_close($this->curl);
	}
}
$interface = new curlTest("http://www.google.com/explanation.html");
$interface->makeRequest();

Expected result:
----------------
Nothing

Actual result:
--------------
Segmentation Fault

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-08-09 05:56 UTC] joey@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php for *NIX and
http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

I could not reproduce this crash on debian i386, debian
amd64, or SLED 10 i386. Seeking backtrace.
 [2006-08-09 06:28 UTC] asubstitute at gmail dot com
==backtrace==

(gdb) bt
#0  0x0056a008 in SSL_SESSION_hash () from /lib/libssl.so.4
#1  0x004311c4 in lh_free () from /lib/libcrypto.so.4
#2  0x00431333 in lh_delete () from /lib/libcrypto.so.4
#3  0x0056e131 in SSL_CTX_get_timeout () from /lib/libssl.so.4
#4  0x004312ae in lh_retrieve () from /lib/libcrypto.so.4
#5  0x0056e1e7 in SSL_CTX_flush_sessions () from /lib/libssl.so.4
#6  0x0056a192 in SSL_CTX_free () from /lib/libssl.so.4
#7  0x002a6fbd in Curl_ossl_close (conn=0x98d2f98) at ssluse.c:724
#8  0x002b6489 in Curl_ssl_close (conn=0x98d2f98) at sslgen.c:381
#9  0x002a1281 in Curl_disconnect (conn=0x98d2f98) at url.c:1634
#10 0x002a26f7 in ConnectionKillOne (data=0x98d5d70) at url.c:1835
#11 0x002a2743 in Curl_close (data=0x98d5d70) at url.c:203
#12 0x002af8f9 in curl_easy_cleanup (curl=0x98d5d70) at easy.c:485
#13 0x080dc1b5 in _php_curl_close (rsrc=0x98cce44) at /home/rixth/php-5.1.4/ext/curl/interface.c:1736
#14 0x08291da1 in list_entry_destructor (ptr=0x98cce44) at /home/rixth/php-5.1.4/Zend/zend_list.c:184
#15 0x0828f484 in zend_hash_del_key_or_index (ht=0x86ab080, arKey=0x0, nKeyLength=0, h=1, flag=1)
    at /home/rixth/php-5.1.4/Zend/zend_hash.c:492
#16 0x08291b3c in _zend_list_delete (id=1) at /home/rixth/php-5.1.4/Zend/zend_list.c:58
#17 0x080dc192 in zif_curl_close (ht=1, return_value=0x98cc81c, return_value_ptr=0x0, this_ptr=0x0,
    return_value_used=0) at /home/rixth/php-5.1.4/ext/curl/interface.c:1721
#18 0x082a22d1 in zend_do_fcall_common_helper_SPEC (execute_data=0xbff2c2d0)
    at /home/rixth/php-5.1.4/Zend/zend_vm_execute.h:200
#19 0x082a1c3d in execute (op_array=0x98ce404) at /home/rixth/php-5.1.4/Zend/zend_vm_execute.h:92
#20 0x082a1e91 in zend_do_fcall_common_helper_SPEC (execute_data=0xbff2c490)
    at /home/rixth/php-5.1.4/Zend/zend_vm_execute.h:234
#21 0x082a1c3d in execute (op_array=0x98c83c4) at /home/rixth/php-5.1.4/Zend/zend_vm_execute.h:92
#22 0x08287b76 in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /home/rixth/php-5.1.4/Zend/zend.c:1109
#23 0x0824e838 in php_execute_script (primary_file=0xbff30be0) at /home/rixth/php-5.1.4/main/main.c:1732
#24 0x0830fa44 in main (argc=2, argv=0xbff30cb4) at /home/rixth/php-5.1.4/sapi/cgi/cgi_main.c:1608
(gdb)


If I use procedural code like this, it works fine.

$curl = curl_init();
$curl_setopt($curl, CURLOPT_URL, "http://www.google.com/explanation.html");		
$responseData = curl_exec($curl);
if (curl_errno($curl)) {
	$responseData = null;
	$responseError = curl_error($curl);
}
else {
	curl_close($curl);
}
 [2006-08-09 07:48 UTC] mike@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5.2-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5.2-win32-latest.zip

Can't reproduce either.
 [2006-08-09 07:48 UTC] mike@php.net
Even looks like an OpenSSL problem.
 [2006-08-09 08:37 UTC] tony2001@php.net
What was your configure line?
 [2006-08-09 10:32 UTC] asubstitute at gmail dot com
Look in my inital post, see I tried the snapshot code too. (RIght before I submitted this)

The procedural code above works only for HTTP urls.

HTTPS cause a segfault (though both protocols make the OOP version die)

I can run curl from the command line, and it works fine. Indicating it is unlikely to be a libcurl issue.
Curl info from phpinfo. libcurl/7.15.5 OpenSSL/0.9.7a zlib/1.2.3 libidn/0.5.6

Server: lighttpd 1.4.11

./configure' '--enable-fastcgi' '--enable-discard-path' '--enable-force-redirect' '--enable-exif' '--enable-ftp' '--with-dom' '--enable-sockets' '--enable-memory-limit' '--enable-mbstring' '--with-gettext' '--with-mime-magic' '--with-iconv' '--with-gd=/usr' '--with-ttf' '--with-freetype-dir=/usr/X11R6' '--enable-gd-native-ttf' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6/lib' '--with-mysql=/usr/lib' '--with-zlib' '--with-curl' '--with-curlwrappers' '--with-expat-dir=/usr' '--with-xsl' '--with-bz2' '--with-openssl' '--enable-debug'
 [2006-08-09 10:56 UTC] tony2001@php.net
Does it work if you build it without MySQL support?
 [2006-08-09 11:13 UTC] asubstitute at gmail dot com
When compiling. (WITH mysql) but I had just upgraded OpenSSL to 0.9b (from0.7a).

Going to try without myself now.

/usr/local/ssl/lib/libcrypto.a(cryptlib.o)(.text+0x224): In function `CRYPTO_lock':
: multiple definition of `CRYPTO_lock'
/usr/lib/mysql/libmysqlclient.a(libtaocrypt_la-misc.o)(.text+0x54):/home/mysqldev/rpm/BUILD/mysql-5.0.24/extra/yassl/taocrypt/src/misc.cpp:33: first defined here
/usr/bin/ld: Warning: size of symbol `CRYPTO_lock' changed from 7 in /usr/lib/mysql/libmysqlclient.a(libtaocrypt_la-misc.o) to 283 in /usr/local/ssl/lib/libcrypto.a(cryptlib.o)
/usr/local/ssl/lib/libcrypto.a(cryptlib.o)(.text+0x340): In function `CRYPTO_add_lock':
: multiple definition of `CRYPTO_add_lock'
/usr/lib/mysql/libmysqlclient.a(libtaocrypt_la-misc.o)(.text+0x5c):/home/mysqldev/rpm/BUILD/mysql-5.0.24/extra/yassl/taocrypt/src/misc.cpp:34: first defined here
/usr/bin/ld: Warning: size of symbol `CRYPTO_add_lock' changed from 7 in /usr/lib/mysql/libmysqlclient.a(libtaocrypt_la-misc.o) to 98 in /usr/local/ssl/lib/libcrypto.a(cryptlib.o)
/usr/local/ssl/lib/libcrypto.a(bn_lib.o)(.text+0xc08): In function `BN_bin2bn':
: multiple definition of `BN_bin2bn'
/usr/lib/mysql/libmysqlclient.a(ssl.o)(.text+0x1d3c):/home/mysqldev/rpm/BUILD/mysql-5.0.24/extra/yassl/src/ssl.cpp:757: first defined here
/usr/bin/ld: Warning: size of symbol `BN_bin2bn' changed from 178 in /usr/lib/mysql/libmysqlclient.a(ssl.o) to 447 in /usr/local/ssl/lib/libcrypto.a(bn_lib.o)
collect2: ld returned 1 exit status
make: *** [sapi/cgi/php] Error 1

real    3m41.666s
user    2m55.375s
sys     0m48.024s
[root@86335-app6 php-5.1.4]#
 [2006-08-09 11:35 UTC] asubstitute at gmail dot com
Install now segfaults.

I have tried extracting the source again  but got the same error.

$: php -v
Segmentation fault

Installing PHP SAPI module:       cgi
Installing PHP CGI into: /usr/local/bin/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
make[1]: *** [install-pear-installer] Segmentation fault
make: *** [install-pear] Error 2
[root@86335-app6 php-5.1.4]#
 [2006-08-09 11:47 UTC] tony2001@php.net
You're using the latest snapshot, right?
 [2006-08-09 11:59 UTC] asubstitute at gmail dot com
Ah no, these have been the 5.1.4 tarball...

Ill try 5.2 WITH MySQL and WITHOUT as it seems to be the thing which causes the segfault on installing (without mysql installs fine, with fails)
 [2006-08-09 12:08 UTC] asubstitute at gmail dot com
With MySQL (note that compilng without mysql is a total no no for production)

Installing PHP SAPI module:       cgi
Installing PHP CGI into: /usr/local/bin/
Installing build environment:     /usr/local/lib/php/build/
Installing header files:          /usr/local/include/php/
Installing helper programs:       /usr/local/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/lib/php/
--07:06:56--  http://pear.php.net/install-pear-nozlib.phar
           => `pear/install-pear-nozlib.phar'
Resolving pear.php.net... 216.92.131.66
Connecting to pear.php.net|216.92.131.66|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3,167,908 (3.0M) [text/plain]

100%[====================================>] 3,167,908     84.98K/s    ETA 00:00

07:07:31 (88.43 KB/s) - `pear/install-pear-nozlib.phar' saved [3167908/3167908]

make[1]: *** [install-pear-installer] Segmentation fault
make: *** [install-pear] Error 2
[root@86335-app6 php5.2-200608091030]#
 [2006-08-09 12:09 UTC] asubstitute at gmail dot com
Without --with-mysql and --with-openssl, the script works fine (with https)
 [2006-08-09 12:11 UTC] tony2001@php.net
Yes, please try 5.2 snapshot without MySQL.
MySQL has recently replaced OpenSSL with YaSSL in their binary builds and I suspect this is the reason of the issue you're facing.
 [2006-08-09 21:01 UTC] asubstitute at gmail dot com
I updated:
* MySQL-devel package
* OpenSSL
* libcurl

Compiled with --with-mysql and not with --open-ssl.

Install worked.

Https worked with curl. THe cause of this bug is still TBD.
 [2006-08-09 21:30 UTC] tony2001@php.net
I'd appreaciate if you try this:
1) install Mysql 5.0.13;
or
2) build any MySQL version > 5.0.13 from sources.
And then rebuild PHP with --with-mysql.
If this would work for you, then the cause is clearly in MySQL. See http://bugs.mysql.com/bug.php?id=19817.
 [2006-08-17 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-12-30 06:16 UTC] darkelder@php.net
It is caused by mySQL version. I did tested with MySQL 5.0.27-0 and it worked by CGI. As CLI it worked by at curl_close it gives segmentation fault yet. I did not testes but at http://bugs.mysql.com/bug.php?id=19817  they told it is fixed in mySQL CVS.
 [2007-01-26 12:02 UTC] kot at hacktest dot net
I have got the same issue with small clarifications. 

When I try to use mod_php, all works fine: curl receive both http and https documents.

But when I ask my hoster to recompile php into CGI mode (it was needed for another purposes), script works fine for http retrieving, but failed for https. 

Fails is appeared about curl_close() call. No errors or notifications, core dumped. MySQL version is the same for mod and cgi: 5.0.27.

Please let me know if you need any additional info, and I'll try to provide it as far as possible.

P.S. 
OS FreeBSD 6.1-RELEASE-p6 
PHP Version 5.1.6, 5.2.0 (too). 

Coppiling without --with-mysql helps (curl works fine), but it is not good-enough solution -- I need MySQL too.

In any case: why it works fine for mod_php, and failed for cgi?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 14:01:28 2024 UTC