php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55703 PHP crash when calling mysqli_fetch_fields
Submitted: 2011-09-15 15:12 UTC Modified: 2011-09-17 03:12 UTC
From: eran at zend dot com Assigned: laruence (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.8 OS: Linux Ubuntu 11.04
Private report: No CVE-ID: None
 [2011-09-15 15:12 UTC] eran at zend dot com
Description:
------------
Hi,

Running the attached test script causes a crash in mysqli extension (in every 
run).
The crash comes from mysqli_api.c, at around line 1058:

add_property_string(value, "catalog", (field->catalog ? field->catalog : ""), 
1);

The member field->catalog contains an address to an uninitialized pointer.
Debugging libmysqlclient (self compiled, v5.1.58) shows that 
libmysqlclient simply left this member uninitialized, thus pointing to an 
uninitialized memory.

To work around this bug, I modified my PHP sources locally so the "catalog" 
value is always set to "def" (which according to the documentation 
http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html is always 
true) 
(I also had a patch for libmysqlclient, but I am not sure where to send it...)

This crash is reproducible in CLI mode using the test script attached.
Attached is the patch to mysqli extension as well.



Test script:
---------------
<?php
$host  = '127.0.0.1';
$user  = 'user';
$pass  = 'password';
$db    = 'mydb';
$port  = 3306;
$link = mysqli_init();
if (mysqli_real_connect($link, $host, $user, $pass, $db, $port)) {
        $stmt = mysqli_stmt_init($link);
        if(mysqli_stmt_prepare($stmt, "show processlist")) {
                $res     = mysqli_stmt_execute($stmt);
                $res_set = mysqli_stmt_result_metadata($stmt);
                var_dump ( $res_set );
                var_dump(mysqli_fetch_fields( $res_set ));
        }
}



Patches

mysqli_patch (last revision 2011-09-15 15:13 UTC by eran at zend dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-09-16 08:51 UTC] laruence@php.net
-Status: Open +Status: Duplicate
 [2011-09-16 08:51 UTC] laruence@php.net
plz look at #55662. anyway seems not only "explain" statement cause this segfault
 [2011-09-16 19:41 UTC] eran at zend dot com
Agreed. Same crash as #55662

Can you apply the attached patch? The patch simply avoids accessing the uninitialized pointer and 
sets the value to "def" (which like I mentioned in my previous post, is always the correct value, 
see here: http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html)
 [2011-09-17 02:58 UTC] laruence@php.net
-Assigned To: +Assigned To: laruence
 [2011-09-17 02:58 UTC] laruence@php.net
in that case, then change it to always be "def" is okey, thanks :)
 [2011-09-17 03:12 UTC] laruence@php.net
Automatic comment from SVN on behalf of laruence
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=316895
Log: Fix Bug #55703(PHP crash when calling mysqli_fetch_fields)
Since the catalog values always is &quot;def&quot; now, see http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html
 [2011-09-17 03:12 UTC] laruence@php.net
-Status: Duplicate +Status: Closed
 [2011-09-17 03:12 UTC] laruence@php.net
This bug has been fixed in SVN.

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

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:48 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=212d210ac936ab617e3e354db748b4893af3a1a4
Log: Fix Bug #55703(PHP crash when calling mysqli_fetch_fields) Since the catalog values always is &quot;def&quot; now, see http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html
 [2012-07-24 23:39 UTC] rasmus@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=212d210ac936ab617e3e354db748b4893af3a1a4
Log: Fix Bug #55703(PHP crash when calling mysqli_fetch_fields) Since the catalog values always is &quot;def&quot; now, see http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html
 [2013-11-17 09:36 UTC] laruence@php.net
Automatic comment on behalf of laruence
Revision: http://git.php.net/?p=php-src.git;a=commit;h=212d210ac936ab617e3e354db748b4893af3a1a4
Log: Fix Bug #55703(PHP crash when calling mysqli_fetch_fields) Since the catalog values always is &quot;def&quot; now, see http://dev.mysql.com/doc/refman/5.0/en/c-api-data-structures.html
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Nov 11 05:01:28 2024 UTC