microsoft / msphpsql

Microsoft Drivers for PHP for SQL Server
MIT License
1.8k stars 374 forks source link

SEGMENTATION FAULT when using array with keys #1465

Open GDmac opened 1 year ago

GDmac commented 1 year ago

Possible fix: This should throw an Exception not a hard crash on SEGMENTATION FAULT

When parameter is an array with string keys, the driver crashes hard with a segmentation fault. php 7.4 driver 5.10 but this seems NOT fixed in later recent drivers (not tested).

$params = [ 442502 ];
// bool true

$params = [ array(442502) ];
// bool true

$params = [ array('id' => 442502) ];
// SQLerror: Parameter array 1 must have at least one value or variable

$params = [ array('id' => 442502, 'foo' => 'bar') ];
// SEGMENTATION FAULT: 11 !!!!!

$res = sqlsrv_query($conn, "SELECT id FROM product WHERE id = ?", $params);
if (sqlsrv_errors()) var_dump(sqlsrv_errors());
var_dump(sqlsrv_has_rows($res));
v-makouz commented 1 year ago

I can reproduce this, and will investigate further.

v-makouz commented 1 year ago

We know where the error is, so now it's a matter of applying the fix.

GDmac commented 1 year ago

can the fix be back-ported to 5.10 (5.10.1 ?) too - some of our projects will remain on old PHP 😬