Skip to content

Commit e290140

Browse files
committed
Add a new zend API to check that strings don't have NUL bytes
1 parent d766e91 commit e290140

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

UPGRADING.INTERNALS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ PHP 8.2 INTERNALS UPGRADE NOTES
5454
* Registered zend_observer_fcall_init handlers are now also called for internal functions.
5555
* The pestrdup and pestrndup macros and zend_strndup function are now also infallible
5656
for persistent strings, so checking for NULL is no longer necessary.
57+
* The CHECK_NULL_PATH and CHECK_ZVAL_NULL_PATH macros are now wrappers using
58+
the new inline functions: bool zend_str_has_nul_byte(const zend_string *str)
59+
and zend_char_has_nul_byte(const char *s, size_t known_length)
5760

5861
========================
5962
2. Build system changes

Zend/zend_API.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,8 +823,18 @@ END_EXTERN_C()
823823
#define CHECK_ZVAL_STRING(z)
824824
#endif
825825

826-
#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
827-
#define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
826+
static zend_always_inline bool zend_str_has_nul_byte(const zend_string *str)
827+
{
828+
return ZSTR_LEN(str) != strlen(ZSTR_VAL(str));
829+
}
830+
static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t known_length)
831+
{
832+
return known_length != strlen(s);
833+
}
834+
835+
/* Compatibility with PHP 8.1 and below */
836+
#define CHECK_ZVAL_NULL_PATH(p) zend_str_has_nul_byte(Z_STR_P(p))
837+
#define CHECK_NULL_PATH(p, l) zend_char_has_nul_byte((p),(l))
828838

829839
#define ZVAL_STRINGL(z, s, l) do { \
830840
ZVAL_NEW_STR(z, zend_string_init(s, l, 0)); \

0 commit comments

Comments
 (0)