Skip to content

Commit 6da93a8

Browse files
authored
zend_API: Remove CHECK*NULL_PATH (php#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.
1 parent c42fcec commit 6da93a8

File tree

9 files changed

+14
-15
lines changed

9 files changed

+14
-15
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ PHP 8.6 INTERNALS UPGRADE NOTES
2626
call the variant without the leading underscore instead.
2727
Affected: _zval_get_long, _zval_get_double, _zval_get_string,
2828
_zval_get_long_func, _zval_get_double_func, _zval_get_string_func
29+
. CHECK_ZVAL_NULL_PATH() and CHECK_NULL_PATH() have been removed, use
30+
zend_str_has_nul_byte(Z_STR_P(...)) and zend_char_has_nul_byte()
31+
respectively.
2932

3033
========================
3134
2. Build system changes

Zend/zend_API.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -951,10 +951,6 @@ static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t know
951951
return known_length != strlen(s);
952952
}
953953

954-
/* Compatibility with PHP 8.1 and below */
955-
#define CHECK_ZVAL_NULL_PATH(p) zend_str_has_nul_byte(Z_STR_P(p))
956-
#define CHECK_NULL_PATH(p, l) zend_char_has_nul_byte(p, l)
957-
958954
#define ZVAL_STRINGL(z, s, l) do { \
959955
ZVAL_NEW_STR(z, zend_string_init(s, l, 0)); \
960956
} while (0)

ext/bz2/bz2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ PHP_FUNCTION(bzopen)
352352
RETURN_THROWS();
353353
}
354354

355-
if (CHECK_ZVAL_NULL_PATH(file)) {
355+
if (zend_str_has_nul_byte(Z_STR_P(file))) {
356356
zend_argument_type_error(1, "must not contain null bytes");
357357
RETURN_THROWS();
358358
}

ext/dom/document.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ xmlDocPtr dom_document_parser(zval *id, dom_load_mode mode, const char *source,
13811381
recover = doc_props->recover || (options & XML_PARSE_RECOVER) == XML_PARSE_RECOVER;
13821382

13831383
if (mode == DOM_LOAD_FILE) {
1384-
if (CHECK_NULL_PATH(source, source_len)) {
1384+
if (zend_char_has_nul_byte(source, source_len)) {
13851385
zend_argument_value_error(1, "must not contain any null bytes");
13861386
return NULL;
13871387
}
@@ -1864,7 +1864,7 @@ static void dom_document_schema_validate(INTERNAL_FUNCTION_PARAMETERS, int type)
18641864

18651865
switch (type) {
18661866
case DOM_LOAD_FILE:
1867-
if (CHECK_NULL_PATH(source, source_len)) {
1867+
if (zend_char_has_nul_byte(source, source_len)) {
18681868
PHP_LIBXML_RESTORE_GLOBALS(new_parser_ctxt);
18691869
zend_argument_value_error(1, "must not contain any null bytes");
18701870
RETURN_THROWS();
@@ -1971,7 +1971,7 @@ static void dom_document_relaxNG_validate(INTERNAL_FUNCTION_PARAMETERS, int type
19711971

19721972
switch (type) {
19731973
case DOM_LOAD_FILE:
1974-
if (CHECK_NULL_PATH(source, source_len)) {
1974+
if (zend_char_has_nul_byte(source, source_len)) {
19751975
zend_argument_value_error(1, "must not contain any null bytes");
19761976
RETURN_THROWS();
19771977
}
@@ -2064,7 +2064,7 @@ static void dom_load_html(INTERNAL_FUNCTION_PARAMETERS, int mode) /* {{{ */
20642064
}
20652065

20662066
if (mode == DOM_LOAD_FILE) {
2067-
if (CHECK_NULL_PATH(source, source_len)) {
2067+
if (zend_char_has_nul_byte(source, source_len)) {
20682068
zend_argument_value_error(1, "must not contain any null bytes");
20692069
RETURN_THROWS();
20702070
}

ext/gd/gd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4378,7 +4378,7 @@ static gdIOCtx *create_output_context(zval *to_zval, uint32_t arg_num) {
43784378
}
43794379
close_stream = 0;
43804380
} else if (Z_TYPE_P(to_zval) == IS_STRING) {
4381-
if (CHECK_ZVAL_NULL_PATH(to_zval)) {
4381+
if (zend_str_has_nul_byte(Z_STR_P(to_zval))) {
43824382
zend_argument_type_error(arg_num, "must not contain null bytes");
43834383
return NULL;
43844384
}

ext/hash/hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void php_hash_do_hash(
365365
RETURN_THROWS();
366366
}
367367
if (isfilename) {
368-
if (CHECK_NULL_PATH(data, data_len)) {
368+
if (zend_char_has_nul_byte(data, data_len)) {
369369
zend_argument_value_error(1, "must not contain any null bytes");
370370
RETURN_THROWS();
371371
}
@@ -508,7 +508,7 @@ static void php_hash_do_hash_hmac(
508508
}
509509

510510
if (isfilename) {
511-
if (CHECK_NULL_PATH(data, data_len)) {
511+
if (zend_char_has_nul_byte(data, data_len)) {
512512
zend_argument_value_error(2, "must not contain any null bytes");
513513
RETURN_THROWS();
514514
}

ext/openssl/openssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ bool php_openssl_check_path_ex(
303303
fs_file_path_len = file_path_len;
304304
}
305305

306-
if (CHECK_NULL_PATH(fs_file_path, fs_file_path_len)) {
306+
if (zend_char_has_nul_byte(fs_file_path, fs_file_path_len)) {
307307
error_msg = "must not contain any null bytes";
308308
error_type = E_ERROR;
309309
} else if (expand_filepath(fs_file_path, real_path) == NULL) {

ext/phar/phar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2251,7 +2251,7 @@ zend_result phar_split_fname(const char *filename, size_t filename_len, char **a
22512251
#endif
22522252
size_t ext_len;
22532253

2254-
if (CHECK_NULL_PATH(filename, filename_len)) {
2254+
if (zend_char_has_nul_byte(filename, filename_len)) {
22552255
return FAILURE;
22562256
}
22572257

main/fopen_wrappers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, size_t filename_lengt
506506
php_stream_wrapper *wrapper;
507507
zend_string *exec_filename;
508508

509-
if (!filename || CHECK_NULL_PATH(filename, filename_length)) {
509+
if (!filename || zend_char_has_nul_byte(filename, filename_length)) {
510510
return NULL;
511511
}
512512

0 commit comments

Comments
 (0)