Skip to content

Commit fbd2fc7

Browse files
committed
tree: use new zend_return_non_interned_string() to prevent SCCP interning
1 parent b96e7d6 commit fbd2fc7

19 files changed

Lines changed: 61 additions & 43 deletions

‎Zend/tests/attributes/deprecated/class_constants/value_unknown_at_compile_time_001.phpt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
--TEST--
22
#[\Deprecated]: Class constant with value unknown at compile time.
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

6-
define('SUFFIX', random_int(1, 2) == 1 ? 'a' : 'b');
8+
define('SUFFIX', zend_return_non_interned_string('a'));
79

810
class Clazz {
911
#[\Deprecated]
@@ -17,5 +19,5 @@ var_dump($value === 'Clazz-' . SUFFIX);
1719
?>
1820
--EXPECTF--
1921
Deprecated: Constant Clazz::CONSTANT is deprecated in %s on line %d
20-
string(7) "Clazz-%c"
22+
string(7) "Clazz-a"
2123
bool(true)

‎Zend/tests/attributes/deprecated/constants/value_unknown_at_compile_time_001.phpt‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
--TEST--
22
#[\Deprecated]: Constant with value unknown at compile time.
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

6-
define('SUFFIX', random_int(1, 2) == 1 ? 'a' : 'b');
8+
define('SUFFIX', zend_return_non_interned_string('a'));
79

810
#[\Deprecated]
911
const CONSTANT = 'Prefix-' . SUFFIX;
@@ -15,5 +17,5 @@ var_dump($value === 'Prefix-' . SUFFIX);
1517
?>
1618
--EXPECTF--
1719
Deprecated: Constant CONSTANT is deprecated in %s on line %d
18-
string(8) "Prefix-%c"
20+
string(8) "Prefix-a"
1921
bool(true)
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
--TEST--
22
#[\Deprecated]: Message with value unknown at compile time.
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

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

810
#[\Deprecated(MESSAGE)]
911
function test() {
@@ -13,4 +15,4 @@ test();
1315

1416
?>
1517
--EXPECTF--
16-
Deprecated: Function test() is deprecated, value-%c in %s on line %d
18+
Deprecated: Function test() is deprecated, value-a in %s on line %d

‎Zend/tests/error_reporting/bug81652.phpt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
--TEST--
22
Bug #81652: The value of error_reporting() gets overridden
3+
--EXTENSIONS--
4+
zend_test
35
--FILE--
46
<?php
57

‎ext/curl/tests/refcounted_return_must_not_leak.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Returning refcounted value from callback must not leak
33
--EXTENSIONS--
44
curl
5+
zend_test
56
--FILE--
67
<?php
78
include 'server.inc';
@@ -11,7 +12,7 @@ $url = "{$host}/get.inc";
1112
$ch = curl_init($url);
1213

1314
function return_non_interned_string() {
14-
return str_repeat('x', random_int(5, 5));
15+
return zend_return_non_interned_string('x');
1516
}
1617

1718
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);

‎ext/dom/tests/DOMXPath_callables_errors.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
registerPHPFunctions() with callables - error cases
33
--EXTENSIONS--
44
dom
5+
zend_test
56
--FILE--
67
<?php
78

@@ -64,7 +65,7 @@ $x = new class {
6465
$classes = get_declared_classes();
6566

6667
try {
67-
$str = str_repeat($classes[count($classes) - 1] . '::dump', random_int(1, 1));
68+
$str = zend_return_non_interned_string($classes[count($classes) - 1] . '::dump');
6869
$xpath->registerPhpFunctions([$str]);
6970
} catch (Throwable $e) {
7071
echo $e::class, ': ', $e->getMessage(), "\n";

‎ext/dom/tests/gh12002.phpt‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,20 @@
22
GH-12002 (DOMDocument::encoding memory leak with invalid encoding)
33
--EXTENSIONS--
44
dom
5+
zend_test
56
--FILE--
67
<?php
78

8-
function make_nonconst(string $x) {
9-
// Defeat SCCP, even with inlining
10-
return str_repeat($x, random_int(1, 1));
11-
}
12-
139
$dom = new DOMDocument();
14-
$dom->encoding = make_nonconst('utf-8');
10+
$dom->encoding = zend_return_non_interned_string('utf-8');
1511
var_dump($dom->encoding);
1612
try {
17-
$dom->encoding = make_nonconst('foobar');
13+
$dom->encoding = zend_return_non_interned_string('foobar');
1814
} catch (Throwable $e) {
1915
echo $e::class, ': ', $e->getMessage(), "\n";
2016
}
2117
var_dump($dom->encoding);
22-
$dom->encoding = make_nonconst('utf-16le');
18+
$dom->encoding = zend_return_non_interned_string('utf-16le');
2319
var_dump($dom->encoding);
2420
try {
2521
$dom->encoding = NULL;

‎ext/dom/tests/modern/html/parser/Element_innerHTML.phpt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Test writing Element::$innerHTML on HTML documents
33
--EXTENSIONS--
44
dom
5+
zend_test
56
--FILE--
67
<?php
78

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

2223
// Create a non-interned string that gets the UTF-8 validity flag added
23-
$str = str_repeat("my valid string", random_int(2, 2));
24+
$str = zend_return_non_interned_string("my valid string");
2425
preg_match('/^.*$/u', $str);
2526
$el->innerHTML = $str;
2627
echo $dom->saveXML(), "\n";
@@ -56,7 +57,7 @@ echo $dom->saveXML(), "\n";
5657
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
5758
<div xmlns="http://www.w3.org/1999/xhtml">invalid�utf-8𐍈𐍈𐍈</div>
5859
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
59-
<div xmlns="http://www.w3.org/1999/xhtml">my valid stringmy valid string</div>
60+
<div xmlns="http://www.w3.org/1999/xhtml">my valid string</div>
6061
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
6162
<style xmlns="http://www.w3.org/1999/xhtml">&lt;p&gt;foo&lt;/p&gt;</style>
6263
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

‎ext/intl/tests/msgfmt_format_error4.phpt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
MessageFormatter::format() invalid UTF-8 for arg key or value
33
--EXTENSIONS--
44
intl
5+
zend_test
56
--INI--
67
intl.use_exceptions=On
78
--FILE--
@@ -29,7 +30,7 @@ try {
2930
try {
3031
var_dump($mf->format(array("foo" => new class {
3132
function __toString(): string {
32-
return str_repeat("\x80", random_int(1, 1));
33+
return zend_return_non_interned_string("\x80");
3334
}
3435
})));
3536
} catch (Throwable $e) {

‎ext/ldap/tests/ldap_set_option_leak_attrvalue_context.phpt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
ldap_set_option() - Leaks attrvalue and context
33
--EXTENSIONS--
44
ldap
5+
zend_test
56
--FILE--
67
<?php
78
require "connect.inc";
89

910
$link = ldap_connect($uri);
1011

11-
$attrvalue = str_repeat("attrvalue", random_int(1, 1));
12-
$context = str_repeat("context", random_int(1, 1));
12+
$attrvalue = zend_return_non_interned_string("attrvalue");
13+
$context = zend_return_non_interned_string("context");
1314

1415
$controls = [
1516
["oid" => "2.16.840.1.113730.3.4.9", "value" => ["attrvalue" => $attrvalue, "context" => $context, "before" => 0, "after" => 0]],

0 commit comments

Comments
 (0)