From 31f699a10be32223ba772042c251e189dfb7ee1b Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Fri, 19 Aug 2022 13:34:59 +0100 Subject: [PATCH 1/2] Add a new zend API to check that strings don't have NUL bytes --- UPGRADING.INTERNALS | 3 +++ Zend/zend_API.h | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 162b145fcfa1a..24ed5e9b53862 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -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 diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 2970299836689..d8ed903d82e7d 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -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)); \ From f4611a15e141d51c3770d75bc30e16e809e386bc Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Mon, 22 Aug 2022 15:27:56 +0100 Subject: [PATCH 2/2] Update Zend/zend_API.h Co-authored-by: Christoph M. Becker --- Zend/zend_API.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index d8ed903d82e7d..5821a5b5f35bb 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -834,7 +834,7 @@ static zend_always_inline bool zend_char_has_nul_byte(const char *s, size_t know /* 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 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)); \