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
8 changes: 7 additions & 1 deletion .github/actions/freebsd/action.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: FreeBSD
inputs:
configurationParameters:
default: ''
required: false
runs:
using: composite
steps:
Expand Down Expand Up @@ -80,7 +84,9 @@ runs:
--with-sodium \
--enable-werror \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d
--with-config-file-scan-dir=/etc/php.d \
${{ inputs.configurationParameters }}

gmake -j2
mkdir /etc/php.d
gmake install > /dev/null
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ on:
run_macos_arm64:
required: true
type: boolean
run_freebsd_zts:
required: true
type: boolean
ubuntu_version:
required: true
type: string
Expand Down Expand Up @@ -1052,7 +1055,13 @@ jobs:
- name: Test
run: .github/scripts/windows/test.bat
FREEBSD:
name: FREEBSD
strategy:
fail-fast: false
matrix:
zts: [true, false]
exclude:
- zts: ${{ !inputs.run_freebsd_zts && true || '*never*' }}
name: "FREEBSD_${{ matrix.zts && 'ZTS' || 'NTS' }}"
runs-on: ubuntu-latest
steps:
- name: git checkout
Expand All @@ -1061,3 +1070,6 @@ jobs:
ref: ${{ inputs.branch }}
- name: FreeBSD
uses: ./.github/actions/freebsd
with:
configurationParameters: >-
--${{ matrix.zts && 'enable' || 'disable' }}-zts
1 change: 1 addition & 0 deletions .github/workflows/root.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
run_alpine: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }}
run_linux_ppc64: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }}
run_macos_arm64: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 4) || matrix.branch.version[0] >= 9 }}
run_freebsd_zts: ${{ (matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 3) || matrix.branch.version[0] >= 9 }}
ubuntu_version: ${{
(((matrix.branch.version[0] == 8 && matrix.branch.version[1] >= 5) || matrix.branch.version[0] >= 9) && '24.04')
|| '22.04' }}
Expand Down
2 changes: 2 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ PHP 8.5 INTERNALS UPGRADE NOTES
properties.
. ZEND_IS_XDIGIT() macro was removed because it was unused and its name
did not match its actual behavior.
. zend_register_constant() now returns a pointer to the added constant
on success and NULL on failure instead of SUCCESS/FAILURE.

========================
2. Build system changes
Expand Down
19 changes: 19 additions & 0 deletions Zend/tests/attributes/constants/oss_fuzz_428053935.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--TEST--
OSS-Fuzz #428053935
--FILE--
<?php
namespace Foo; // Capital letter is important for the ns lookup
#[Attr]
const MyConst = '';

