php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54221 mysqli::get_warnings segfault when used in multi queries
Submitted: 2011-03-11 09:39 UTC Modified: 2011-03-17 11:32 UTC
From: glen at delfi dot ee Assigned: mysql (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-03-11 09:39 UTC] glen at delfi dot ee
Description:
------------
http://php.net/manual/en/mysqli.get-warnings.php

can't use mysqli::get_warnings with multi queries reliably as it will get either 
segfault or empty result.

the code is supposed to print 2 times warning:
"Warning: 1050: Table 'a' already exists"
"Warning: 1050: Table 'a' already exists"

but instead it segfaults (PHP 5.3.5).

also if i run queries where only one warning is printed. it will not segfault. 
segfault seems to happen in ->next() call.

seems is because internally this is implemented as "SHOW WARNINGS" query [1]

[1] http://svn.php.net/viewvc/php/php-
src/branches/PHP_5_3/ext/mysqli/mysqli_warning.c?annotate=306939#l76

segfault must be fixed, but regarding the usage, perhaps document that you can't 
use it sanely with multi queries, due limitations of mysql protocol, as seems it 
is problem in mysql protocol, that it returns warnings only from last of the 
multi query

Test script:
---------------
<?php
$dbh = new mysqli(null, null, null, "test");
if ($dbh->connect_error) {
        die('Connect Error (' . $dbh->connect_errno . ') ' . $dbh->connect_error);
}

$create = "create temporary table if not exists a (a int4)";
$query = "$create;$create";$create;";
if ($dbh->multi_query($query)) {
        do {
                $sth = $dbh->store_result();

                if ($dbh->warning_count) {
                        $e = $dbh->get_warnings();
                        do {
                                echo "Warning: $e->errno: $e->message\n"; 
                        } while ($e->next()); 
                }
        } while ($dbh->next_result());
}
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-17 11:06 UTC] andrey@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: mysql
 [2011-03-17 11:06 UTC] andrey@php.net
Reproduced
 [2011-03-17 11:28 UTC] andrey@php.net
Automatic comment from SVN on behalf of andrey
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=309339
Log: Fix for bug #54221 mysqli::get_warnings segfault when used in multi queries
 [2011-03-17 11:32 UTC] andrey@php.net
-Status: Assigned +Status: Closed
 [2011-03-17 11:32 UTC] andrey@php.net
Fixed. The fix will be part of 5.3.7.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 23:01:36 2024 UTC