Add a new zend API to check that strings don't have NUL bytes (#9375)

Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
This commit is contained in:
George Peter Banyard 2022-08-22 15:28:38 +01:00 committed by GitHub
parent a5d84ba0d8
commit d0d6dae8f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -54,6 +54,9 @@ PHP 8.2 INTERNALS UPGRADE NOTES
* Registered zend_observer_fcall_init handlers are now also called for internal functions.
* The pestrdup and pestrndup macros and zend_strndup function are now also infallible
for persistent strings, so checking for NULL is no longer necessary.
* The CHECK_NULL_PATH and CHECK_ZVAL_NULL_PATH macros are now wrappers using
the new inline functions: bool zend_str_has_nul_byte(const zend_string *str)
and zend_char_has_nul_byte(const char *s, size_t known_length)
========================
2. Build system changes

View File

@ -823,8 +823,18 @@ END_EXTERN_C()
#define CHECK_ZVAL_STRING(z)
#endif
#define CHECK_ZVAL_NULL_PATH(p) (Z_STRLEN_P(p) != strlen(Z_STRVAL_P(p)))
#define CHECK_NULL_PATH(p, l) (strlen(p) != (size_t)(l))
static zend_always_inline bool zend_str_has_nul_byte(const zend_string *str)
{
return ZSTR_LEN(str) != strlen(ZSTR_VAL(str));
}
static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t known_length)
{
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)); \