$rc = new \ReflectionConstant('Foo\\MyConst');
var_dump($rc->getAttributes());
?>
--EXPECTF--
array(1) {
[0]=>
object(ReflectionAttribute)#%d (1) {
["name"]=>
string(8) "Foo\Attr"
}
}
63 changes: 63 additions & 0 deletions Zend/tests/clone/ast.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,60 @@ try {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, ));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, $array));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, $array, $extraParameter, $trailingComma, ));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone($x, withProperties: [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(object: $x, [ "foo" => $foo, "bar" => $bar ]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(...["object" => $x, "withProperties" => [ "foo" => $foo, "bar" => $bar ]]));
} catch (Error $e) {
echo $e->getMessage(), PHP_EOL;
}

try {
assert(false && $y = clone(...));
} catch (Error $e) {
Expand All @@ -28,4 +82,13 @@ try {
--EXPECT--
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x)))
assert(false && ($y = \clone($x, ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone($x, $array)))
assert(false && ($y = \clone($x, $array, $extraParameter, $trailingComma)))
assert(false && ($y = \clone(object: $x, withProperties: ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone($x, withProperties: ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone(object: $x)))
assert(false && ($y = \clone(object: $x, ['foo' => $foo, 'bar' => $bar])))
assert(false && ($y = \clone(...['object' => $x, 'withProperties' => ['foo' => $foo, 'bar' => $bar]])))
assert(false && ($y = \clone(...)))
2 changes: 1 addition & 1 deletion Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ ZEND_FUNCTION(define)
/* non persistent */
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
c.name = zend_string_copy(name);
if (zend_register_constant(&c) == SUCCESS) {
if (zend_register_constant(&c) != NULL) {
RETURN_TRUE;
} else {
RETURN_FALSE;
Expand Down
7 changes: 3 additions & 4 deletions Zend/zend_constants.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_consta
return ret;
}

ZEND_API zend_result zend_register_constant(zend_constant *c)
ZEND_API zend_constant *zend_register_constant(zend_constant *c)
{
zend_string *lowercase_name = NULL;
zend_string *name;
zend_result ret = SUCCESS;
zend_constant *ret = NULL;
bool persistent = (ZEND_CONSTANT_FLAGS(c) & CONST_PERSISTENT) != 0;

#if 0
Expand Down Expand Up @@ -539,7 +539,7 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
/* Check if the user is trying to define any special constant */
if (zend_string_equals_literal(name, "__COMPILER_HALT_OFFSET__")
|| (!persistent && zend_get_special_const(ZSTR_VAL(name), ZSTR_LEN(name)))
|| zend_hash_add_constant(EG(zend_constants), name, c) == NULL
|| (ret = zend_hash_add_constant(EG(zend_constants), name, c)) == NULL
) {
zend_error(E_WARNING, "Constant %s already defined", ZSTR_VAL(name));
zend_string_release(c->name);
Expand All @@ -550,7 +550,6 @@ ZEND_API zend_result zend_register_constant(zend_constant *c)
if (!persistent) {
zval_ptr_dtor_nogc(&c->value);
}
ret = FAILURE;
}
if (lowercase_name) {
zend_string_release(lowercase_name);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ZEND_API void zend_register_long_constant(const char *name, size_t name_len, zen
ZEND_API void zend_register_double_constant(const char *name, size_t name_len, double dval, int flags, int module_number);
ZEND_API void zend_register_string_constant(const char *name, size_t name_len, const char *strval, int flags, int module_number);
ZEND_API void zend_register_stringl_constant(const char *name, size_t name_len, const char *strval, size_t strlen, int flags, int module_number);
ZEND_API zend_result zend_register_constant(zend_constant *c);
ZEND_API zend_constant *zend_register_constant(zend_constant *c);
void zend_constant_add_attributes(zend_constant *c, HashTable *attributes);
#ifdef ZTS
void zend_copy_constants(HashTable *target, HashTable *source);
Expand Down
43 changes: 36 additions & 7 deletions Zend/zend_language_parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> unprefixed_use_declarations const_decl inner_statement
%type <ast> expr optional_expr while_statement for_statement foreach_variable
%type <ast> foreach_statement declare_statement finally_statement unset_variable variable
%type <ast> extends_from parameter optional_type_without_static argument global_var
%type <ast> extends_from parameter optional_type_without_static argument argument_no_expr global_var
%type <ast> static_var class_statement trait_adaptation trait_precedence trait_alias
%type <ast> absolute_trait_method_reference trait_method_reference property echo_expr
%type <ast> new_dereferenceable new_non_dereferenceable anonymous_class class_name class_name_reference simple_variable
Expand Down Expand Up @@ -287,7 +287,7 @@ static YYSIZE_T zend_yytnamerr(char*, const char*);
%type <ast> enum_declaration_statement enum_backing_type enum_case enum_case_expr
%type <ast> function_name non_empty_member_modifiers
%type <ast> property_hook property_hook_list optional_property_hook_list hooked_property property_hook_body
%type <ast> optional_parameter_list
%type <ast> optional_parameter_list clone_argument_list non_empty_clone_argument_list

%type <num> returns_ref function fn is_reference is_variadic property_modifiers property_hook_modifiers
%type <num> method_modifiers class_const_modifiers member_modifier optional_cpp_modifiers
Expand Down Expand Up @@ -914,13 +914,42 @@ non_empty_argument_list:
{ $$ = zend_ast_list_add($1, $3); }
;

argument:
expr { $$ = $1; }
| identifier ':' expr
/* `clone_argument_list` is necessary to resolve a parser ambiguity (shift-reduce conflict)
* of `clone($expr)`, which could either be parsed as a function call with `$expr` as the first
* argument or as a use of the `clone` language construct with an expression with useless
* parenthesis. Both would be valid and result in the same AST / the same semantics.
* `clone_argument_list` is defined in a way that an `expr` in the first position needs to
* be followed by a `,` which is not valid syntax for a parenthesized `expr`, ensuring
* that calling `clone()` with a single unnamed parameter is handled by the language construct
* syntax.
*/
clone_argument_list:
'(' ')' { $$ = zend_ast_create_list(0, ZEND_AST_ARG_LIST); }
| '(' non_empty_clone_argument_list possible_comma ')' { $$ = $2; }
| '(' expr ',' ')' { $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $2); }
| '(' T_ELLIPSIS ')' { $$ = zend_ast_create_fcc(); }
;

non_empty_clone_argument_list:
expr ',' argument
{ $$ = zend_ast_create_list(2, ZEND_AST_ARG_LIST, $1, $3); }
| argument_no_expr
{ $$ = zend_ast_create_list(1, ZEND_AST_ARG_LIST, $1); }
| non_empty_clone_argument_list ',' argument
{ $$ = zend_ast_list_add($1, $3); }
;

argument_no_expr:
identifier ':' expr
{ $$ = zend_ast_create(ZEND_AST_NAMED_ARG, $1, $3); }
| T_ELLIPSIS expr { $$ = zend_ast_create(ZEND_AST_UNPACK, $2); }
;

argument:
expr { $$ = $1; }
| argument_no_expr { $$ = $1; }
;

global_var_list:
global_var_list ',' global_var { $$ = zend_ast_list_add($1, $3); }
| global_var { $$ = zend_ast_create_list(1, ZEND_AST_STMT_LIST, $1); }
Expand Down Expand Up @@ -1228,10 +1257,10 @@ expr:
{ $$ = zend_ast_create(ZEND_AST_ASSIGN, $1, $3); }
| variable '=' ampersand variable
{ $$ = zend_ast_create(ZEND_AST_ASSIGN_REF, $1, $4); }
| T_CLONE '(' T_ELLIPSIS ')' {
| T_CLONE clone_argument_list {
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
name->attr = ZEND_NAME_FQ;
$$ = zend_ast_create(ZEND_AST_CALL, name, zend_ast_create_fcc());
$$ = zend_ast_create(ZEND_AST_CALL, name, $2);
}
| T_CLONE expr {
zend_ast *name = zend_ast_create_zval_from_str(ZSTR_KNOWN(ZEND_STR_CLONE));
Expand Down
9 changes: 4 additions & 5 deletions Zend/zend_vm_def.h
Original file line number Diff line number Diff line change
Expand Up @@ -8261,7 +8261,7 @@ ZEND_VM_HANDLER(143, ZEND_DECLARE_CONST, CONST, CONST)
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
c.name = zend_string_copy(Z_STR_P(name));

if (zend_register_constant(&c) == FAILURE) {
if (zend_register_constant(&c) == NULL) {
}

FREE_OP1();
Expand All @@ -8274,7 +8274,7 @@ ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST)
USE_OPLINE
zval *name;
zval *val;
zend_constant c;
zend_constant c, *registered;

SAVE_OPLINE();
name = GET_OP1_ZVAL_PTR(BP_VAR_R);
Expand All @@ -8293,17 +8293,16 @@ ZEND_VM_HANDLER(210, ZEND_DECLARE_ATTRIBUTED_CONST, CONST, CONST)
ZEND_CONSTANT_SET_FLAGS(&c, 0, PHP_USER_CONSTANT);
c.name = zend_string_copy(Z_STR_P(name));

if (zend_register_constant(&c) == FAILURE) {
registered = zend_register_constant(&c);
if (registered == NULL) {
FREE_OP1();
FREE_OP2();
/* two opcodes used, second one is the data with attributes */
ZEND_VM_NEXT_OPCODE_EX(1, 2);
}

HashTable *attributes = Z_PTR_P(GET_OP_DATA_ZVAL_PTR(BP_VAR_R));
zend_constant *registered = zend_get_constant_ptr(c.name);
ZEND_ASSERT(attributes != NULL);
ZEND_ASSERT(registered != NULL);
zend_constant_add_attributes(registered, attributes);

FREE_OP1();
Expand Down
9 changes: 4 additions & 5 deletions Zend/zend_vm_execute.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.