Bug #74376 [NEW]: Invalid free of persistent results on error/connection loss
| From: | dev at pp3345 dot net | Date: | Wed, 05 Apr 2017 18:51:15 +0000 |
| Subject: | Bug #74376 [NEW]: Invalid free of persistent results on error/connection loss | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-208344@lists.php.net to get a copy of this message | ||
From: dev at pp3345 dot net
Operating system: Irrelevant
PHP version: 7.1.3
Package: MySQL related
Bug Type: Bug
Bug description:Invalid free of persistent results on error/connection loss
Description:
------------
mysqlnd allocates result objects in mysqlnd_result.c:1899
(mysqlnd_result_init):
MYSQLND_RES * ret = mnd_pecalloc(1, alloc_size, persistent);
Note that these objects may be allocated persistently if the underlying
connection is persistent. Normally these objects will be free'd in
mysqlnd_result.c:347 (mysqlnd_res::free_result_internal):
mnd_pefree(result, result->persistent);
Here, the persistency flag is respected.
However, in some cases (query errors or connection loss), mysqlnd_ps.c
will use mnd_efree() instead of mnd_pefree() to free a result object:
line 132 (mysqlnd_stmt::store_result):
mnd_efree(stmt->result);
line 359 (mysqlnd_stmt_prepare_read_eof):
mnd_efree(stmt->result);
This will cause segfaults/"zend_mm_heap corrupted" in the
above-mentioned cases.
Test script:
---------------
<?php
$conn = new PDO("mysql:...", "...", "...", [PDO::ATTR_PERSISTENT =>
true, PDO::ATTR_EMULATE_PREPARES => false]);
$conn->query("select (select 1 union select 2)");
Expected result:
----------------
Script executes successfully.
Actual result:
--------------
segfault
--
Edit bug report at https://bugs.php.net/bug.php?id=74376&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74376&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74376&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74376&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74376&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74376&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74376&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74376&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74376&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74376&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74376&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74376&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74376&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74376&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74376&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74376&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74376&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74376&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74376&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74376&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74376&r=mysqlcfg