Skip to content
Draft
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
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--TEST--
#[\Deprecated]: Class constant with value unknown at compile time.
--EXTENSIONS--
zend_test
--FILE--
<?php

define('SUFFIX', random_int(1, 2) == 1 ? 'a' : 'b');
define('SUFFIX', zend_return_non_interned_string('a'));

class Clazz {
#[\Deprecated]
Expand All @@ -17,5 +19,5 @@ var_dump($value === 'Clazz-' . SUFFIX);
?>
--EXPECTF--
Deprecated: Constant Clazz::CONSTANT is deprecated in %s on line %d
string(7) "Clazz-%c"
string(7) "Clazz-a"
bool(true)
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--TEST--
#[\Deprecated]: Constant with value unknown at compile time.
--EXTENSIONS--
zend_test
--FILE--
<?php

define('SUFFIX', random_int(1, 2) == 1 ? 'a' : 'b');
define('SUFFIX', zend_return_non_interned_string('a'));

#[\Deprecated]
const CONSTANT = 'Prefix-' . SUFFIX;
Expand All @@ -15,5 +17,5 @@ var_dump($value === 'Prefix-' . SUFFIX);
?>
--EXPECTF--
Deprecated: Constant CONSTANT is deprecated in %s on line %d
string(8) "Prefix-%c"
string(8) "Prefix-a"
bool(true)
6 changes: 4 additions & 2 deletions Zend/tests/attributes/deprecated/message_004.phpt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
--TEST--
#[\Deprecated]: Message with value unknown at compile time.
--EXTENSIONS--
zend_test
--FILE--
<?php

define('MESSAGE', 'value-' . (random_int(1, 2) == 1 ? 'a' : 'b'));
define('MESSAGE', 'value-' . zend_return_non_interned_string('a'));

#[\Deprecated(MESSAGE)]
function test() {
Expand All @@ -13,4 +15,4 @@ test();

?>
--EXPECTF--
Deprecated: Function test() is deprecated, value-%c in %s on line %d
Deprecated: Function test() is deprecated, value-a in %s on line %d
2 changes: 2 additions & 0 deletions Zend/tests/error_reporting/bug81652.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
--TEST--
Bug #81652: The value of error_reporting() gets overridden
--EXTENSIONS--
zend_test
--FILE--
<?php

Expand Down
3 changes: 2 additions & 1 deletion ext/curl/tests/refcounted_return_must_not_leak.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Returning refcounted value from callback must not leak
--EXTENSIONS--
curl
zend_test
--FILE--
<?php
include 'server.inc';
Expand All @@ -11,7 +12,7 @@ $url = "{$host}/get.inc";
$ch = curl_init($url);

function return_non_interned_string() {
return str_repeat('x', random_int(5, 5));
return zend_return_non_interned_string('x');
}

curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
Expand Down
3 changes: 2 additions & 1 deletion ext/dom/tests/DOMXPath_callables_errors.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
registerPHPFunctions() with callables - error cases
--EXTENSIONS--
dom
zend_test
--FILE--
<?php

Expand Down Expand Up @@ -64,7 +65,7 @@ $x = new class {
$classes = get_declared_classes();

try {
$str = str_repeat($classes[count($classes) - 1] . '::dump', random_int(1, 1));
$str = zend_return_non_interned_string($classes[count($classes) - 1] . '::dump');
$xpath->registerPhpFunctions([$str]);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
Expand Down
12 changes: 4 additions & 8 deletions ext/dom/tests/gh12002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,20 @@
GH-12002 (DOMDocument::encoding memory leak with invalid encoding)
--EXTENSIONS--
dom
zend_test
--FILE--
<?php

function make_nonconst(string $x) {
// Defeat SCCP, even with inlining
return str_repeat($x, random_int(1, 1));
}

$dom = new DOMDocument();
$dom->encoding = make_nonconst('utf-8');
$dom->encoding = zend_return_non_interned_string('utf-8');
var_dump($dom->encoding);
try {
$dom->encoding = make_nonconst('foobar');
$dom->encoding = zend_return_non_interned_string('foobar');
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), "\n";
}
var_dump($dom->encoding);
$dom->encoding = make_nonconst('utf-16le');
$dom->encoding = zend_return_non_interned_string('utf-16le');
var_dump($dom->encoding);
try {
$dom->encoding = NULL;
Expand Down
3 changes: 2 additions & 1 deletion ext/dom/tests/modern/html/parser/Element_innerHTML.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test writing Element::$innerHTML on HTML documents
--EXTENSIONS--
dom
zend_test
--FILE--
<?php

Expand All @@ -20,7 +21,7 @@ $el->innerHTML = "invalid\xffutf-8𐍈𐍈𐍈";
echo $dom->saveXML(), "\n";

// Create a non-interned string that gets the UTF-8 validity flag added
$str = str_repeat("my valid string", random_int(2, 2));
$str = zend_return_non_interned_string("my valid string");
preg_match('/^.*$/u', $str);
$el->innerHTML = $str;
echo $dom->saveXML(), "\n";
Expand Down
3 changes: 2 additions & 1 deletion ext/intl/tests/msgfmt_format_error4.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
MessageFormatter::format() invalid UTF-8 for arg key or value
--EXTENSIONS--
intl
zend_test
--INI--
intl.use_exceptions=On
--FILE--
Expand Down Expand Up @@ -29,7 +30,7 @@ try {
try {
var_dump($mf->format(array("foo" => new class {
function __toString(): string {
return str_repeat("\x80", random_int(1, 1));
return zend_return_non_interned_string("\x80");
}
})));
} catch (Throwable $e) {
Expand Down
5 changes: 3 additions & 2 deletions ext/ldap/tests/ldap_set_option_leak_attrvalue_context.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
ldap_set_option() - Leaks attrvalue and context
--EXTENSIONS--
ldap
zend_test
--FILE--
<?php
require "connect.inc";

$link = ldap_connect($uri);

$attrvalue = str_repeat("attrvalue", random_int(1, 1));
$context = str_repeat("context", random_int(1, 1));
$attrvalue = zend_return_non_interned_string("attrvalue");
$context = zend_return_non_interned_string("context");

$controls = [
["oid" => "2.16.840.1.113730.3.4.9", "value" => ["attrvalue" => $attrvalue, "context" => $context, "before" => 0, "after" => 0]],
Expand Down
5 changes: 4 additions & 1 deletion ext/pcre/tests/preg_match_frameless_leak.phpt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
--TEST--
Memory leak in preg_match() frameless function with invalid regex and object arguments
--EXTENSIONS--
pcre
zend_test
--FILE--
<?php
class Str {
private $val;
public function __construct($val) {
$this->val = str_repeat($val, random_int(1, 1));
$this->val = zend_return_non_interned_string($val);
}
public function __toString() {
return $this->val;
Expand Down
16 changes: 8 additions & 8 deletions ext/pdo/tests/pdo_fetch_class_by_ref_constructor.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
PDO Common: PDO::FETCH_CLASS with by-ref constructor and arg by value
--EXTENSIONS--
pdo
zend_test
--SKIPIF--
<?php
$dir = getenv('REDIR_TEST_DIR');
Expand Down Expand Up @@ -36,8 +37,7 @@ class TestByRefCtor
}

$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))]));
var_dump($stmt->fetchAll(PDO::FETCH_CLASS, 'TestByRefCtor', [zend_return_non_interned_string('a')]));

?>
--CLEAN--
Expand All @@ -48,13 +48,13 @@ PDOTest::dropTableIfExists($db, "pdo_fetch_class_by_ref_ctor");
?>
--EXPECTF--
Warning: TestByRefCtor::__construct(): Argument #1 ($str) must be passed by reference, value given in %s on line %d
TestByRefCtor::__construct(aaaaaaaaaa, 1)
TestByRefCtor::__construct(a, 1)

Warning: TestByRefCtor::__construct(): Argument #1 ($str) must be passed by reference, value given in %s on line %d
TestByRefCtor::__construct(aaaaaaaaaa, 2)
TestByRefCtor::__construct(a, 2)

Warning: TestByRefCtor::__construct(): Argument #1 ($str) must be passed by reference, value given in %s on line %d
TestByRefCtor::__construct(aaaaaaaaaa, 3)
TestByRefCtor::__construct(a, 3)
array(3) {
[0]=>
object(TestByRefCtor)#%d (3) {
Expand All @@ -63,7 +63,7 @@ array(3) {
["val"]=>
string(1) "A"
["str":"TestByRefCtor":private]=>
string(11) "aaaaaaaaaaA"
string(2) "aA"
}
[1]=>
object(TestByRefCtor)#%d (3) {
Expand All @@ -72,7 +72,7 @@ array(3) {
["val"]=>
string(1) "B"
["str":"TestByRefCtor":private]=>
string(11) "aaaaaaaaaaB"
string(2) "aB"
}
[2]=>
object(TestByRefCtor)#%d (3) {
Expand All @@ -81,6 +81,6 @@ array(3) {
["val"]=>
string(1) "C"
["str":"TestByRefCtor":private]=>
string(11) "aaaaaaaaaaC"
string(2) "aC"
}
}
7 changes: 4 additions & 3 deletions ext/pdo_firebird/tests/gh18276.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
GH-18276 (persistent connection - setAttribute(Pdo\Firebird::ATTR_DATE_FORMAT, ..) results in "zend_mm_heap corrupted")
--EXTENSIONS--
pdo_firebird
zend_test
--SKIPIF--
<?php require('skipif.inc'); ?>
--XLEAK--
Expand All @@ -23,9 +24,9 @@ for ($i = 0; $i < 2; $i++) {
],
);
// Avoid interned
$dbh->setAttribute(Pdo\Firebird::ATTR_DATE_FORMAT, str_repeat('Y----m----d', random_int(1, 1)));
$dbh->setAttribute(Pdo\Firebird::ATTR_TIME_FORMAT, str_repeat('H::::i::::s', random_int(1, 1)));
$dbh->setAttribute(Pdo\Firebird::ATTR_TIMESTAMP_FORMAT, str_repeat('Y----m----d....H::::i::::s', random_int(1, 1)));
$dbh->setAttribute(Pdo\Firebird::ATTR_DATE_FORMAT, zend_return_non_interned_string('Y----m----d'));
$dbh->setAttribute(Pdo\Firebird::ATTR_TIME_FORMAT, zend_return_non_interned_string('H::::i::::s'));
$dbh->setAttribute(Pdo\Firebird::ATTR_TIMESTAMP_FORMAT, zend_return_non_interned_string('Y----m----d....H::::i::::s'));
unset($dbh);
}

Expand Down
3 changes: 2 additions & 1 deletion ext/phar/tests/gh18953.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ GH-18953 (Phar: Stream double free)
--EXTENSIONS--
phar
zlib
zend_test
--INI--
phar.readonly=0
--FILE--
<?php

$phar = new Phar(__DIR__ . "/gh18953.phar");
$phar->addFromString("file", str_repeat("123", random_int(1, 1)));
$phar->addFromString("file", zend_return_non_interned_string("123"));
$phar->addEmptyDir("dir");
$phar2 = $phar->compress(Phar::GZ);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
openssl_sign() polyfill with wrong return value
--EXTENSIONS--
phar
zend_test
--SKIPIF--
<?php
if (getenv('SKIP_SLOW_TESTS')) die('skip');
Expand All @@ -14,7 +15,7 @@ phar.require_hash=0
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.tar';

function openssl_sign() {
return str_repeat('foobar', random_int(1, 1));
return zend_return_non_interned_string('foobar');
}

$phar = new PharData($fname);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ session.gc_probability=0
session.save_handler=files
--EXTENSIONS--
session
zend_test
--FILE--
<?php
ob_start();
Expand All @@ -17,7 +18,7 @@ session_set_save_handler(
function(string $id): string|false { return ""; },
function(string $id, string $data) { return true; },
function(string $id) { return true; },
function(int $max) { return str_repeat("x", random_int(100, 100)); }
function(int $max) { return zend_return_non_interned_string("x"); }
);

session_start();
Expand Down
7 changes: 4 additions & 3 deletions ext/snmp/tests/gh16959.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
snmpget() modifies object_id array source
--EXTENSIONS--
snmp
zend_test
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
Expand All @@ -25,17 +26,17 @@ try {
}

try {
snmp2_set($hostname, $communityWrite, $bad_object_ids, array(new stdClass()), array(null));
snmp2_set($hostname, $communityWrite, $bad_object_ids, [new stdClass()], [null]);
} catch (Throwable $e) {
echo $e->getMessage() . PHP_EOL;
}
try {
snmp2_set($hostname, $communityWrite, $bad_object_ids, array("toolongtype"), array(null));
snmp2_set($hostname, $communityWrite, $bad_object_ids, ["toolongtype"], [null]);
} catch (Throwable $e) {
echo $e->getMessage() . PHP_EOL;
}
try {
snmp2_set($hostname, $communityWrite, $bad_object_ids, array(str_repeat("onetoomuch", random_int(1, 1))), array(null));
snmp2_set($hostname, $communityWrite, $bad_object_ids, [zend_return_non_interned_string("onetoomuch")], [null]);
} catch (Throwable $e) {
echo $e->getMessage();
}
Expand Down
3 changes: 2 additions & 1 deletion ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
SNMP::setSecurity() - the context name is copied
--EXTENSIONS--
snmp
zend_test
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
Expand All @@ -11,7 +12,7 @@ require_once(__DIR__.'/skipif.inc');
require_once(__DIR__.'/snmp_include.inc');

$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
$context = str_repeat('c', 5) . random_int(10, 99);
$context = zend_return_non_interned_string('c');
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $context);
unset($context);
// The agent does not know this context, only the lifetime of the name matters.
Expand Down
6 changes: 3 additions & 3 deletions ext/standard/tests/array/gh17977.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
array_any() / array_all() leak
--DESCRIPTION--
Found in GH-16831#issuecomment-2700410631
--EXTENSIONS--
zend_test
--FILE--
<?php

// Don't touch this str_repeat + random_int combination,
// this is to circumvent SCCP and interning
$key = str_repeat('abc', random_int(3, 3));
$key = zend_return_non_interned_string('abc');

var_dump(array_any([$key => 1], static fn () => true));
var_dump(array_all([$key => 1], static fn () => false));
Expand Down
Loading
Loading