Skip to content

Commit 5addc69

Browse files
committed
zend_string: Support NUL bytes in ZSTR_INIT_LITERAL()
1 parent 948ab10 commit 5addc69

File tree

7 files changed

+30
-3
lines changed

7 files changed

+30
-3
lines changed

UPGRADING.INTERNALS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
3434
pointer. If the error will be delayed until runtime, it is stored in the
3535
new `validation_error` field of the `zend_attribute` struct.
3636
RFC: https://wiki.php.net/rfc/delayedtargetvalidation_attribute
37+
. ZSTR_INIT_LITERAL() now supports strings containing NUL bytes. Passing
38+
non-literal char* is no longer supported.
3739

3840
- Hash
3941
. Hash functions now use proper hash_spec_result enum for return values

Zend/zend_string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ END_EXTERN_C()
123123

124124
#define ZSTR_ALLOCA_FREE(str, use_heap) free_alloca(str, use_heap)
125125

126-
#define ZSTR_INIT_LITERAL(s, persistent) (zend_string_init((s), strlen(s), (persistent)))
126+
#define ZSTR_INIT_LITERAL(s, persistent) (zend_string_init((s), sizeof("" s) - 1, (persistent)))
127127

128128
/*---*/
129129

ext/dom/element.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ zend_result dom_element_class_name_write(dom_object *obj, zval *newval)
180180
zval *dom_get_prop_checked_offset(dom_object *obj, uint32_t offset, const char *name)
181181
{
182182
#if ZEND_DEBUG
183-
zend_string *name_zstr = ZSTR_INIT_LITERAL(name, false);
183+
zend_string *name_zstr = zend_string_init(name, strlen(name), false);
184184
const zend_property_info *prop_info = zend_get_property_info(obj->std.ce, name_zstr, 0);
185185
zend_string_release_ex(name_zstr, false);
186186
ZEND_ASSERT(OBJ_PROP_TO_NUM(prop_info->offset) == offset);

ext/zend_test/test.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ static ZEND_FUNCTION(zend_test_zend_ini_str)
593593
RETURN_STR(ZT_G(str_test));
594594
}
595595

596+
static ZEND_FUNCTION(zend_test_zstr_init_literal)
597+
{
598+
ZEND_PARSE_PARAMETERS_NONE();
599+
600+
RETURN_STR(ZSTR_INIT_LITERAL("foo\0bar", false));
601+
}
602+
596603
static ZEND_FUNCTION(zend_test_is_string_marked_as_valid_utf8)
597604
{
598605
zend_string *str;

ext/zend_test/test.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ function zend_test_zend_ini_parse_quantity(string $str): int {}
301301
function zend_test_zend_ini_parse_uquantity(string $str): int {}
302302

303303
function zend_test_zend_ini_str(): string {}
304+
function zend_test_zstr_init_literal(): string {}
304305

305306
#ifdef ZEND_CHECK_STACK_LIMIT
306307
function zend_test_zend_call_stack_get(): ?array {}

ext/zend_test/test_arginfo.h

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
zstr_init_literal
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
8+
var_dump(strlen(zend_test_zstr_init_literal()), bin2hex(zend_test_zstr_init_literal()));
9+
10+
?>
11+
--EXPECT--
12+
int(7)
13+
string(14) "666f6f00626172"

0 commit comments

Comments
 (0)