Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions UPGRADING.INTERNALS
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)); \
Expand Down