php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #24535 Segmentation fault after second mysql_connect
Submitted: 2003-07-08 06:36 UTC Modified: 2003-07-22 11:07 UTC
From: artem at osp dot ru Assigned: georg (profile)
Status: Closed Package: MySQL related
PHP Version: 4.3.3RC2-dev OS: Linux 2.2.25
Private report: No CVE-ID: None
 [2003-07-08 06:36 UTC] artem at osp dot ru
Description:
------------
I need two connections to mysql server for processing big result trought mysql_unbuffered_query(). 
But on mysql_fetch_row() after second connect there is error.

php was configured:

./configure  --with-mysql=/opt/mysql --enable-track-vars --with-gd --with-zlib-dir=/usr/lib/ --enable-memory-limit --enable-debug --with-apache=../apache_1.3.27-ssl

mysql version 4.0.13
mysql was configured:

./configure '--prefix=/opt/mysql-4.0.13' '--with-mysqld-ldflags=-all-static' '--disable-shared' '--with-charset=cp1251' '--with-innodb' '--enable-local-inf
ile'


Reproduce code:
---------------
<?php
 function my_connect() {
  $s=@mysql_connect("localhost","<login>","<pass>",1);
  if(!$s) {
   echo "Troubes at connect to MySQL. ".mysql_error();
   exit;
  }
  if(!mysql_select_db("<DB>")) {
   echo "Troubes at select DB on MySQL. ".mysql_error();
   exit;
  }
  return $s;
 }
 ob_implicit_flush(1);
 echo "1<br>\n";
 my_connect();
 echo "2<br>\n";
 $res=mysql_unbuffered_query("select 'All ok'");
 echo "3<br>\n";
 if(!$res) {
  echo "Mysql say: ".mysql_error();
  exit;
 }
 my_connect();
 echo "4<br>\n";
 $row=mysql_fetch_row($res);
 echo "5<br>\n";
 echo $row[0];
?>


Expected result:
----------------
1
2
3
4
5
All ok

Actual result:
--------------
1
2
3
4

==========================
Segmentation fault
==========================
[www2:/opt/www/bin]:1087# gdb /opt/www/bin/httpd
GNU gdb 5.0
Copyright 2000 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux"...
(gdb) run -X
Starting program: /opt/www/bin/httpd -X

Program received signal SIGSEGV, Segmentation fault.
0x822263d in my_net_read ()
(gdb) bt
#0  0x822263d in my_net_read ()
#1  0x8217a1b in net_safe_read ()
#2  0x82185c8 in read_one_row ()
#3  0x821b92b in mysql_fetch_row ()
#4  0x80f667b in php_mysql_fetch_hash (ht=1, return_value=0x840ba7c,
    this_ptr=0x0, return_value_used=1, result_type=2, expected_args=1)
    at /usr/local/src/php-4.3.2-ssl/ext/mysql/php_mysql.c:1886
#5  0x80f689a in zif_mysql_fetch_row (ht=1, return_value=0x840ba7c,
    this_ptr=0x0, return_value_used=1)
    at /usr/local/src/php-4.3.2-ssl/ext/mysql/php_mysql.c:1937
#6  0x80b1adf in execute_internal (execute_data_ptr=0xbfffcca0,
    return_value_used=1)
    at /usr/local/src/php-4.3.2-ssl/Zend/zend_execute_API.c:42
#7  0x3452e2 in xdebug_execute_internal (current_execute_data=0xbfffcca0,
    return_value_used=1) at /tmp/tmprX1YIP/xdebug-1.2.0/xdebug.c:782
#8  0x80cbed1 in execute (op_array=0x840ac5c)
    at /usr/local/src/php-4.3.2-ssl/Zend/zend_execute.c:1608
#9  0x3451f6 in xdebug_execute (op_array=0x840ac5c)
    at /tmp/tmprX1YIP/xdebug-1.2.0/xdebug.c:750
#10 0x80bc28e in zend_execute_scripts (type=8, retval=0x0, file_count=3)
    at /usr/local/src/php-4.3.2-ssl/Zend/zend.c:869
#11 0x8092554 in php_execute_script (primary_file=0xbffff3b0)
    at /usr/local/src/php-4.3.2-ssl/main/main.c:1671
---Type <return> to continue, or q <return> to quit---
#12 0x80d0882 in apache_php_module_main (r=0x83f2f7c, display_source_mode=0)
    at /usr/local/src/php-4.3.2-ssl/sapi/apache/sapi_apache.c:54
