Compare commits

...
20 Commits
Author SHA1 Message Date
Anatol Belski 140e2adb5a missed piece for renaming
(cherry picked from commit 5ba9eab436)
2016-10-13 15:41:36 +02:00
Anatol Belski d23ee8bf76 rename publicly exposed symbol to avoid name conflicts
(cherry picked from commit 730288ae41)
2016-10-13 15:27:58 +02:00
Anatol Belski 56d3f5d91e sync NEWS 2016-10-13 10:48:08 +02:00
Stanislav Malyshev 50775b77dd Fix potential overflows in php_pcre_replace_impl
(cherry picked from commit 9c50ba42d6)
2016-10-13 10:17:01 +02:00
Stanislav Malyshev 48f6137751 Fix outlen for openssl function
Even though datalen can't be over int, outlen can.

(cherry picked from commit cd8c9b0614)
2016-10-13 09:43:59 +02:00
Stanislav Malyshev 7d014f4bd0 Syncronize with 5.6 - __toString should return ""
(cherry picked from commit 2301608736)
2016-10-13 09:29:46 +02:00
Anatol Belski cb6f00c0a5 sync NEWS 2016-10-13 00:56:45 +02:00
Stanislav Malyshev 87202a52f4 Fix bug #73189 - Memcpy negative size parameter php_resolve_path
(cherry picked from commit da7e89cde8)
(cherry picked from commit c4c2cce37d)
2016-10-13 00:51:13 +02:00
Anatol Belski 4094e54c26 update len in fallback cases
(cherry picked from commit 58b18892bf)
2016-10-13 00:50:58 +02:00
Stanislav Malyshev 85998b2a7e Fix bug #73190: memcpy negative parameter _bc_new_num_ex
(cherry picked from commit 40e7baab3c)
(cherry picked from commit 74b5662536)
2016-10-13 00:49:25 +02:00
Stanislav Malyshev d13507d2e6 Fix bug #73147: Use After Free in PHP7 unserialize()
(cherry picked from commit 0e6fe3a4c9)
(cherry picked from commit f42cbd749c)
2016-10-13 00:36:57 +02:00
Anatol Belski 84b2d938b7 fix typo
(cherry picked from commit efc1f33b58)
2016-10-13 00:36:41 +02:00
Anatol Belski 3ec841fcb1 followup with #73276 merge
(cherry picked from commit b135ba3fa9)
2016-10-13 00:36:25 +02:00
Anatol Belski 91ec0ac723 fix test
(cherry picked from commit 7c6cb1282d)
2016-10-13 00:35:30 +02:00
Stanislav Malyshev 1c2d486cb1 Fix bug #73276 - crash in openssl_random_pseudo_bytes function
(cherry picked from commit 85a22a0af0)
(cherry picked from commit 7dc8b5e7ae)
2016-10-13 00:35:18 +02:00
Stanislav Malyshev 850504ae7d Fix bug #73293 - NULL pointer dereference in SimpleXMLElement::asXML()
(cherry picked from commit 96a8cf8e1b)
(cherry picked from commit 4ef79370a8)
2016-10-13 00:35:06 +02:00
Anatol Belski 9557f711d4 avoid strlen
(cherry picked from commit aaa5d07365)
2016-10-13 00:31:18 +02:00
Stanislav Malyshev 142a94516e Bug #73218: add mitigation for ICU int overflow
(cherry picked from commit d946d10293)
(cherry picked from commit b26b02b2df)
2016-10-13 00:31:02 +02:00
Stanislav Malyshev 6329a1eb78 Add more locale length checks, due to ICU bugs.
(cherry picked from commit d3eb58332a)
(cherry picked from commit 87a8240b5a)
2016-10-13 00:30:49 +02:00
Stanislav Malyshev 512d3c679d Fix bug #73150: missing NULL check in dom_document_save_html
(cherry picked from commit 1c0e9126fb)
(cherry picked from commit d1e878f272)
2016-10-13 00:30:23 +02:00
20 changed files with 192 additions and 67 deletions

No files matched your search

