mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
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:
parent
a5d84ba0d8
commit
d0d6dae8f7
@ -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
|
||||
|
@ -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)); \
|
||||
|
Loading…
Reference in New Issue
Block a user