Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions ext/intl/common/common_date.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ U_CFUNC TimeZone *timezone_convert_datetimezone(int type,
}
/* }}} */

U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
U_CFUNC zend_result intl_datetime_decompose(zend_object *obj, double *millis, TimeZone **tz,
intl_error *err, const char *func)
{
zval retval;
zval zfuncname;
char *message;
php_date_obj *datetime = php_date_obj_from_obj(obj);

if (err && U_FAILURE(err->code)) {
return FAILURE;
Expand All @@ -109,35 +108,35 @@ U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
*millis = ZEND_NAN;
}
if (tz) {
*tz = NULL;
*tz = nullptr;
}

if (millis) {
php_date_obj *datetime;

ZVAL_STRING(&zfuncname, "getTimestamp");
if (call_user_function(NULL, z, &zfuncname, &retval, 0, NULL)
!= SUCCESS || Z_TYPE(retval) != IS_LONG) {
spprintf(&message, 0, "%s: error calling ::getTimeStamp() on the "
"object", func);
intl_errors_set(err, U_INTERNAL_PROGRAM_ERROR,
message, 1);
auto getTimestampMethod = static_cast<zend_function *>(zend_hash_str_find_ptr(&obj->ce->function_table, ZEND_STRL("gettimestamp")));
zval retval;

ZEND_ASSERT(getTimestampMethod && "DateTimeInterface is sealed and thus must have this method");
zend_call_known_function(getTimestampMethod, obj, obj->ce, &retval, 0, nullptr, nullptr);

/* An exception has occurred */
if (Z_TYPE(retval) == IS_UNDEF) {
return FAILURE;
}
// TODO: Remove this when DateTimeInterface::getTimestamp() no longer has a tentative return type
if (Z_TYPE(retval) != IS_LONG) {
spprintf(&message, 0, "%s: %s::getTimestamp() did not return an int", func, ZSTR_VAL(obj->ce->name));
intl_errors_set(err, U_INTERNAL_PROGRAM_ERROR, message, 1);
efree(message);
zval_ptr_dtor(&zfuncname);
return FAILURE;
}

datetime = Z_PHPDATE_P(z);
*millis = U_MILLIS_PER_SECOND * (double)Z_LVAL(retval) + (datetime->time->us / 1000);
zval_ptr_dtor(&zfuncname);
}

if (tz) {
php_date_obj *datetime;
datetime = Z_PHPDATE_P(z);
if (!datetime->time) {
spprintf(&message, 0, "%s: the %s object is not properly "
"initialized", func, ZSTR_VAL(Z_OBJCE_P(z)->name));
"initialized", func, ZSTR_VAL(obj->ce->name));
intl_errors_set(err, U_ILLEGAL_ARGUMENT_ERROR,
message, 1);
efree(message);
Expand Down Expand Up @@ -198,7 +197,7 @@ U_CFUNC double intl_zval_to_millis(zval *z, intl_error *err, const char *func)
break;
case IS_OBJECT:
if (instanceof_function(Z_OBJCE_P(z), php_date_get_interface_ce())) {
intl_datetime_decompose(z, &rv, NULL, err, func);
intl_datetime_decompose(Z_OBJ_P(z), &rv, nullptr, err, func);
} else if (instanceof_function(Z_OBJCE_P(z), Calendar_ce_ptr)) {
Calendar_object *co = Z_INTL_CALENDAR_P(z);
if (co->ucal == NULL) {
Expand Down
3 changes: 1 addition & 2 deletions ext/intl/common/common_date.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ U_CDECL_END
using icu::TimeZone;

U_CFUNC TimeZone *timezone_convert_datetimezone(int type, void *object, int is_datetime, intl_error *outside_error, const char *func);
U_CFUNC int intl_datetime_decompose(zval *z, double *millis, TimeZone **tz,
intl_error *err, const char *func);
U_CFUNC zend_result intl_datetime_decompose(zend_object *obj, double *millis, TimeZone **tz, intl_error *err, const char *func);

#endif

Expand Down
10 changes: 5 additions & 5 deletions ext/intl/dateformat/dateformat_format_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ static bool valid_format(zval *z) {

U_CFUNC PHP_FUNCTION(datefmt_format_object)
{
zval *object,
*format = NULL;
zend_object *object;
zval *format = NULL;
char *locale_str = NULL;
size_t locale_len;
bool pattern = false;
Expand All @@ -78,7 +78,7 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
timeStyle = DateFormat::kDefault;

ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_OBJECT(object)
Z_PARAM_OBJ(object)
Z_PARAM_OPTIONAL
Z_PARAM_ZVAL(format)
Z_PARAM_STRING_OR_NULL(locale_str, locale_len)
Expand Down Expand Up @@ -149,9 +149,9 @@ U_CFUNC PHP_FUNCTION(datefmt_format_object)
timeStyle = (DateFormat::EStyle)(timeStyle & ~DateFormat::kRelative);
}

zend_class_entry *instance_ce = Z_OBJCE_P(object);
zend_class_entry *instance_ce = object->ce;
if (instanceof_function(instance_ce, Calendar_ce_ptr)) {
Calendar *obj_cal = calendar_fetch_native_calendar(Z_OBJ_P(object));
Calendar *obj_cal = calendar_fetch_native_calendar(object);
if (obj_cal == NULL) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR,
"datefmt_format_object: bad IntlCalendar instance: "
Expand Down
2 changes: 0 additions & 2 deletions ext/intl/tests/dateformat_formatObject_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ bool(false)

Warning: IntlDateFormatter::formatObject(): datefmt_format_object: bad IntlCalendar instance: not initialized properly in %s on line %d
bool(false)

Warning: IntlDateFormatter::formatObject(): datefmt_format_object: error calling ::getTimeStamp() on the object in %s on line %d
Object of type B (inheriting DateTime) has not been correctly initialized by calling parent::__construct() in its constructor

Warning: IntlDateFormatter::formatObject(): datefmt_format_object: the date/time format type is invalid in %s on line %d
Expand Down
14 changes: 14 additions & 0 deletions ext/mysqli/tests/bug74021.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,21 @@ $link->close();

$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
$res = $link->query("SELECT RPAD('1',9000000,'1') as a,RPAD('1',9000000,'1') as b");
if ($res === false) {
printf("[001] [%d] %s\n", $link->errno, $link->error);
}

$r = $res->fetch_array();
if (!is_array($r)) {
printf("[002] Expecting array, got %s/%s\n", gettype($r), $r);
}
if(!is_string($r['a'])) {
printf("[003] Expecting string, got %s/%s\n", gettype($r['a']), $r['a']);
}
if(!is_string($r['b'])) {
printf("[004] Expecting string, got %s/%s\n", gettype($r['b']), $r['b']);
}

var_dump(md5($r['a']));
var_dump(md5($r['b']));
?>
Expand Down
2 changes: 2 additions & 0 deletions ext/mysqli/tests/functions/mysqli_character_set_name.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";

$link = default_mysqli_connect();

mysqli_set_charset($link, 'utf8mb4');

$result = mysqli_query($link, 'SELECT @@character_set_connection AS charset, @@collation_connection AS collation');
$tmp = mysqli_fetch_assoc($result);
mysqli_free_result($result);
Expand Down
2 changes: 2 additions & 0 deletions ext/mysqli/tests/functions/mysqli_character_set_name_oo.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";

$link = default_mysqli_connect();

$link->set_charset('utf8mb4');

$result = $link->query('SELECT @@character_set_connection AS charset, @@collation_connection AS collation');
$tmp = $result->fetch_assoc();
$result->free_result();
Expand Down
2 changes: 1 addition & 1 deletion ext/mysqli/tests/ghsa-h35g-vwh6-m678-stmt-row-string.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ print "done!";
[*] Sending - Malicious Stmt Response for items [Extract heap through buffer over-read]: 01000001013000000203646566087068705f74657374056974656d73056974656d73046974656d046974656d0ce000c8000000fd011000000005000003fe00002200070000040000fa7465737405000005fe00002200

Warning: mysqli_result::fetch_assoc(): Malformed server packet. Field length pointing after the end of packet in %s on line %d
[*] Received: 0500000019010000000100000001
[*] Received: 05000000190100000%d
[*] Server finished
done!
4 changes: 2 additions & 2 deletions ext/mysqli/tests/mysqli_stmt_get_result.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ require_once 'skipifconnectfailure.inc';
mysqli_free_result($result);

$link->real_query('KILL '.mysqli_thread_id($link));
// We kill our own connection so we should get "Query execution was interrupted"
if ($link->errno !== 1317)
// We kill our own connection so we should get "Query execution was interrupted" or "Connection was killed"
if ($link->errno !== 1317 && $link->errno !== 1927)
printf("[042] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

if (false !== ($tmp = mysqli_stmt_get_result($stmt)))
Expand Down
6 changes: 3 additions & 3 deletions ext/mysqli/tests/mysqli_thread_id.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ require_once 'skipifconnectfailure.inc';

// should work if the thread id is correct
$link->real_query('KILL '.mysqli_thread_id($link));
// We kill our own connection so we should get "Query execution was interrupted"
if ($link->errno !== 1317)
// We kill our own connection so we should get "Query execution was interrupted" or "Connection was killed"
if ($link->errno !== 1317 && $link->errno !== 1927)
printf("[042] [%d] %s\n", mysqli_errno($link), mysqli_error($link));

mysqli_close($link);

try {
Expand Down
File renamed without changes.
81 changes: 81 additions & 0 deletions ext/pdo/tests/pdo_fetch_class_by_ref_constructor.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--TEST--
PDO Common: PDO::FETCH_CLASS with by-ref constructor and arg by value
--EXTENSIONS--
pdo
--SKIPIF--
<?php
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();

$db->exec('CREATE TABLE pdo_fetch_class_by_ref_ctor(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))');
$db->exec("INSERT INTO pdo_fetch_class_by_ref_ctor VALUES(1, 'A', 'AA')");
$db->exec("INSERT INTO pdo_fetch_class_by_ref_ctor VALUES(2, 'B', 'BB')");
$db->exec("INSERT INTO pdo_fetch_class_by_ref_ctor VALUES(3, 'C', 'CC')");
$stmt = $db->prepare('SELECT id, val FROM pdo_fetch_class_by_ref_ctor');

class TestByRefCtor
{
public $id;
public $val;
private $str;

public function __construct(string &$str)
{
echo __METHOD__ . "($str, {$this->id})\n";
$str .= $this->val;
$this->str = $str;
}
}

$stmt->execute();
// Use of random_int(10,10) is to defeat SCCP
var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestByRefCtor', [str_repeat('a', random_int(10,10))]));

?>
--CLEAN--
<?php
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
PDOTest::dropTableIfExists($db, "pdo_fetch_class_by_ref_ctor");
?>
--EXPECTF--
TestByRefCtor::__construct(aaaaaaaaaa, 1)
TestByRefCtor::__construct(aaaaaaaaaaA, 2)
TestByRefCtor::__construct(aaaaaaaaaaAB, 3)
array(3) {
[0]=>
object(TestByRefCtor)#%d (3) {
["id"]=>
string(1) "1"
["val"]=>
string(1) "A"
["str":"TestByRefCtor":private]=>
string(11) "aaaaaaaaaaA"
}
[1]=>
object(TestByRefCtor)#%d (3) {
["id"]=>
string(1) "2"
["val"]=>
string(1) "B"
["str":"TestByRefCtor":private]=>
string(12) "aaaaaaaaaaAB"
}
[2]=>
object(TestByRefCtor)#%d (3) {
["id"]=>
string(1) "3"
["val"]=>
string(1) "C"
["str":"TestByRefCtor":private]=>
string(13) "aaaaaaaaaaABC"
}
}
81 changes: 81 additions & 0 deletions ext/pdo/tests/pdo_fetch_class_ctor_with_named_arguments.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
--TEST--
PDO Common: PDO::FETCH_CLASS using named arguments in constructor array
--EXTENSIONS--
pdo
--SKIPIF--
<?php
$dir = getenv('REDIR_TEST_DIR');
if (false == $dir) die('skip no driver');
require_once $dir . 'pdo_test.inc';
PDOTest::skip();
?>
--FILE--
<?php
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.__DIR__ . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();

$db->exec('CREATE TABLE pdo_fetch_class_ctor_named(id int NOT NULL PRIMARY KEY, val VARCHAR(10), val2 VARCHAR(10))');
$db->exec("INSERT INTO pdo_fetch_class_ctor_named VALUES(1, 'A', 'AA')");
$db->exec("INSERT INTO pdo_fetch_class_ctor_named VALUES(2, 'B', 'BB')");
$db->exec("INSERT INTO pdo_fetch_class_ctor_named VALUES(3, 'C', 'CC')");

$stmt = $db->prepare('SELECT id, val, val2 from pdo_fetch_class_ctor_named');

class TestBase
{
public $id;
protected $val;
private $val2;

public function __construct(string $a, string $b) {
echo 'Value of $a: ', $a, PHP_EOL,
'Value of $b: ', $b, PHP_EOL;
}
}
$stmt->execute();
var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestBase', ['b' => 'My key is B', 'a' => 'My key is A']));

?>
--CLEAN--
<?php
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
PDOTest::dropTableIfExists($db, "pdo_fetch_class_ctor_named");
?>
--EXPECTF--
Value of $a: My key is B
Value of $b: My key is A
Value of $a: My key is B
Value of $b: My key is A
Value of $a: My key is B
Value of $b: My key is A
array(3) {
[0]=>
object(TestBase)#%d (3) {
["id"]=>
string(1) "1"
["val":protected]=>
string(1) "A"
["val2":"TestBase":private]=>
string(2) "AA"
}
[1]=>
object(TestBase)#%d (3) {
["id"]=>
string(1) "2"
["val":protected]=>
string(1) "B"
["val2":"TestBase":private]=>
string(2) "BB"
}
[2]=>
object(TestBase)#%d (3) {
["id"]=>
string(1) "3"
["val":protected]=>
string(1) "C"
["val2":"TestBase":private]=>
string(2) "CC"
}
}
Loading
Loading