php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49442 Some queries crash PHP with mysqli_real_connect()
Submitted: 2009-09-02 12:32 UTC Modified: 2009-09-16 17:10 UTC
From: vrana@php.net Assigned: mysql (profile)
Status: Closed Package: MySQLi related
PHP Version: 5.3.0 OS: Windows
Private report: No CVE-ID: None
 [2009-09-02 12:32 UTC] vrana@php.net
Description:
------------
LOAD DATA LOCAL INFILE query together with connecting by mysqli_real_connect() causes PHP crash. Maybe it is not the single crashing query but common queries like SELECT or INSERT work.

When I replace mysqli_init() + mysqli_real_connect() by mysqli_connect() then everything works (no crash).

Reproduce code:
---------------
<?php
$dbh = mysqli_init();
$dbh->real_connect("", "ODBC", "", "cds");
$dbh->query("LOAD DATA LOCAL INFILE 'songs.csv' INTO TABLE songs");
?>


Expected result:
----------------
Query executed OK.

Actual result:
--------------
PHP crashes.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-02 12:46 UTC] vrana@php.net
Backtrace analysis is available at http://www.vrana.cz/phpbug49442.zip
 [2009-09-02 13:21 UTC] pajoye@php.net
Please provide the create table and a small CSV to reproduce the problem.
 [2009-09-02 13:27 UTC] vrana@php.net
CREATE TABLE and sample CSV included in http://www.vrana.cz/phpbug49442.zip
 [2009-09-16 17:03 UTC] svn@php.net
Automatic comment from SVN on behalf of uw
Revision: http://svn.php.net/viewvc/?view=revision&revision=288379
Log: Fix (by Andrey) and test for bug #49442 . Don't use efree() for memory allocated with malloc()... If a connection gets created by mysqli_init(), mysqlnd makes it 'persistent'. 'Persistent' means that mysqlnd uses malloc(). mysqlnd does use malloc() instead of ealloc() because it is unknown if the connection will become a true persistent connection in the sense of ext/mysqli. It is unknown if the user wants a persistent connection or not until the user calls mysqli_real_connect(). To avoid tricky conversions mysqlnd uses malloc(), which sets a private persistent flag in the mysqlnd structures. A precondition for the crash to happen was that the private persistent flag is set. The flag is also set when creating a real persistent connection (in the sense of ext/mysqli) and so the bug can happen with mysql_init()/mysqli_real_connect() and mysql_connect('p:<host>', ...). Therefore we test both cases. Note the (tricky?) difference between the implementation detail'mysqlnd private persistent flag = use malloc()' and persistent connections from a user perspective. Although mysqlnd will always set its private persistent flag and  use malloc() for connections created with mysqli_init() it is still up to the user to decide in mysqli_real_connect() if the connection shall become a (true) persistent connection or not.
 [2009-09-16 17:10 UTC] uw@php.net
A patch has been committed to fix the problem. Please try the latest SVN snapshots.

The bug affects all operating systems. It is a mysqlnd bug. In theory it should be possible to cause the crash using any MySQL API that uses mysqlnd: ext/mysql, ext/mysqli, PDO_MYSQL. 

The crash happens both with connections created using mysqli_init() + mysqli_real_connect() and mysqli_connect("p:<host>", ...).


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 01 19:01:31 2024 UTC