+27
View File
@@ -13,10 +13,23 @@ PHP NEWS
. Fixed bug #73163 (PHP hangs if error handler throws while accessing undef
const in default value). (Nikita)
. Fixed bug #73172 (parse error: Invalid numeric literal). (Nikita, Anatol)
. Fixed for #73240 (Write out of bounds at number_format). (Stas)
. Fixed bug #73147 (Use After Free in PHP7 unserialize()). (Stas)
. Fixed bug #73189 (Memcpy negative size parameter php_resolve_path). (Stas)
- BCmath:
. Fix bug #73190 (memcpy negative parameter _bc_new_num_ex). (Stas)
- COM:
. Fixed bug #73126 (Cannot pass parameter 1 by reference). (Anatol)
- Date:
. Fixed bug #73091 (Unserializing DateInterval object may lead to __toString
invocation). (Stas)
- DOM:
. Fixed bug #73150 (missing NULL check in dom_document_save_html). (Stas)
- Filter:
. Fixed bug #72972 (Bad filter for the flags FILTER_FLAG_NO_RES_RANGE and
FILTER_FLAG_NO_PRIV_RANGE). (julien)
@@ -38,6 +51,9 @@ PHP NEWS
files). (cmb)
. Fixed bug #73161 (imagecreatefromgd2() may leak memory). (cmb)
- Intl:
. Fixed bug #73218 (add mitigation for ICU int overflow). (Stas)
- Mbstring:
. Fixed bug #66797 (mb_substr only takes 32-bit signed integer). (cmb)
. Fixed bug #66964 (mb_convert_variables() cannot detect recursion) (Yasuo)
@@ -55,10 +71,13 @@ PHP NEWS
- OpenSSL:
. Fixed bug #73072 (Invalid path SNI_server_certs causes segfault).
(Jakub Zelenka)
. Fixed bug #73276 (crash in openssl_random_pseudo_bytes function). (Stas)
. Fixed bug #73275 (crash in openssl_encrypt function). (Stas)
- PCRE:
. Fixed bug #73121 (Bundled PCRE doesn't compile because JIT isn't supported
on s390). (Anatol)
. Fixed bug #73174 (heap overflow in php_pcre_replace_impl). (Stas)
- PDO_DBlib:
. Fixed bug #72414 (Never quote values as raw binary data). (Adam Baratz)
@@ -82,11 +101,19 @@ PHP NEWS
. Fixed bug #73100 (session_destroy null dereference in ps_files_path_create).
(cmb)
- SimpleXML:
. Fixed bug #73293 (NULL pointer dereference in SimpleXMLElement::asXML()).
(Stas)
- SOAP:
. Fixed bug #71711 (Soap Server Member variables reference bug). (Nikita)
. Fixed bug #71996 (Using references in arrays doesn't work like expected).
(Nikita)
- SPL:
. Fixed bug #73257, #73258 (SplObjectStorage unserialize allows use of
non-object as key). (Stas)
- SQLite3:
. Updated bundled SQLite3 to 3.14.2. (cmb)
+18
View File
@@ -3847,6 +3847,24 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zval *object, c
}
/* }}} */
ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length) /* {{{ */
{
zval property;
zend_class_entry *old_scope = EG(scope);
EG(scope) = scope;
if (!Z_OBJ_HT_P(object)->unset_property) {
zend_error_noreturn(E_CORE_ERROR, "Property %s of class %s cannot be unset", name, ZSTR_VAL(Z_OBJCE_P(object)->name));
}
ZVAL_STRINGL(&property, name, name_length);
Z_OBJ_HT_P(object)->unset_property(object, &property, 0);
zval_ptr_dtor(&property);
EG(scope) = old_scope;
}
/* }}} */
ZEND_API void zend_update_property_bool(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_long value) /* {{{ */
{
zval tmp;
+1
View File
@@ -343,6 +343,7 @@ ZEND_API void zend_update_property_double(zend_class_entry *scope, zval *object,
ZEND_API void zend_update_property_str(zend_class_entry *scope, zval *object, const char *name, size_t name_length, zend_string *value);
ZEND_API void zend_update_property_string(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value);
ZEND_API void zend_update_property_stringl(zend_class_entry *scope, zval *object, const char *name, size_t name_length, const char *value, size_t value_length);
ZEND_API void zend_unset_property(zend_class_entry *scope, zval *object, const char *name, size_t name_length);
ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *name, size_t name_length, zval *value);
ZEND_API int zend_update_static_property_null(zend_class_entry *scope, const char *name, size_t name_length);
+6 -19
View File
@@ -1472,7 +1472,7 @@ static void *zend_mm_realloc_heap(zend_mm_heap *heap, void *ptr, size_t size, si
#endif
#ifdef ZEND_WIN32
/* On Windows we don't have ability to extend huge blocks in-place.
* We allocate them with 2MB size granularity, to avoid many
* We allocate them with 2MB size granularity, to avoid many
* reallocations when they are extended by small pieces
*/
new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE));
@@ -1740,7 +1740,7 @@ static void *zend_mm_alloc_huge(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_D
{
#ifdef ZEND_WIN32
/* On Windows we don't have ability to extend huge blocks in-place.
* We allocate them with 2MB size granularity, to avoid many
* We allocate them with 2MB size granularity, to avoid many
* reallocations when they are extended by small pieces
*/
size_t new_size = ZEND_MM_ALIGNED_SIZE_EX(size, MAX(REAL_PAGE_SIZE, ZEND_MM_CHUNK_SIZE));
@@ -2500,37 +2500,24 @@ ZEND_API size_t ZEND_FASTCALL _zend_mem_block_size(void *ptr ZEND_FILE_LINE_DC Z
return zend_mm_size(AG(mm_heap), ptr ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
}
static zend_always_inline size_t safe_address(size_t nmemb, size_t size, size_t offset)
{
int overflow;
size_t ret = zend_safe_address(nmemb, size, offset, &overflow);
if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return ret;
}
ZEND_API void* ZEND_FASTCALL _safe_emalloc(size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
return emalloc_rel(safe_address(nmemb, size, offset));
return emalloc_rel(zend_safe_address_guarded(nmemb, size, offset));
}
ZEND_API void* ZEND_FASTCALL _safe_malloc(size_t nmemb, size_t size, size_t offset)
{
return pemalloc(safe_address(nmemb, size, offset), 1);
return pemalloc(zend_safe_address_guarded(nmemb, size, offset), 1);
}
ZEND_API void* ZEND_FASTCALL _safe_erealloc(void *ptr, size_t nmemb, size_t size, size_t offset ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
{
return erealloc_rel(ptr, safe_address(nmemb, size, offset));
return erealloc_rel(ptr, zend_safe_address_guarded(nmemb, size, offset));
}
ZEND_API void* ZEND_FASTCALL _safe_realloc(void *ptr, size_t nmemb, size_t size, size_t offset)
{
return perealloc(ptr, safe_address(nmemb, size, offset), 1);
return perealloc(ptr, zend_safe_address_guarded(nmemb, size, offset), 1);
}
+21 -5
View File
@@ -293,10 +293,7 @@ ZEND_METHOD(exception, __construct)
#define CHECK_EXC_TYPE(name, type) \
pvalue = zend_read_property(i_get_exception_base(object), (object), name, sizeof(name) - 1, 1, &value); \
if (Z_TYPE_P(pvalue) != IS_NULL && Z_TYPE_P(pvalue) != type) { \
zval tmp; \
ZVAL_STRINGL(&tmp, name, sizeof(name) - 1); \
Z_OBJ_HANDLER_P(object, unset_property)(object, &tmp, NULL); \
zval_ptr_dtor(&tmp); \
zend_unset_property(i_get_exception_base(object), object, name, sizeof(name)-1); \
}
ZEND_METHOD(exception, __wakeup)
@@ -309,7 +306,12 @@ ZEND_METHOD(exception, __wakeup)
CHECK_EXC_TYPE("file", IS_STRING);
CHECK_EXC_TYPE("line", IS_LONG);
CHECK_EXC_TYPE("trace", IS_ARRAY);
CHECK_EXC_TYPE("previous", IS_OBJECT);
pvalue = zend_read_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1, 1, &value);
if (pvalue && Z_TYPE_P(pvalue) != IS_NULL && (Z_TYPE_P(pvalue) != IS_OBJECT ||
!instanceof_function(Z_OBJCE_P(pvalue), i_get_exception_base(object)) ||
pvalue == object)) {
zend_unset_property(i_get_exception_base(object), object, "previous", sizeof("previous")-1);
}
}
/* }}} */
@@ -771,10 +773,24 @@ ZEND_METHOD(exception, __toString)
zend_string_release(file);
zval_ptr_dtor(&trace);
Z_OBJPROP_P(exception)->u.v.nApplyCount++;
exception = GET_PROPERTY(exception, "previous");
if (exception && Z_TYPE_P(exception) == IS_OBJECT && Z_OBJPROP_P(exception)->u.v.nApplyCount > 0) {
exception = NULL;
}
}
zval_dtor(&fname);
/* Reset apply counts */
while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(exception)) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
if(Z_OBJPROP_P(exception)->u.v.nApplyCount) {
Z_OBJPROP_P(exception)->u.v.nApplyCount--;
} else {
break;
}
exception = GET_PROPERTY(exception, "previous");
}
exception = getThis();
base_ce = i_get_exception_base(exception);
+12
View File
@@ -266,6 +266,18 @@ static zend_always_inline size_t zend_safe_address(size_t nmemb, size_t size, si
}
#endif
static zend_always_inline size_t zend_safe_address_guarded(size_t nmemb, size_t size, size_t offset)
{
int overflow;
size_t ret = zend_safe_address(nmemb, size, offset, &overflow);
if (UNEXPECTED(overflow)) {
zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
return 0;
}
return ret;
}
#endif /* ZEND_MULTIPLY_H */
/*
+4 -1
View File
@@ -49,7 +49,10 @@ _bc_new_num_ex (length, scale, persistent)
int length, scale, persistent;
{
bc_num temp;
/* PHP Change: add length check */
if ((size_t)length+(size_t)scale > INT_MAX) {
zend_error(E_ERROR, "Result too long, max is %d", INT_MAX);
}
/* PHP Change: malloc() -> pemalloc(), removed free_list code */
temp = (bc_num) safe_pemalloc (1, sizeof(bc_struct)+length, scale, persistent);
#if 0
+1 -2
View File
@@ -41,6 +41,5 @@
void bc_out_of_memory (void)
{
(void) fprintf (stderr, "bcmath: out of memory!\n");
exit (1);
zend_error_noreturn(E_ERROR, "bcmath: out of memory!");
}
+1
View File
@@ -137,6 +137,7 @@ ZEND_METHOD(CURLFile, setPostFilename)
Unserialization handler */
ZEND_METHOD(CURLFile, __wakeup)
{
zend_unset_property(curl_CURLFile_class, getThis(), "name", sizeof("name")-1);
zend_update_property_string(curl_CURLFile_class, getThis(), "name", sizeof("name")-1, "");
zend_throw_exception(NULL, "Unserialization of CURLFile instances is not allowed", 0);
}
+20
View File
@@ -0,0 +1,20 @@
--TEST--
Bug #73147: Use After Free in PHP7 unserialize()
--SKIPIF--
<?php
if (!extension_loaded("curl")) {
exit("skip curl extension not loaded");
}
?>
--FILE--
<?php
$poc = 'a:1:{i:0;O:8:"CURLFile":1:{s:4:"name";R:1;}}';
try {
var_dump(unserialize($poc));
} catch(Exception $e) {
echo $e->getMessage();
}
?>
--EXPECT--
Unserialization of CURLFile instances is not allowed
+2 -2
View File
@@ -1663,7 +1663,7 @@ PHP_FUNCTION(dom_document_savexml)
if (options & LIBXML_SAVE_NOEMPTYTAG) {
xmlSaveNoEmptyTags = saveempty;
}
if (!size) {
if (!size || !mem) {
RETURN_FALSE;
}
RETVAL_STRINGL((char *) mem, size);
@@ -2215,7 +2215,7 @@ PHP_FUNCTION(dom_document_save_html)
#else
htmlDocDumpMemory(docp, &mem, &size);
#endif
if (!size) {
if (!size || !mem) {
RETVAL_FALSE;
} else {
RETVAL_STRINGL((const char*) mem, size);
+13
View File
@@ -405,7 +405,10 @@ static void get_icu_value_src_php( char* tag_name, INTERNAL_FUNCTION_PARAMETERS)
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name_len = strlen(loc_name);
}
INTL_CHECK_LOCALE_LEN(loc_name_len);
/* Call ICU get */
tag_value = get_icu_value_internal( loc_name , tag_name , &result ,0);
@@ -1167,8 +1170,10 @@ PHP_FUNCTION(locale_get_all_variants)
if(loc_name_len == 0) {
loc_name = intl_locale_get_default();
loc_name_len = strlen(loc_name);
}
INTL_CHECK_LOCALE_LEN(loc_name_len);
array_init( return_value );
@@ -1271,12 +1276,16 @@ PHP_FUNCTION(locale_filter_matches)
if(loc_range_len == 0) {
loc_range = intl_locale_get_default();
loc_range_len = strlen(loc_range);
}
if( strcmp(loc_range,"*")==0){
RETURN_TRUE;
}
INTL_CHECK_LOCALE_LEN(loc_range_len);
INTL_CHECK_LOCALE_LEN(lang_tag_len);
if( boolCanonical ){
/* canonicalize loc_range */
can_loc_range=get_icu_value_internal( loc_range , LOC_CANONICALIZE_TAG , &result , 0);
@@ -1551,13 +1560,17 @@ PHP_FUNCTION(locale_lookup)
if(loc_range_len == 0) {
if(fallback_loc_str) {
loc_range = ZSTR_VAL(fallback_loc_str);
loc_range_len = ZSTR_LEN(fallback_loc_str);
} else {
loc_range = intl_locale_get_default();
loc_range_len = strlen(loc_range);
}
}
hash_arr = Z_ARRVAL_P(arr);
INTL_CHECK_LOCALE_LEN(loc_range_len);
if( !hash_arr || zend_hash_num_elements( hash_arr ) == 0 ) {
RETURN_EMPTY_STRING();
}
@@ -101,6 +101,13 @@ static int resourcebundle_ctor(INTERNAL_FUNCTION_PARAMETERS, zend_bool is_constr
locale = intl_locale_get_default();
}
if (bundlename_len >= MAXPATHLEN) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "Bundle name too long", 0 );
zval_dtor(return_value);
ZVAL_NULL(return_value);
return FAILURE;
}
if (fallback) {
rb->me = ures_open(bundlename, locale, &INTL_DATA_ERROR_CODE(rb));
} else {
@@ -331,6 +338,11 @@ PHP_FUNCTION( resourcebundle_locales )
RETURN_FALSE;
}
if (bundlename_len >= MAXPATHLEN) {
intl_error_set( NULL, U_ILLEGAL_ARGUMENT_ERROR, "resourcebundle_locales: bundle name too long", 0 );
RETURN_FALSE;
}
if(bundlename_len == 0) {
// fetch default locales list
bundlename = NULL;
+1 -3
View File
@@ -9,6 +9,4 @@ $out = locale_get_primary_language($var1);
echo strlen($out) . PHP_EOL;
echo unpack('H*', $out)[1] . PHP_EOL;
--EXPECT--
1000
61616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161
0
+15 -9
View File
@@ -5303,7 +5303,8 @@ PHP_FUNCTION(openssl_encrypt)
size_t data_len, method_len, password_len, iv_len = 0, max_iv_len;
const EVP_CIPHER *cipher_type;
EVP_CIPHER_CTX cipher_ctx;
int i=0, outlen, keylen;
int i=0, keylen;
size_t outlen;
zend_string *outbuf;
unsigned char *key;
zend_bool free_iv;
@@ -5334,7 +5335,7 @@ PHP_FUNCTION(openssl_encrypt)
}
free_iv = php_openssl_validate_iv(&iv, &iv_len, max_iv_len);
outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
outbuf = zend_string_alloc(outlen, 0);
EVP_EncryptInit(&cipher_ctx, cipher_type, NULL, NULL);
@@ -5386,7 +5387,8 @@ PHP_FUNCTION(openssl_decrypt)
size_t data_len, method_len, password_len, iv_len = 0;
const EVP_CIPHER *cipher_type;
EVP_CIPHER_CTX cipher_ctx;
int i, outlen, keylen;
int i, keylen;
size_t outlen;
zend_string *outbuf;
unsigned char *key;
zend_string *base64_str = NULL;
@@ -5410,7 +5412,7 @@ PHP_FUNCTION(openssl_decrypt)
}
if (!(options & OPENSSL_RAW_DATA)) {
base64_str = php_base64_decode((unsigned char*)data, (int)data_len);
base64_str = php_base64_decode((unsigned char*)data, data_len);
if (!base64_str) {
php_error_docref(NULL, E_WARNING, "Failed to base64 decode the input");
RETURN_FALSE;
@@ -5430,7 +5432,7 @@ PHP_FUNCTION(openssl_decrypt)
free_iv = php_openssl_validate_iv(&iv, &iv_len, EVP_CIPHER_iv_length(cipher_type));
outlen = (int)data_len + EVP_CIPHER_block_size(cipher_type);
outlen = data_len + EVP_CIPHER_block_size(cipher_type);
outbuf = zend_string_alloc(outlen, 0);
EVP_DecryptInit(&cipher_ctx, cipher_type, NULL, NULL);
@@ -5546,15 +5548,18 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
return;
}
if (buffer_length <= 0) {
RETURN_FALSE;
}
if (zstrong_result_returned) {
zval_dtor(zstrong_result_returned);
ZVAL_FALSE(zstrong_result_returned);
}
if (buffer_length <= 0
#ifndef PHP_WIN32
|| ZEND_LONG_INT_OVFL(buffer_length)
#endif
) {
RETURN_FALSE;
}
buffer = zend_string_alloc(buffer_length, 0);
#ifdef PHP_WIN32
@@ -5570,6 +5575,7 @@ PHP_FUNCTION(openssl_random_pseudo_bytes)
PHP_OPENSSL_CHECK_LONG_TO_INT(buffer_length, length);
PHP_OPENSSL_RAND_ADD_TIME();
/* FIXME loop if requested size > INT_MAX */
if (RAND_bytes((unsigned char*)ZSTR_VAL(buffer), (int)buffer_length) <= 0) {
zend_string_release(buffer);
if (zstrong_result_returned) {
+16 -18
View File
@@ -88,7 +88,7 @@ static void pcre_handle_exec_error(int pcre_code) /* {{{ */
case PCRE_ERROR_BADUTF8_OFFSET:
preg_code = PHP_PCRE_BAD_UTF8_OFFSET_ERROR;
break;
#ifdef HAVE_PCRE_JIT_SUPPORT
case PCRE_ERROR_JIT_STACKLIMIT:
preg_code = PHP_PCRE_JIT_STACKLIMIT_ERROR;
@@ -925,7 +925,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec
to achieve this, unless we're already at the end of the string. */
if (g_notempty != 0 && start_offset < subject_len) {
int unit_len = calculate_unit_length(pce, subject + start_offset);
offsets[0] = (int)start_offset;
offsets[1] = (int)(start_offset + unit_len);
} else
@@ -1125,7 +1125,6 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
int backref; /* Backreference number */
int start_offset; /* Where the new search starts */
int g_notempty=0; /* If the match should not be empty */
int replace_len=0; /* Length of replacement string */
char *replace=NULL, /* Replacement string */
*walkbuf, /* Location of current replacement in the result */
*walk, /* Used to walk the replacement string */
@@ -1133,7 +1132,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
*piece, /* The current piece of subject */
*replace_end=NULL, /* End of replacement string */
walk_last; /* Last walked character */
int result_len; /* Length of result */
size_t result_len; /* Length of result */
unsigned char *mark = NULL; /* Target for MARK name */
zend_string *result; /* Result of replacement */
zend_string *eval_result=NULL; /* Result of custom function */
@@ -1155,8 +1154,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
if (!is_callable_replace) {
replace = Z_STRVAL_P(replace_val);
replace_len = (int)Z_STRLEN_P(replace_val);
replace_end = replace + replace_len;
replace_end = replace + Z_STRLEN_P(replace_val);
}
/* Calculate the size of the offsets array, and allocate memory for it. */
@@ -1224,7 +1222,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
match = subject + offsets[0];
new_len = result_len + offsets[0] - start_offset; /* part before the match */
/* if (!is_callable_replace) */
if (EXPECTED(replace)) {
/* do regular substitution */
@@ -1250,7 +1248,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
}
if (new_len >= alloc_len) {
alloc_len = alloc_len + 2 * new_len;
alloc_len = zend_safe_address_guarded(2, new_len, alloc_len);
if (result == NULL) {
result = zend_string_alloc(alloc_len, 0);
} else {
@@ -1260,7 +1258,7 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
/* copy the part of the string before the match */
memcpy(&ZSTR_VAL(result)[result_len], piece, match-piece);
result_len += (int)(match-piece);
result_len += (match-piece);
/* copy replacement and backrefs */
walkbuf = ZSTR_VAL(result) + result_len;
@@ -1288,14 +1286,14 @@ PHPAPI zend_string *php_pcre_replace_impl(pcre_cache_entry *pce, zend_string *su
}
*walkbuf = '\0';
/* increment the result length by how much we've added to the string */
result_len += (int)(walkbuf - (ZSTR_VAL(result) + result_len));
result_len += (walkbuf - (ZSTR_VAL(result) + result_len));
} else {
/* Use custom function to get replacement string and its length. */
eval_result = preg_do_repl_func(replace_val, subject, offsets, subpat_names, count, mark);
ZEND_ASSERT(eval_result);
new_len += (int)ZSTR_LEN(eval_result);
new_len = zend_safe_address_guarded(1, ZSTR_LEN(eval_result), new_len);
if (new_len >= alloc_len) {
alloc_len = alloc_len + 2 * new_len;
alloc_len = zend_safe_address_guarded(2, new_len, alloc_len);
if (result == NULL) {
result = zend_string_alloc(alloc_len, 0);
} else {
@@ -1517,7 +1515,7 @@ static int preg_replace_impl(zval *return_value, zval *regex, zval *replace, zva
}
}
} ZEND_HASH_FOREACH_END();
} else {
} else {
/* if subject is not an array */
old_replace_count = replace_count;
if ((result = php_replace_in_subject(regex, replace, subject, limit_val, is_callable_replace, &replace_count)) != NULL) {
@@ -1528,7 +1526,7 @@ static int preg_replace_impl(zval *return_value, zval *regex, zval *replace, zva
}
}
}
return replace_count;
}
/* }}} */
@@ -1617,7 +1615,7 @@ static PHP_FUNCTION(preg_replace_callback_array)
Z_PARAM_LONG(limit)
Z_PARAM_ZVAL_EX(zcount, 0, 1)
ZEND_PARSE_PARAMETERS_END();
ZVAL_UNDEF(&zv);
ZEND_HASH_FOREACH_STR_KEY_VAL(Z_ARRVAL_P(pattern), str_idx, replace) {
if (str_idx) {
@@ -1626,7 +1624,7 @@ static PHP_FUNCTION(preg_replace_callback_array)
php_error_docref(NULL, E_WARNING, "Delimiter must not be alphanumeric or backslash");
zval_ptr_dtor(return_value);
RETURN_NULL();
}
}
if (!zend_is_callable(replace, 0, &callback_name)) {
php_error_docref(NULL, E_WARNING, "'%s' is not a valid callback", ZSTR_VAL(callback_name));
@@ -1648,14 +1646,14 @@ static PHP_FUNCTION(preg_replace_callback_array)
zval_ptr_dtor(&regex);
if (Z_ISUNDEF(zv)) {
RETURN_NULL();
RETURN_NULL();
}
ZVAL_COPY_VALUE(return_value, &zv);
if (UNEXPECTED(EG(exception))) {
zval_ptr_dtor(return_value);
RETURN_NULL();
RETURN_NULL();
}
} ZEND_HASH_FOREACH_END();
+16 -3
View File
@@ -1472,9 +1472,15 @@ SXE_METHOD(asXML)
if (node) {
if (node->parent && (XML_DOCUMENT_NODE == node->parent->type)) {
xmlDocDumpMemoryEnc((xmlDocPtr) sxe->document->ptr, &strval, &strval_len, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
RETVAL_STRINGL((char *)strval, strval_len);
if (!strval) {
RETVAL_FALSE;
} else {
RETVAL_STRINGL((char *)strval, strval_len);
}
xmlFree(strval);
} else {
char *return_content;
size_t return_len;
/* Should we be passing encoding information instead of NULL? */
outbuf = xmlAllocOutputBuffer(NULL);
@@ -1485,10 +1491,17 @@ SXE_METHOD(asXML)
xmlNodeDumpOutput(outbuf, (xmlDocPtr) sxe->document->ptr, node, 0, 0, (const char *) ((xmlDocPtr) sxe->document->ptr)->encoding);
xmlOutputBufferFlush(outbuf);
#ifdef LIBXML2_NEW_BUFFER
RETVAL_STRINGL((char *)xmlOutputBufferGetContent(outbuf), xmlOutputBufferGetSize(outbuf));
return_content = (char *)xmlOutputBufferGetContent(outbuf);
return_len = xmlOutputBufferGetSize(outbuf);
#else
RETVAL_STRINGL((char *)outbuf->buffer->content, outbuf->buffer->use);
return_content = (char *)outbuf->buffer->content;
return_len = outbuf->buffer->use;
#endif
if (!return_content) {
RETVAL_FALSE;
} else {
RETVAL_STRINGL(return_content, return_len);
}
xmlOutputBufferClose(outbuf);
}
} else {
+1 -1
View File
@@ -2810,7 +2810,7 @@ SPL_METHOD(CachingIterator, __toString)
if (Z_TYPE(intern->u.caching.zstr) == IS_STRING) {
RETURN_STR_COPY(Z_STR_P(&intern->u.caching.zstr));
} else {
RETURN_NULL();
RETURN_EMPTY_STRING();
}
} /* }}} */
@@ -13,4 +13,4 @@ $ci->__toString() // if conversion to string is done by echo, for example, an ex
);
?>
--EXPECTF--
NULL
string(0) ""
+4 -3
View File
@@ -536,7 +536,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length,
}
end = strchr(p, DEFAULT_DIR_SEPARATOR);
if (end) {
if ((end-ptr) + 1 + filename_length + 1 >= MAXPATHLEN) {
if (filename_length > (MAXPATHLEN - 2) || (end-ptr) > MAXPATHLEN || (end-ptr) + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) {
ptr = end + 1;
continue;
}
@@ -545,9 +545,9 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length,
memcpy(trypath+(end-ptr)+1, filename, filename_length+1);
ptr = end+1;
} else {
int len = (int)strlen(ptr);
size_t len = strlen(ptr);
if (len + 1 + filename_length + 1 >= MAXPATHLEN) {
if (filename_length > (MAXPATHLEN - 2) || len > MAXPATHLEN || len + 1 + (size_t)filename_length + 1 >= MAXPATHLEN) {
break;
}
memcpy(trypath, ptr, len);
@@ -585,6 +585,7 @@ PHPAPI zend_string *php_resolve_path(const char *filename, int filename_length,
while ((--exec_fname_length < SIZE_MAX) && !IS_SLASH(exec_fname[exec_fname_length]));
if (exec_fname_length > 0 &&
filename_length < (MAXPATHLEN - 2) &&
exec_fname_length + 1 + filename_length + 1 < MAXPATHLEN) {
memcpy(trypath, exec_fname, exec_fname_length + 1);
memcpy(trypath+exec_fname_length + 1, filename, filename_length+1);