Convert error filename to zend_string

Error handling functions/callbacks now accept the error filename
as a zend_string* instead of a const char*.
This commit is contained in:
Nikita Popov 2021-04-23 10:47:08 +02:00
parent 8c420bd265
commit a1c6ee2164
9 changed files with 50 additions and 54 deletions

View file

@ -77,7 +77,7 @@ ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path);
ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle); ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle);
ZEND_API void (*zend_ticks_function)(int ticks); ZEND_API void (*zend_ticks_function)(int ticks);
ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data); ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); ZEND_API void (*zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap); void (*zend_printf_to_smart_str)(smart_str *buf, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(const char *name, size_t name_len); ZEND_API char *(*zend_getenv)(const char *name, size_t name_len);
@ -1316,7 +1316,7 @@ ZEND_API zval *zend_get_configuration_directive(zend_string *name) /* {{{ */
} while (0) } while (0)
static ZEND_COLD void zend_error_impl( static ZEND_COLD void zend_error_impl(
int orig_type, const char *error_filename, uint32_t error_lineno, zend_string *message) int orig_type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
{ {
zval params[4]; zval params[4];
zval retval; zval retval;
@ -1381,7 +1381,7 @@ static ZEND_COLD void zend_error_impl(
ZVAL_LONG(&params[0], type); ZVAL_LONG(&params[0], type);
if (error_filename) { if (error_filename) {
ZVAL_STRING(&params[2], error_filename); ZVAL_STR_COPY(&params[2], error_filename);
} else { } else {
ZVAL_NULL(&params[2]); ZVAL_NULL(&params[2]);
} }
@ -1449,7 +1449,7 @@ static ZEND_COLD void zend_error_impl(
/* }}} */ /* }}} */
static ZEND_COLD void zend_error_va_list( static ZEND_COLD void zend_error_va_list(
int orig_type, const char *error_filename, uint32_t error_lineno, int orig_type, zend_string *error_filename, uint32_t error_lineno,
const char *format, va_list args) const char *format, va_list args)
{ {
zend_string *message = zend_vstrpprintf(0, format, args); zend_string *message = zend_vstrpprintf(0, format, args);
@ -1457,7 +1457,7 @@ static ZEND_COLD void zend_error_va_list(
zend_string_release(message); zend_string_release(message);
} }
static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint32_t *lineno) { static ZEND_COLD void get_filename_lineno(int type, zend_string **filename, uint32_t *lineno) {
/* Obtain relevant filename and lineno */ /* Obtain relevant filename and lineno */
switch (type) { switch (type) {
case E_CORE_ERROR: case E_CORE_ERROR:
@ -1479,16 +1479,11 @@ static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint3
case E_USER_DEPRECATED: case E_USER_DEPRECATED:
case E_RECOVERABLE_ERROR: case E_RECOVERABLE_ERROR:
if (zend_is_compiling()) { if (zend_is_compiling()) {
*filename = ZSTR_VAL(zend_get_compiled_filename()); *filename = zend_get_compiled_filename();
*lineno = zend_get_compiled_lineno(); *lineno = zend_get_compiled_lineno();
} else if (zend_is_executing()) { } else if (zend_is_executing()) {
*filename = zend_get_executed_filename(); *filename = zend_get_executed_filename_ex();
if ((*filename)[0] == '[') { /* [no active file] */ *lineno = zend_get_executed_lineno();
*filename = NULL;
*lineno = 0;
} else {
*lineno = zend_get_executed_lineno();
}
} else { } else {
*filename = NULL; *filename = NULL;
*lineno = 0; *lineno = 0;
@ -1500,12 +1495,12 @@ static ZEND_COLD void get_filename_lineno(int type, const char **filename, uint3
break; break;
} }
if (!*filename) { if (!*filename) {
*filename = "Unknown"; *filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
} }
} }
ZEND_API ZEND_COLD void zend_error_at( ZEND_API ZEND_COLD void zend_error_at(
int type, const char *filename, uint32_t lineno, const char *format, ...) { int type, zend_string *filename, uint32_t lineno, const char *format, ...) {
va_list args; va_list args;
if (!filename) { if (!filename) {
@ -1519,7 +1514,7 @@ ZEND_API ZEND_COLD void zend_error_at(
} }
ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) { ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
const char *filename; zend_string *filename;
uint32_t lineno; uint32_t lineno;
va_list args; va_list args;
@ -1530,7 +1525,7 @@ ZEND_API ZEND_COLD void zend_error(int type, const char *format, ...) {
} }
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...) { ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...) {
const char *filename; zend_string *filename;
uint32_t lineno; uint32_t lineno;
va_list args; va_list args;
@ -1541,7 +1536,7 @@ ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...)
} }
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn( ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
int type, const char *filename, uint32_t lineno, const char *format, ...) int type, zend_string *filename, uint32_t lineno, const char *format, ...)
{ {
va_list args; va_list args;
@ -1559,7 +1554,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...) ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *format, ...)
{ {
const char *filename; zend_string *filename;
uint32_t lineno; uint32_t lineno;
va_list args; va_list args;
@ -1572,7 +1567,7 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *
} }
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) { ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message) {
const char *filename; zend_string *filename;
uint32_t lineno; uint32_t lineno;
get_filename_lineno(type, &filename, &lineno); get_filename_lineno(type, &filename, &lineno);
zend_error_impl(type, filename, lineno, message); zend_error_impl(type, filename, lineno, message);

View file

@ -215,7 +215,7 @@ struct _zend_class_entry {
}; };
typedef struct _zend_utility_functions { typedef struct _zend_utility_functions {
void (*error_function)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); void (*error_function)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2); size_t (*printf_function)(const char *format, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
size_t (*write_function)(const char *str, size_t str_length); size_t (*write_function)(const char *str, size_t str_length);
FILE *(*fopen_function)(zend_string *filename, zend_string **opened_path); FILE *(*fopen_function)(zend_string *filename, zend_string **opened_path);
@ -310,7 +310,7 @@ extern ZEND_API zend_write_func_t zend_write;
extern ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path); extern ZEND_API FILE *(*zend_fopen)(zend_string *filename, zend_string **opened_path);
extern ZEND_API void (*zend_ticks_function)(int ticks); extern ZEND_API void (*zend_ticks_function)(int ticks);
extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data); extern ZEND_API void (*zend_interrupt_function)(zend_execute_data *execute_data);
extern ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); extern ZEND_API void (*zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
extern ZEND_API void (*zend_on_timeout)(int seconds); extern ZEND_API void (*zend_on_timeout)(int seconds);
extern ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle); extern ZEND_API zend_result (*zend_stream_open_function)(zend_file_handle *handle);
extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap); extern void (*zend_printf_to_smart_string)(smart_string *buf, const char *format, va_list ap);
@ -330,8 +330,8 @@ ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_noreturn(int type, const char *
/* For custom format specifiers like H */ /* For custom format specifiers like H */
ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...); ZEND_API ZEND_COLD void zend_error_unchecked(int type, const char *format, ...);
/* If filename is NULL the default filename is used. */ /* If filename is NULL the default filename is used. */
ZEND_API ZEND_COLD void zend_error_at(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5); ZEND_API ZEND_COLD void zend_error_at(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, const char *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5); ZEND_API ZEND_COLD ZEND_NORETURN void zend_error_at_noreturn(int type, zend_string *filename, uint32_t lineno, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 4, 5);
ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message); ZEND_API ZEND_COLD void zend_error_zstr(int type, zend_string *message);
ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); ZEND_API ZEND_COLD void zend_throw_error(zend_class_entry *exception_ce, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);

