Skip to content

Commit 0ac55e9

Browse files
committed
Add zend_test_crash funtion to segfault PHP process
This is useful for testing PHP-FPM handling of crashed children. Closes GH-11082
1 parent fc32d39 commit 0ac55e9

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

Zend/tests/arginfo_zpp_mismatch.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function skipFunction($function): bool {
99
/* intentionally violate invariants */
1010
|| $function === 'zend_create_unterminated_string'
1111
|| $function === 'zend_test_array_return'
12+
|| $function === 'zend_test_crash'
1213
|| $function === 'zend_leak_bytes'
1314
/* mess with output */
1415
|| (is_string($function) && str_starts_with($function, 'ob_'))

ext/zend_test/test.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,23 @@ static ZEND_FUNCTION(zend_get_map_ptr_last)
327327
RETURN_LONG(CG(map_ptr_last));
328328
}
329329

330+
static ZEND_FUNCTION(zend_test_crash)
331+
{
332+
zend_string *message;
333+
334+
ZEND_PARSE_PARAMETERS_START(0, 1)
335+
Z_PARAM_OPTIONAL
336+
Z_PARAM_STR_OR_NULL(message)
337+
ZEND_PARSE_PARAMETERS_END();
338+
339+
if (message) {
340+
php_printf("%s", ZSTR_VAL(message));
341+
}
342+
343+
char *invalid = (char *) 1;
344+
php_printf("%s", invalid);
345+
}
346+
330347
static zend_object *zend_test_class_new(zend_class_entry *class_type)
331348
{
332349
zend_object *obj = zend_objects_new(class_type);

ext/zend_test/test.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ function zend_get_current_func_name(): string {}
119119
function zend_call_method(string $class, string $method, mixed $arg1 = UNKNOWN, mixed $arg2 = UNKNOWN): mixed {}
120120

121121
function zend_get_map_ptr_last(): int {}
122+
123+
function zend_test_crash(?string $message = null): void {}
122124
}
123125

124126
namespace ZendTestNS {

ext/zend_test/test_arginfo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 614310958c6e2acde46c9b7932ba894caf72d6df */
2+
* Stub hash: 47eb58d644268f4fdce7a6b5007f7755ebfcb197 */
33

44
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_array_return, 0, 0, IS_ARRAY, 0)
55
ZEND_END_ARG_INFO()
@@ -82,6 +82,10 @@ ZEND_END_ARG_INFO()
8282
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_get_map_ptr_last, 0, 0, IS_LONG, 0)
8383
ZEND_END_ARG_INFO()
8484

85+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_zend_test_crash, 0, 0, IS_VOID, 0)
86+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, message, IS_STRING, 1, "null")
87+
ZEND_END_ARG_INFO()
88+
8589
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_ZendTestNS2_ZendSubNS_namespaced_func, 0, 0, _IS_BOOL, 0)
8690
ZEND_END_ARG_INFO()
8791

@@ -143,6 +147,7 @@ static ZEND_FUNCTION(zend_test_parameter_with_attribute);
143147
static ZEND_FUNCTION(zend_get_current_func_name);
144148
static ZEND_FUNCTION(zend_call_method);
145149
static ZEND_FUNCTION(zend_get_map_ptr_last);
150+
static ZEND_FUNCTION(zend_test_crash);
146151
static ZEND_FUNCTION(namespaced_func);
147152
static ZEND_METHOD(_ZendTestClass, is_object);
148153
static ZEND_METHOD(_ZendTestClass, __toString);
@@ -182,6 +187,7 @@ static const zend_function_entry ext_functions[] = {
182187
ZEND_FE(zend_get_current_func_name, arginfo_zend_get_current_func_name)
183188
ZEND_FE(zend_call_method, arginfo_zend_call_method)
184189
ZEND_FE(zend_get_map_ptr_last, arginfo_zend_get_map_ptr_last)
190+
ZEND_FE(zend_test_crash, arginfo_zend_test_crash)
185191
ZEND_NS_FE("ZendTestNS2\\ZendSubNS", namespaced_func, arginfo_ZendTestNS2_ZendSubNS_namespaced_func)
186192
ZEND_FE_END
187193
};

0 commit comments

Comments
 (0)