|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2010-08-05 22:04 UTC] rgagnon24 at gmail dot com
Description: ------------ Fix for bug 51213 released into 5.2.14 and 5.3.3 causes segmentation fault when an SQL query attempts to read MSSQL MONEY type columns, or aggregates of those column types. Problem appears to be invalid val->data pointer passed to spprintf() call at line 174 of dblib_stmt.c Oddly, the patch attached to bug 51213 works properly, but is not the same as what was comitted to the code base. In the patch attached to 51213, val->data is properly emalloc'd some memory before any sprintf()-type of operation is performed. Test script: --------------- // On a table containing a MONEY (field named "amount"); $sql = "SELECT SUM(amount) FROM table"; $rs = $pdo->query($sql, PDO::FETCH_OBJ); foreach($rs as $row) { var_dump($row); } Expected result: ---------------- Expected to see rows dumped from table. Actual result: -------------- Segmentation fault. Patchesfix_pdo_dblib_MONEY_seg_fault_5.2.14 (last revision 2010-08-06 16:17 UTC by rgagnon24 at gmail dot com)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 11:00:01 2025 UTC |
Here's a fix. Test code --------- <?php $dbh = new PDO('dblib:dbname=DB;host=HOST', 'USER', 'PASS'); $sth = $dbh->query ('create table #tmp(col money)'); $sth = $dbh->query ('insert into #tmp(col) values(123.25)'); $sth = $dbh->query ('insert into #tmp(col) values(-123.25)'); $sth = $dbh->prepare('SELECT col FROM #tmp'); $sth->execute(); $r = $sth->fetchAll(2); print_r($r); --------- Output --------- Array ( [0] => Array ( [col] => 123.2500 ) [1] => Array ( [col] => -123.2500 ) ) --------- Diff --------- --- php-5.3.3/ext/pdo_dblib/dblib_stmt.c 2010-03-08 13:39:44.000000000 +0100 +++ ../php-5.3.3/ext/pdo_dblib/dblib_stmt.c 2010-08-10 15:18:48.000000000 +0200 @@ -170,8 +170,10 @@ case SQLMONEY4: case SQLMONEYN: { DBFLT8 money_value; + val->len = (2 * dbdatlen(H->link, i + 1)) + 32; + val->data = emalloc(val->len); dbconvert(NULL, S->cols[i].coltype, dbdata(H->link, i+1), dbdatlen(H->link, i+1), SQLFLT8, (LPBYTE)&money_value, val->len); - val->len = spprintf(val->data, 0, "%.4f", money_value); + val->len = sprintf(val->data, "%.4f", money_value); } break; default: ---------