View file

@ -872,7 +872,7 @@ ZEND_API ZEND_COLD zend_object *zend_throw_error_exception(zend_class_entry *exc
} }
/* }}} */ /* }}} */
static void zend_error_va(int type, const char *file, uint32_t lineno, const char *format, ...) /* {{{ */ static void zend_error_va(int type, zend_string *file, uint32_t lineno, const char *format, ...) /* {{{ */
{ {
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@ -900,8 +900,8 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE)); zend_long line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
int type = (ce_exception == zend_ce_parse_error ? E_PARSE : E_COMPILE_ERROR) | E_DONT_BAIL; int type = (ce_exception == zend_ce_parse_error ? E_PARSE : E_COMPILE_ERROR) | E_DONT_BAIL;
zend_observer_error_notify(type, ZSTR_VAL(file), line, message); zend_observer_error_notify(type, file, line, message);
zend_error_cb(type, ZSTR_VAL(file), line, message); zend_error_cb(type, file, line, message);
zend_string_release_ex(file, 0); zend_string_release_ex(file, 0);
zend_string_release_ex(message, 0); zend_string_release_ex(message, 0);
@ -930,7 +930,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
line = zval_get_long(GET_PROPERTY_SILENT(&zv, ZEND_STR_LINE)); line = zval_get_long(GET_PROPERTY_SILENT(&zv, ZEND_STR_LINE));
} }
zend_error_va(E_WARNING, (file && ZSTR_LEN(file) > 0) ? ZSTR_VAL(file) : NULL, line, zend_error_va(E_WARNING, (file && ZSTR_LEN(file) > 0) ? file : NULL, line,
"Uncaught %s in exception handling during call to %s::__toString()", "Uncaught %s in exception handling during call to %s::__toString()",
ZSTR_VAL(Z_OBJCE(zv)->name), ZSTR_VAL(ce_exception->name)); ZSTR_VAL(Z_OBJCE(zv)->name), ZSTR_VAL(ce_exception->name));
@ -944,7 +944,7 @@ ZEND_API ZEND_COLD zend_result zend_exception_error(zend_object *ex, int severit
line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE)); line = zval_get_long(GET_PROPERTY_SILENT(&exception, ZEND_STR_LINE));
zend_error_va(severity | E_DONT_BAIL, zend_error_va(severity | E_DONT_BAIL,
(file && ZSTR_LEN(file) > 0) ? ZSTR_VAL(file) : NULL, line, (file && ZSTR_LEN(file) > 0) ? file : NULL, line,
"Uncaught %s\n thrown", ZSTR_VAL(str)); "Uncaught %s\n thrown", ZSTR_VAL(str));
zend_string_release_ex(str, 0); zend_string_release_ex(str, 0);

