static inline int convert_cp(UChar32* pcp, zval *zcp) { zend_long cp = -1; if (Z_TYPE_P(zcp) == IS_LONG) { cp = Z_LVAL_P(zcp); } else if (Z_TYPE_P(zcp) == IS_STRING) { int32_t i = 0; size_t zcp_len = Z_STRLEN_P(zcp); if (ZEND_SIZE_T_INT_OVFL(zcp_len)) { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Input string is too long.", 0); return FAILURE; } U8_NEXT(Z_STRVAL_P(zcp), i, zcp_len, cp); if ((size_t)i != zcp_len) { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Passing a UTF-8 character for codepoint requires a string which is exactly one UTF-8 codepoint long.", 0); return FAILURE; } } else { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Invalid parameter for unicode point. Must be either integer or UTF-8 sequence.", 0); return FAILURE; } if ((cp < UCHAR_MIN_VALUE) || (cp > UCHAR_MAX_VALUE)) { intl_error_set_code(NULL, U_ILLEGAL_ARGUMENT_ERROR); intl_error_set_custom_msg(NULL, "Codepoint out of range", 0); return FAILURE; } *pcp = (UChar32)cp; return SUCCESS; }
/* * get php_do_pcre_match */ int pcre_match (char * regex, char * subject) // {{{ { /* parameters */ pcre_cache_entry * pce; /* Compiled regular expression */ zend_string * regex_string; /* Regular expression */ zval * subpats = NULL; /* Array for subpatterns */ zval * matches; /* match counter */ zend_long start_offset = 0; /* Where the new search starts */ int return_val = -1; regex_string = ze_string_init (regex, STRLEN (regex), 0); #if PHP_VERSION_ID < 70300 if ( ZEND_SIZE_T_INT_OVFL (STRLEN (subject))) { php_error_docref (NULL, E_WARNING, "Subject is too long"); return -1; } #endif /* Compile regex or get it from cache. */ if ( (pce = pcre_get_compiled_regex_cache (regex_string) ) == NULL) { return -1; } zend_string_release (regex_string); matches = safe_emalloc (pce->capture_count + 1, sizeof (zval), 0); pce->refcount++; php_pcre_match_impl ( pce, subject, STRLEN (subject), matches, subpats, 0, 0, 0, start_offset ); pce->refcount--; if ( Z_TYPE_P (matches) != IS_LONG ) { kr_safe_efree (matches); return -1; } return_val = (int) Z_LVAL_P (matches); kr_safe_efree (matches); return return_val; } // }}}
static zend_string* php_password_get_salt(zval *return_value, size_t required_salt_len, HashTable *options) { zend_string *buffer; zval *option_buffer; if (!options || !(option_buffer = zend_hash_str_find(options, "salt", sizeof("salt") - 1))) { buffer = php_password_make_salt(required_salt_len); if (!buffer) { RETVAL_FALSE; } return buffer; } php_error_docref(NULL, E_DEPRECATED, "Use of the 'salt' option to password_hash is deprecated"); switch (Z_TYPE_P(option_buffer)) { case IS_STRING: buffer = zend_string_copy(Z_STR_P(option_buffer)); break; case IS_LONG: case IS_DOUBLE: case IS_OBJECT: buffer = zval_get_string(option_buffer); break; case IS_FALSE: case IS_TRUE: case IS_NULL: case IS_RESOURCE: case IS_ARRAY: default: php_error_docref(NULL, E_WARNING, "Non-string salt parameter supplied"); return NULL; } /* XXX all the crypt related APIs work with int for string length. That should be revised for size_t and then we maybe don't require the > INT_MAX check. */ if (ZEND_SIZE_T_INT_OVFL(ZSTR_LEN(buffer))) { php_error_docref(NULL, E_WARNING, "Supplied salt is too long"); zend_string_release(buffer); return NULL; } if (ZSTR_LEN(buffer) < required_salt_len) { php_error_docref(NULL, E_WARNING, "Provided salt is too short: %zd expecting %zd", ZSTR_LEN(buffer), required_salt_len); zend_string_release(buffer); return NULL; } if (php_password_salt_is_alphabet(ZSTR_VAL(buffer), ZSTR_LEN(buffer)) == FAILURE) { zend_string *salt = zend_string_alloc(required_salt_len, 0); if (php_password_salt_to64(ZSTR_VAL(buffer), ZSTR_LEN(buffer), required_salt_len, ZSTR_VAL(salt)) == FAILURE) { php_error_docref(NULL, E_WARNING, "Provided salt is too short: %zd", ZSTR_LEN(buffer)); zend_string_release(salt); zend_string_release(buffer); return NULL; } zend_string_release(buffer); return salt; } else { zend_string *salt = zend_string_alloc(required_salt_len, 0); memcpy(ZSTR_VAL(salt), ZSTR_VAL(buffer), required_salt_len); zend_string_release(buffer); return salt; } }