1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

zend_API: Remove CHECK*NULL_PATH (#20155)

* tree-wide: Replace `CHECK_NULL_PATH()` by `zend_char_has_nul_byte()`

The former is a direct alias of the latter with a more explicit name and the
former is explicitly documented as a “compatibility” alias.

* tree-wide: Replace `CHECK_ZVAL_NULL_PATH()` by its definition

The former is explicitly documented as a “compatibility” alias.

* zend_API: Remove `CHECK*NULL_PATH`

The `CHECK_ZVAL_NULL_PATH()` macro is unsafe, because it implicitly assumes
that the given `zval*` is `IS_STRING`.

Based on a GitHub search there does not seem to be any user outside of PHP, all
hits were just forks / copies of php-src.
This commit is contained in:
Tim Düsterhus
2025-10-15 10:24:22 +02:00
committed by GitHub
parent c42fcec453
commit 6da93a86f2
9 changed files with 14 additions and 15 deletions

View File

@@ -26,6 +26,9 @@ PHP 8.6 INTERNALS UPGRADE NOTES
call the variant without the leading underscore instead.
Affected: _zval_get_long, _zval_get_double, _zval_get_string,
_zval_get_long_func, _zval_get_double_func, _zval_get_string_func
. CHECK_ZVAL_NULL_PATH() and CHECK_NULL_PATH() have been removed, use
zend_str_has_nul_byte(Z_STR_P(...)) and zend_char_has_nul_byte()
respectively.
========================
2. Build system changes

View File

@@ -951,10 +951,6 @@ static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t know
return known_length != strlen(s);
}
/* Compatibility with PHP 8.1 and below */
#define CHECK_ZVAL_NULL_PATH(p) zend_str_has_nul_byte(Z_STR_P(p))
#define CHECK_NULL_PATH(p, l) zend_char_has_nul_byte(p, l)
#define ZVAL_STRINGL(z, s, l) do { \
ZVAL_NEW_STR(z, zend_string_init(s, l, 0)); \
} while (0)

View File

@@ -352,7 +352,7 @@ PHP_FUNCTION(bzopen)
RETURN_THROWS();
}
if (CHECK_ZVAL_NULL_PATH(file)) {
if (zend_str_has_nul_byte(Z_STR_P(file))) {
zend_argument_type_error(1, "must not contain null bytes");
RETURN_THROWS();
}

View File

@@ -1381,7 +1381,7 @@ xmlDocPtr dom_document_parser(zval *id, dom_load_mode mode, const char *source,
recover = doc_props->recover || (options & XML_PARSE_RECOVER) == XML_PARSE_RECOVER;
if (mode == DOM_LOAD_FILE) {
if (CHECK_NULL_PATH(source, source_len)) {
if (zend_char_has_nul_byte(source, source_len)) {
zend_argument_value_error(1, "must not contain any null bytes");
return NULL;
}
@@ -1864,7 +1864,7 @@ static void dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
switch (type) {
case DOM_LOAD_FILE:
if (CHECK_NULL_PATH(source, source_len)) {
if (zend_char_has_nul_byte(source, source_len)) {
PHP_LIBXML_RESTORE_GLOBALS(new_parser_ctxt);
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
@@ -1971,7 +1971,7 @@ static void dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type
switch (type) {
case DOM_LOAD_FILE:
if (CHECK_NULL_PATH(source, source_len)) {
if (zend_char_has_nul_byte(source, source_len)) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}
@@ -2064,7 +2064,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
}
if (mode == DOM_LOAD_FILE) {
if (CHECK_NULL_PATH(source, source_len)) {
if (zend_char_has_nul_byte(source, source_len)) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}

View File

@@ -4378,7 +4378,7 @@ static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num) {
}
close_stream = 0;
} else if (Z_TYPE_P(to_zval) == IS_STRING) {
if (CHECK_ZVAL_NULL_PATH(to_zval)) {
if (zend_str_has_nul_byte(Z_STR_P(to_zval))) {
zend_argument_type_error(arg_num, "must not contain null bytes");
return NULL;
}

View File

@@ -365,7 +365,7 @@ static void php_hash_do_hash(
RETURN_THROWS();
}
if (isfilename) {
if (CHECK_NULL_PATH(data, data_len)) {
if (zend_char_has_nul_byte(data, data_len)) {
zend_argument_value_error(1, "must not contain any null bytes");
RETURN_THROWS();
}
@@ -508,7 +508,7 @@ static void php_hash_do_hash_hmac(
}
if (isfilename) {
if (CHECK_NULL_PATH(data, data_len)) {
if (zend_char_has_nul_byte(data, data_len)) {
zend_argument_value_error(2, "must not contain any null bytes");
RETURN_THROWS();
}

View File

@@ -303,7 +303,7 @@ bool php_openssl_check_path_ex(
fs_file_path_len = file_path_len;
}
if (CHECK_NULL_PATH(fs_file_path, fs_file_path_len)) {
if (zend_char_has_nul_byte(fs_file_path, fs_file_path_len)) {
error_msg = "must not contain any null bytes";
error_type = E_ERROR;
} else if (expand_filepath(fs_file_path, real_path) == NULL) {

View File

@@ -2251,7 +2251,7 @@ zend_result phar_split_fname(const char *filename, size_t filename_len, char **a
#endif
size_t ext_len;
if (CHECK_NULL_PATH(filename, filename_len)) {
if (zend_char_has_nul_byte(filename, filename_len)) {
return FAILURE;
}

View File

@@ -506,7 +506,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
php_stream_wrapper *wrapper;
zend_string *exec_filename;
if (!filename || CHECK_NULL_PATH(filename, filename_length)) {
if (!filename || zend_char_has_nul_byte(filename, filename_length)) {
return NULL;
}