Skip to content
Draft
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
17 changes: 12 additions & 5 deletions ext/libxml/libxml.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,14 @@ static void php_libxml_internal_error_handler_ex(php_libxml_error_level error_ty
php_libxml_ctx_error_level(E_NOTICE, ctx, ZSTR_VAL(LIBXML(error_buffer).s), line);
break;
default:
php_error_docref(NULL, E_WARNING, "%s", ZSTR_VAL(LIBXML(error_buffer).s));
// Remove the extra NULL at the end - fine to manipulate the error buffer because it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code was fine. I don't believe there can be embedded NUL bytes, so why complicate this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Performance - %s requires a strlen call to identify how long the string is

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... for an error path? The complexity isnt worth it

// is about to be freed
if (ZSTR_LEN(LIBXML(error_buffer).s) > 1
&& ZSTR_VAL(LIBXML(error_buffer).s)[ZSTR_LEN(LIBXML(error_buffer).s) - 1] == '\0'
) {
ZSTR_LEN(LIBXML(error_buffer).s)--;
}
php_error_docref(NULL, E_WARNING, "%pS", LIBXML(error_buffer).s);
}
}
smart_str_free(&LIBXML(error_buffer));
Expand Down Expand Up @@ -780,8 +787,8 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,

if (Z_ISUNDEF(retval)) {
php_libxml_ctx_error(context,
"Call to user entity loader callback '%s' has failed",
ZSTR_VAL(LIBXML(entity_loader_callback).function_handler->common.function_name));
"Call to user entity loader callback '%pS' has failed",
LIBXML(entity_loader_callback).function_handler->common.function_name);
} else {
if (Z_TYPE(retval) == IS_STRING) {
is_string:
Expand All @@ -794,8 +801,8 @@ static xmlParserInputPtr php_libxml_external_entity_loader(const char *URL,
zend_string *callable_name = zend_get_callable_name(&callable);
zend_string *func_name = get_active_function_or_method_name();
zend_type_error(
"%s(): The user entity loader callback \"%s\" has returned a resource, but it is not a stream",
ZSTR_VAL(func_name), ZSTR_VAL(callable_name));
"%pS(): The user entity loader callback \"%pS\" has returned a resource, but it is not a stream",
func_name, callable_name);
zend_string_release(func_name);
zend_string_release(callable_name);
zval_ptr_dtor(&callable);
Expand Down
Loading