View file

@ -245,7 +245,7 @@ ZEND_API void zend_observer_error_register(zend_observer_error_cb cb)
zend_llist_add_element(&zend_observer_error_callbacks, &cb); zend_llist_add_element(&zend_observer_error_callbacks, &cb);
} }
void zend_observer_error_notify(int type, const char *error_filename, uint32_t error_lineno, zend_string *message) void zend_observer_error_notify(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
{ {
zend_llist_element *element; zend_llist_element *element;
zend_observer_error_cb callback; zend_observer_error_cb callback;

View file

@ -72,10 +72,10 @@ ZEND_API void ZEND_FASTCALL zend_observer_fcall_end(
ZEND_API void zend_observer_fcall_end_all(void); ZEND_API void zend_observer_fcall_end_all(void);
typedef void (*zend_observer_error_cb)(int type, const char *error_filename, uint32_t error_lineno, zend_string *message); typedef void (*zend_observer_error_cb)(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message);
ZEND_API void zend_observer_error_register(zend_observer_error_cb callback); ZEND_API void zend_observer_error_register(zend_observer_error_cb callback);
void zend_observer_error_notify(int type, const char *error_filename, uint32_t error_lineno, zend_string *message); void zend_observer_error_notify(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message);
END_EXTERN_C() END_EXTERN_C()

View file

@ -505,6 +505,7 @@ EMPTY_SWITCH_DEFAULT_CASE()
_(ZEND_STR_PAAMAYIM_NEKUDOTAYIM, "::") \ _(ZEND_STR_PAAMAYIM_NEKUDOTAYIM, "::") \
_(ZEND_STR_ARGS, "args") \ _(ZEND_STR_ARGS, "args") \
_(ZEND_STR_UNKNOWN, "unknown") \ _(ZEND_STR_UNKNOWN, "unknown") \
_(ZEND_STR_UNKNOWN_CAPITALIZED, "Unknown") \
_(ZEND_STR_EVAL, "eval") \ _(ZEND_STR_EVAL, "eval") \
_(ZEND_STR_INCLUDE, "include") \ _(ZEND_STR_INCLUDE, "include") \
_(ZEND_STR_REQUIRE, "require") \ _(ZEND_STR_REQUIRE, "require") \

View file

@ -122,7 +122,7 @@ static zend_class_entry* (*accelerator_orig_inheritance_cache_get)(zend_class_en
static zend_class_entry* (*accelerator_orig_inheritance_cache_add)(zend_class_entry *ce, zend_class_entry *proto, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, HashTable *dependencies); static zend_class_entry* (*accelerator_orig_inheritance_cache_add)(zend_class_entry *ce, zend_class_entry *proto, zend_class_entry *parent, zend_class_entry **traits_and_interfaces, HashTable *dependencies);
static zend_result (*accelerator_orig_zend_stream_open_function)(zend_file_handle *handle ); static zend_result (*accelerator_orig_zend_stream_open_function)(zend_file_handle *handle );
static zend_string *(*accelerator_orig_zend_resolve_path)(zend_string *filename); static zend_string *(*accelerator_orig_zend_resolve_path)(zend_string *filename);
static void (*accelerator_orig_zend_error_cb)(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message); static void (*accelerator_orig_zend_error_cb)(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
static zif_handler orig_chdir = NULL; static zif_handler orig_chdir = NULL;
static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL; static ZEND_INI_MH((*orig_include_path_on_modify)) = NULL;
static zend_result (*orig_post_startup_cb)(void); static zend_result (*orig_post_startup_cb)(void);
@ -1686,12 +1686,12 @@ static void zend_accel_set_auto_globals(int mask)
ZCG(auto_globals_mask) |= mask; ZCG(auto_globals_mask) |= mask;
} }
static void persistent_error_cb(int type, const char *error_filename, const uint32_t error_lineno, zend_string *message) { static void persistent_error_cb(int type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) {
if (ZCG(record_warnings)) { if (ZCG(record_warnings)) {
zend_recorded_warning *warning = emalloc(sizeof(zend_recorded_warning)); zend_recorded_warning *warning = emalloc(sizeof(zend_recorded_warning));
warning->type = type; warning->type = type;
warning->error_lineno = error_lineno; warning->error_lineno = error_lineno;
warning->error_filename = zend_string_init(error_filename, strlen(error_filename), 0); warning->error_filename = zend_string_copy(error_filename);
warning->error_message = zend_string_copy(message); warning->error_message = zend_string_copy(message);
ZCG(num_warnings)++; ZCG(num_warnings)++;
@ -1705,7 +1705,7 @@ static void replay_warnings(zend_persistent_script *script) {
for (uint32_t i = 0; i < script->num_warnings; i++) { for (uint32_t i = 0; i < script->num_warnings; i++) {
zend_recorded_warning *warning = script->warnings[i]; zend_recorded_warning *warning = script->warnings[i];
accelerator_orig_zend_error_cb( accelerator_orig_zend_error_cb(
warning->type, ZSTR_VAL(warning->error_filename), warning->error_lineno, warning->type, warning->error_filename, warning->error_lineno,
warning->error_message); warning->error_message);
} }
} }
@ -4084,13 +4084,13 @@ static void preload_link(void)
if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS) if (!(ce->ce_flags & ZEND_ACC_ANON_CLASS)
&& zend_hash_exists(EG(class_table), key)) { && zend_hash_exists(EG(class_table), key)) {
zend_error_at( zend_error_at(
E_WARNING, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start, E_WARNING, ce->info.user.filename, ce->info.user.line_start,
"Can't preload already declared class %s", ZSTR_VAL(ce->name)); "Can't preload already declared class %s", ZSTR_VAL(ce->name));
} else { } else {
const char *kind, *name; const char *kind, *name;
get_unlinked_dependency(ce, &kind, &name); get_unlinked_dependency(ce, &kind, &name);
zend_error_at( zend_error_at(
E_WARNING, ZSTR_VAL(ce->info.user.filename), ce->info.user.line_start, E_WARNING, ce->info.user.filename, ce->info.user.line_start,
"Can't preload unlinked class %s: %s%s", "Can't preload unlinked class %s: %s%s",
ZSTR_VAL(ce->name), kind, name); ZSTR_VAL(ce->name), kind, name);
} }

View file

@ -68,7 +68,7 @@ static void delete_service(void *service);
static void delete_url(void *handle); static void delete_url(void *handle);
static void delete_hashtable(void *hashtable); static void delete_hashtable(void *hashtable);
static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message); static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message);
#define SOAP_SERVER_BEGIN_CODE() \ #define SOAP_SERVER_BEGIN_CODE() \
bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\ bool _old_handler = SOAP_GLOBAL(use_soap_error_handler);\
@ -164,7 +164,7 @@ zend_class_entry* soap_var_class_entry;
ZEND_DECLARE_MODULE_GLOBALS(soap) ZEND_DECLARE_MODULE_GLOBALS(soap)
static void (*old_error_handler)(int, const char *, const uint32_t, zend_string *); static void (*old_error_handler)(int, zend_string *, const uint32_t, zend_string *);
PHP_RINIT_FUNCTION(soap); PHP_RINIT_FUNCTION(soap);
PHP_MINIT_FUNCTION(soap); PHP_MINIT_FUNCTION(soap);
@ -1799,7 +1799,7 @@ static ZEND_NORETURN void soap_server_fault(char* code, char* string, char *acto
} }
/* }}} */ /* }}} */
static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
{ {
bool _old_in_compilation; bool _old_in_compilation;
zend_execute_data *_old_current_execute_data; zend_execute_data *_old_current_execute_data;
@ -1900,7 +1900,7 @@ static zend_never_inline ZEND_COLD void soap_real_error_handler(int error_num, c
} }
/* }}} */ /* }}} */
static void soap_error_handler(int error_num, const char *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */ static void soap_error_handler(int error_num, zend_string *error_filename, const uint32_t error_lineno, zend_string *message) /* {{{ */
{ {
if (EXPECTED(!SOAP_GLOBAL(use_soap_error_handler))) { if (EXPECTED(!SOAP_GLOBAL(use_soap_error_handler))) {
old_error_handler(error_num, error_filename, error_lineno, message); old_error_handler(error_num, error_filename, error_lineno, message);

View file

@ -1151,7 +1151,7 @@ static void clear_last_error() {
#if ZEND_DEBUG #if ZEND_DEBUG
/* {{{ report_zend_debug_error_notify_cb */ /* {{{ report_zend_debug_error_notify_cb */
static void report_zend_debug_error_notify_cb(int type, const char *error_filename, uint32_t error_lineno, zend_string *message) static void report_zend_debug_error_notify_cb(int type, zend_string *error_filename, uint32_t error_lineno, zend_string *message)
{ {
if (PG(report_zend_debug)) { if (PG(report_zend_debug)) {
bool trigger_break; bool trigger_break;
@ -1168,7 +1168,7 @@ static void report_zend_debug_error_notify_cb(int type, const char *error_filena
break; break;
} }
zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s", error_filename, error_lineno, ZSTR_VAL(message)); zend_output_debug_string(trigger_break, "%s(%" PRIu32 ") : %s", ZSTR_VAL(error_filename), error_lineno, ZSTR_VAL(message));
} }
} }
/* }}} */ /* }}} */
@ -1176,7 +1176,7 @@ static void report_zend_debug_error_notify_cb(int type, const char *error_filena
/* {{{ php_error_cb /* {{{ php_error_cb
extended error handling function */ extended error handling function */
static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, const uint32_t error_lineno, zend_string *message) static ZEND_COLD void php_error_cb(int orig_type, zend_string *error_filename, const uint32_t error_lineno, zend_string *message)
{ {
bool display; bool display;
int type = orig_type & E_ALL; int type = orig_type & E_ALL;
@ -1188,7 +1188,7 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
if (zend_string_equals(PG(last_error_message), message) if (zend_string_equals(PG(last_error_message), message)
|| (!PG(ignore_repeated_source) || (!PG(ignore_repeated_source)
&& ((PG(last_error_lineno) != (int)error_lineno) && ((PG(last_error_lineno) != (int)error_lineno)
|| strcmp(PG(last_error_file), error_filename)))) { || strcmp(PG(last_error_file), ZSTR_VAL(error_filename))))) {
display = 1; display = 1;
} else { } else {
display = 0; display = 0;
@ -1223,11 +1223,11 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
if (display) { if (display) {
clear_last_error(); clear_last_error();
if (!error_filename) { if (!error_filename) {
error_filename = "Unknown"; error_filename = ZSTR_KNOWN(ZEND_STR_UNKNOWN_CAPITALIZED);
} }
PG(last_error_type) = type; PG(last_error_type) = type;
PG(last_error_message) = zend_string_copy(message); PG(last_error_message) = zend_string_copy(message);
PG(last_error_file) = strdup(error_filename); PG(last_error_file) = strdup(ZSTR_VAL(error_filename));
PG(last_error_lineno) = error_lineno; PG(last_error_lineno) = error_lineno;
} }
@ -1287,14 +1287,14 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, ZSTR_VAL(message), GetCommandLine()); syslog(LOG_ALERT, "PHP %s: %s (%s)", error_type_str, ZSTR_VAL(message), GetCommandLine());
} }
#endif #endif
spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %" PRIu32, error_type_str, ZSTR_VAL(message), error_filename, error_lineno); spprintf(&log_buffer, 0, "PHP %s: %s in %s on line %" PRIu32, error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
php_log_err_with_severity(log_buffer, syslog_type_int); php_log_err_with_severity(log_buffer, syslog_type_int);
efree(log_buffer); efree(log_buffer);
} }
if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) { if (PG(display_errors) && ((module_initialized && !PG(during_request_startup)) || (PG(display_startup_errors)))) {
if (PG(xmlrpc_errors)) { if (PG(xmlrpc_errors)) {
php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" ZEND_LONG_FMT "</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %" PRIu32 "</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, ZSTR_VAL(message), error_filename, error_lineno); php_printf("<?xml version=\"1.0\"?><methodResponse><fault><value><struct><member><name>faultCode</name><value><int>" ZEND_LONG_FMT "</int></value></member><member><name>faultString</name><value><string>%s:%s in %s on line %" PRIu32 "</string></value></member></struct></value></fault></methodResponse>", PG(xmlrpc_error_number), error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
} else { } else {
char *prepend_string = INI_STR("error_prepend_string"); char *prepend_string = INI_STR("error_prepend_string");
char *append_string = INI_STR("error_append_string"); char *append_string = INI_STR("error_append_string");
@ -1302,22 +1302,22 @@ static ZEND_COLD void php_error_cb(int orig_type, const char *error_filename, co
if (PG(html_errors)) { if (PG(html_errors)) {
if (type == E_ERROR || type == E_PARSE) { if (type == E_ERROR || type == E_PARSE) {
zend_string *buf = escape_html(ZSTR_VAL(message), ZSTR_LEN(message)); zend_string *buf = escape_html(ZSTR_VAL(message), ZSTR_LEN(message));
php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), error_filename, error_lineno, STR_PRINT(append_string)); php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(buf), ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
zend_string_free(buf); zend_string_free(buf);
} else { } else {
php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(message), error_filename, error_lineno, STR_PRINT(append_string)); php_printf("%s<br />\n<b>%s</b>: %s in <b>%s</b> on line <b>%" PRIu32 "</b><br />\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
} }
} else { } else {
/* Write CLI/CGI errors to stderr if display_errors = "stderr" */ /* Write CLI/CGI errors to stderr if display_errors = "stderr" */
if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) && if ((!strcmp(sapi_module.name, "cli") || !strcmp(sapi_module.name, "cgi") || !strcmp(sapi_module.name, "phpdbg")) &&
PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR PG(display_errors) == PHP_DISPLAY_ERRORS_STDERR
) { ) {
fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, ZSTR_VAL(message), error_filename, error_lineno); fprintf(stderr, "%s: %s in %s on line %" PRIu32 "\n", error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno);
#ifdef PHP_WIN32 #ifdef PHP_WIN32
fflush(stderr); fflush(stderr);
#endif #endif
} else { } else {
php_printf("%s\n%s: %s in %s on line %" PRIu32 "\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(message), error_filename, error_lineno, STR_PRINT(append_string)); php_printf("%s\n%s: %s in %s on line %" PRIu32 "\n%s", STR_PRINT(prepend_string), error_type_str, ZSTR_VAL(message), ZSTR_VAL(error_filename), error_lineno, STR_PRINT(append_string));
} }
} }
} }