#13 0x8088df0 in send_php ()
#14 0x8088e49 in send_parsed_php ()
#15 0x81d9fb7 in ap_invoke_handler ()
#16 0x81ef52b in process_request_internal ()
#17 0x81ef58c in ap_process_request ()
#18 0x81e620d in child_main ()
#19 0x81e63dc in make_child ()
#20 0x81e6550 in startup_children ()
#21 0x81e6bc8 in standalone_main ()
#22 0x81e7447 in main ()
#23 0x1eff31 in __libc_start_main (main=0x81e7084 <main>, argc=2,
    ubp_av=0xbffff7f4, init=0x808515c <_init>, fini=0x828de10 <_fini>,
    rtld_fini=0x11e274 <_dl_fini>, stack_end=0xbffff7ec)
    at ../sysdeps/generic/libc-start.c:129
(gdb)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-07-08 08:08 UTC] sniper@php.net
I could reproduce this with mysq 3.23.55 (Georg couldn't with mysql 4.0.13). Your PHP configure line points to --with-mysql=/opt/mysql, is that a symlink to /opt/mysql-4.0.13 ?? Check the linked client lib version
from phpinfo() output.


 [2003-07-08 08:14 UTC] sniper@php.net
Here is the backtrace I got:

0x408e7e66 in my_net_read (net=0x874d464) at net.c:647
647         net->buff[net->buf_length - net->remain_in_buf]=net->save_char;
(gdb) bt
#0  0x408e7e66 in my_net_read (net=0x874d464) at net.c:647
#1  0x408e242d in net_safe_read (mysql=0x874d464) at libmysql.c:302
#2  0x408e39b7 in read_one_row (mysql=0x874d464, fields=1, row=0x874ea98, lengths=0x874ea90) at libmysql.c:994
#3  0x408e5eba in mysql_fetch_row (res=0x874ea48) at libmysql.c:1986
#4  0x818be2c in php_mysql_fetch_hash (ht=1, return_value=0x874e914, this_ptr=0x0, return_value_used=1, result_type=2, 
    expected_args=1) at /usr/src/web/php/php4_3/ext/mysql/php_mysql.c:1895
#5  0x818c09a in zif_mysql_fetch_row (ht=1, return_value=0x874e914, this_ptr=0x0, return_value_used=1)
    at /usr/src/web/php/php4_3/ext/mysql/php_mysql.c:1946
#6  0x82e03a2 in execute (op_array=0x8748994) at /usr/src/web/php/php4_3/Zend/zend_execute.c:1616
#7  0x82cce34 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/src/web/php/php4_3/Zend/zend.c:886
#8  0x828fefe in php_execute_script (primary_file=0xbffff8bc) at /usr/src/web/php/php4_3/main/main.c:1685
#9  0x82f4367 in main (argc=2, argv=0xbffff924) at /usr/src/web/php/php4_3/sapi/cli/php_cli.c:818
#10 0x406689cb in __libc_start_main (main=0x82f37e4 <main>, argc=2, argv=0xbffff924, init=0x80ab2c0 <_init>, 
    fini=0x84525b4 <_fini>, rtld_fini=0x4000aea0 <_dl_fini>, stack_end=0xbffff91c)
    at ../sysdeps/generic/libc-start.c:92

 [2003-07-08 08:17 UTC] artem at osp dot ru
from phpinfo():

mysql 
MySQL Support enabled 
Active Persistent Links  1  
Active Links  1  
Client API version  4.0.13  
MYSQL_MODULE_TYPE  external  
MYSQL_SOCKET  /tmp/mysql.sock  
MYSQL_INCLUDE  -I/opt/mysql/include/mysql  
MYSQL_LIBS  -L/opt/mysql/lib/mysql -lmysqlclient  

about simlinks:
/opt/mysql is symlink to mysql-4.0.13
/opt/mysql-4.0.13 is symlink to /usr3/mysql-4.0.13/
 [2003-07-11 05:09 UTC] georg@php.net
Not sure if it's a php bug. I'll discuss it with MySQL developers on LT.
 [2003-07-22 11:07 UTC] iliaa@php.net
This bug has been fixed in CVS.

In case this was a PHP problem, snapshots of the sources are packaged
every three hours; this change will be in the next snapshot. You can
grab the snapshot at http://snaps.php.net/.
 
In case this was a documentation problem, the fix will show up soon at
http://www.php.net/manual/.

In case this was a PHP.net website problem, the change will show
up on the PHP.net site and on the mirror sites in short time.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 10 07:01:28 2024 UTC