From b689857d53177b6027679f67fecbde8f36c174d1 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 4 Sep 2017 21:20:49 +0200 Subject: [PATCH 01/11] Revert "Fixed #74977 - Appending AppendIterator leads to segfault" This reverts commit dbc2ffba822d13e74e37f5ba6e106f163c1008e8. --- ext/spl/spl_iterators.c | 7 +------ ext/spl/tests/bug74977.phpt | 13 ------------- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100644 ext/spl/tests/bug74977.phpt diff --git a/ext/spl/spl_iterators.c b/ext/spl/spl_iterators.c index 0daa55f4b44..4373a3b6518 100644 --- a/ext/spl/spl_iterators.c +++ b/ext/spl/spl_iterators.c @@ -3367,7 +3367,7 @@ SPL_METHOD(AppendIterator, __construct) Append an iterator */ SPL_METHOD(AppendIterator, append) { - spl_dual_it_object *intern, *appender; + spl_dual_it_object *intern; zval *it; SPL_FETCH_AND_CHECK_DUAL_IT(intern, getThis()); @@ -3379,11 +3379,6 @@ SPL_METHOD(AppendIterator, append) spl_array_iterator_append(&intern->u.append.zarrayit, it); intern->u.append.iterator->funcs->move_forward(intern->u.append.iterator); }else{ - appender = Z_SPLDUAL_IT_P(it); - if (appender->dit_type == DIT_AppendIterator) { - spl_array_iterator_append(&intern->u.append.zarrayit, &appender->u.append.zarrayit); - return; - } spl_array_iterator_append(&intern->u.append.zarrayit, it); } diff --git a/ext/spl/tests/bug74977.phpt b/ext/spl/tests/bug74977.phpt deleted file mode 100644 index 09e16eedfe4..00000000000 --- a/ext/spl/tests/bug74977.phpt +++ /dev/null @@ -1,13 +0,0 @@ ---TEST-- -Bug #74977: Recursion leads to crash ---FILE-- -append($iterator); -var_dump($iterator); -?> ---EXPECTF-- -object(AppendIterator)#1 (0) { -} - From c2e3541cc1200f38f72deccac66d889888e3949d Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 4 Sep 2017 21:23:07 +0200 Subject: [PATCH 02/11] Add test for bug #75155 --- NEWS | 4 ++++ ext/spl/tests/bug75155.phpt | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 ext/spl/tests/bug75155.phpt diff --git a/NEWS b/NEWS index 8103b9445e4..3803c649048 100644 --- a/NEWS +++ b/NEWS @@ -20,6 +20,10 @@ PHP NEWS . Fixed bug #74631 (PDO_PCO with PHP-FPM: OCI environment initialized before PHP-FPM sets it up). (Ingmar Runge) +- SPL: + . Fixed bug #75155 (AppendIterator::append() is broken when appending another + AppendIterator). (Nikita) + - Standard: . Fixed bug #75097 (gethostname fails if your host name is 64 chars long). (Andrea) diff --git a/ext/spl/tests/bug75155.phpt b/ext/spl/tests/bug75155.phpt new file mode 100644 index 00000000000..0d0c0753e09 --- /dev/null +++ b/ext/spl/tests/bug75155.phpt @@ -0,0 +1,22 @@ +--TEST-- +Bug #75155: AppendIterator::append() is broken when appending another AppendIterator +--FILE-- +append($array_a); + +$iterator2 = new AppendIterator; +$iterator2->append($iterator); +$iterator2->append($array_b); + +foreach ($iterator2 as $current) { + echo $current; +} + +?> +--EXPECT-- +abcdef From cd9d90f4d41c87494dee8ee72c7a48951213296b Mon Sep 17 00:00:00 2001 From: Bouke van der Bijl Date: Mon, 4 Sep 2017 16:28:29 +0200 Subject: [PATCH 03/11] Fixed bug #70470 --- NEWS | 4 ++ sapi/cli/php_cli_server.c | 110 ++++++++++++++++++++++++-------- sapi/cli/tests/bug70470.phpt | 2 - sapi/cli/tests/emptyheader.phpt | 35 ++++++++++ 4 files changed, 123 insertions(+), 28 deletions(-) create mode 100644 sapi/cli/tests/emptyheader.phpt diff --git a/NEWS b/NEWS index 09b0307aba9..3bb2a0791a5 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,10 @@ PHP NEWS - Core: . Fixed #75042 run-tests.php issues with EXTENSION block). (John Boehr) +- CLI server: + . Fixed bug #70470 (Built-in server truncates headers spanning over TCP + packets). (bouk) + - CURL: . Fixed bug #75093 (OpenSSL support not detected). (Remi) diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 5d820743b6c..4d5324f36c0 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -171,6 +171,9 @@ typedef struct php_cli_server_client { char *current_header_name; size_t current_header_name_len; unsigned int current_header_name_allocated:1; + char *current_header_value; + size_t current_header_value_len; + enum { HEADER_NONE=0, HEADER_FIELD, HEADER_VALUE } last_header_element; size_t post_read_offset; php_cli_server_request request; unsigned int content_sender_initialized:1; @@ -1469,7 +1472,7 @@ static void normalize_vpath(char **retval, size_t *retval_len, const char *vpath #ifdef PHP_WIN32 { char *p = decoded_vpath; - + do { if (*p == '\\') { *p = '/'; @@ -1572,50 +1575,100 @@ static int php_cli_server_client_read_request_on_fragment(php_http_parser *parse return 0; } -static int php_cli_server_client_read_request_on_header_field(php_http_parser *parser, const char *at, size_t length) +static void php_cli_server_client_save_header(php_cli_server_client *client) { - php_cli_server_client *client = parser->data; + /* strip off the colon */ + zend_string *orig_header_name = zend_string_init(client->current_header_name, client->current_header_name_len, 1); + char *lc_header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); + zend_hash_str_add_ptr(&client->request.headers, lc_header_name, client->current_header_name_len, client->current_header_value); + zend_hash_add_ptr(&client->request.headers_original_case, orig_header_name, client->current_header_value); + efree(lc_header_name); + zend_string_release(orig_header_name); + if (client->current_header_name_allocated) { pefree(client->current_header_name, 1); client->current_header_name_allocated = 0; } - client->current_header_name = (char *)at; - client->current_header_name_len = length; + client->current_header_name = NULL; + client->current_header_name_len = 0; + client->current_header_value = NULL; + client->current_header_value_len = 0; +} + +static int php_cli_server_client_read_request_on_header_field(php_http_parser *parser, const char *at, size_t length) +{ + php_cli_server_client *client = parser->data; + switch (client->last_header_element) { + case HEADER_VALUE: + php_cli_server_client_save_header(client); + /* break missing intentionally */ + case HEADER_NONE: + client->current_header_name = (char *)at; + client->current_header_name_len = length; + break; + case HEADER_FIELD: + if (client->current_header_name_allocated) { + size_t new_length = client->current_header_name_len + length; + client->current_header_name = perealloc(client->current_header_name, new_length + 1, 1); + memcpy(client->current_header_name + client->current_header_name_len, at, length); + client->current_header_name_len = new_length; + } else { + size_t new_length = client->current_header_name_len + length; + char* field = pemalloc(new_length + 1, 1); + memcpy(field, client->current_header_name, client->current_header_name_len); + memcpy(field + client->current_header_name_len, at, length); + client->current_header_name = field; + client->current_header_name_len = new_length; + client->current_header_name_allocated = 1; + } + break; + } + + client->last_header_element = HEADER_FIELD; return 0; } static int php_cli_server_client_read_request_on_header_value(php_http_parser *parser, const char *at, size_t length) { php_cli_server_client *client = parser->data; - char *value = pestrndup(at, length, 1); - if (!value) { - return 1; - } - { - /* strip off the colon */ - zend_string *orig_header_name = zend_string_init(client->current_header_name, client->current_header_name_len, 1); - char *lc_header_name = zend_str_tolower_dup(client->current_header_name, client->current_header_name_len); - zend_hash_str_add_ptr(&client->request.headers, lc_header_name, client->current_header_name_len, value); - zend_hash_add_ptr(&client->request.headers_original_case, orig_header_name, value); - efree(lc_header_name); - zend_string_release(orig_header_name); - } - - if (client->current_header_name_allocated) { - pefree(client->current_header_name, 1); - client->current_header_name_allocated = 0; + switch (client->last_header_element) { + case HEADER_FIELD: + client->current_header_value = pestrndup(at, length, 1); + client->current_header_value_len = length; + break; + case HEADER_VALUE: + { + size_t new_length = client->current_header_value_len + length; + client->current_header_value = perealloc(client->current_header_value, new_length + 1, 1); + memcpy(client->current_header_value + client->current_header_value_len, at, length); + client->current_header_value_len = new_length; + } + break; + case HEADER_NONE: + // can't happen + assert(0); + break; } + client->last_header_element = HEADER_VALUE; return 0; } static int php_cli_server_client_read_request_on_headers_complete(php_http_parser *parser) { php_cli_server_client *client = parser->data; - if (client->current_header_name_allocated) { - pefree(client->current_header_name, 1); - client->current_header_name_allocated = 0; + switch (client->last_header_element) { + case HEADER_NONE: + break; + case HEADER_FIELD: + client->current_header_value = pemalloc(1, 1); + *client->current_header_value = '\0'; + client->current_header_value_len = 0; + /* break missing intentionally */ + case HEADER_VALUE: + php_cli_server_client_save_header(client); + break; } - client->current_header_name = NULL; + client->last_header_element = HEADER_NONE; return 0; } @@ -1791,9 +1844,14 @@ static int php_cli_server_client_ctor(php_cli_server_client *client, php_cli_ser } php_http_parser_init(&client->parser, PHP_HTTP_REQUEST); client->request_read = 0; + + client->last_header_element = HEADER_NONE; client->current_header_name = NULL; client->current_header_name_len = 0; client->current_header_name_allocated = 0; + client->current_header_value = NULL; + client->current_header_value_len = 0; + client->post_read_offset = 0; if (FAILURE == php_cli_server_request_ctor(&client->request)) { return FAILURE; diff --git a/sapi/cli/tests/bug70470.phpt b/sapi/cli/tests/bug70470.phpt index acd8c98f05a..1e05f184b40 100644 --- a/sapi/cli/tests/bug70470.phpt +++ b/sapi/cli/tests/bug70470.phpt @@ -4,8 +4,6 @@ Bug #70470 (Built-in server truncates headers spanning over TCP packets) ---XFAIL-- -bug is not fixed yet --FILE-- +--FILE-- + +--EXPECTF-- +HTTP/1.1 200 OK +%a +array(3) { + ["User-AgentAccept"]=> + string(3) "*/*" + ["Referer"]=> + string(0) "" + ["Hi"]=> + string(0) "" +} From 42549b7844472a896dbd51b8305a835e731ecb25 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 5 Sep 2017 18:13:50 +0200 Subject: [PATCH 04/11] Add missing null termination --- sapi/cli/php_cli_server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sapi/cli/php_cli_server.c b/sapi/cli/php_cli_server.c index 4d5324f36c0..39ded2f5b3c 100644 --- a/sapi/cli/php_cli_server.c +++ b/sapi/cli/php_cli_server.c @@ -1611,12 +1611,14 @@ static int php_cli_server_client_read_request_on_header_field(php_http_parser *p size_t new_length = client->current_header_name_len + length; client->current_header_name = perealloc(client->current_header_name, new_length + 1, 1); memcpy(client->current_header_name + client->current_header_name_len, at, length); + client->current_header_name[new_length] = '\0'; client->current_header_name_len = new_length; } else { size_t new_length = client->current_header_name_len + length; char* field = pemalloc(new_length + 1, 1); memcpy(field, client->current_header_name, client->current_header_name_len); memcpy(field + client->current_header_name_len, at, length); + field[new_length] = '\0'; client->current_header_name = field; client->current_header_name_len = new_length; client->current_header_name_allocated = 1; @@ -1641,6 +1643,7 @@ static int php_cli_server_client_read_request_on_header_value(php_http_parser *p size_t new_length = client->current_header_value_len + length; client->current_header_value = perealloc(client->current_header_value, new_length + 1, 1); memcpy(client->current_header_value + client->current_header_value_len, at, length); + client->current_header_value[new_length] = '\0'; client->current_header_value_len = new_length; } break; From dea41f3c3a003a22893b27eead429f963d3230c3 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Wed, 6 Sep 2017 23:30:53 +0200 Subject: [PATCH 05/11] Fixed bug #44995 (bcpowmod() fails if scale != 0) `bc_divmod()` is supposed to do integer division, so we must not apply a scale factor here. --- NEWS | 3 +++ ext/bcmath/libbcmath/src/divmod.c | 2 +- ext/bcmath/tests/bug44995.phpt | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ext/bcmath/tests/bug44995.phpt diff --git a/NEWS b/NEWS index 3bb2a0791a5..377f4d15406 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,9 @@ PHP NEWS - Core: . Fixed #75042 run-tests.php issues with EXTENSION block). (John Boehr) +- BCMath: + . Fixed bug #44995 (bcpowmod() fails if scale != 0). (cmb) + - CLI server: . Fixed bug #70470 (Built-in server truncates headers spanning over TCP packets). (bouk) diff --git a/ext/bcmath/libbcmath/src/divmod.c b/ext/bcmath/libbcmath/src/divmod.c index d7aaa3509da..08c2f8a2a2d 100644 --- a/ext/bcmath/libbcmath/src/divmod.c +++ b/ext/bcmath/libbcmath/src/divmod.c @@ -59,7 +59,7 @@ bc_divmod (bc_num num1, bc_num num2, bc_num *quot, bc_num *rem, int scale) bc_init_num(&temp); /* Calculate it. */ - bc_divide (num1, num2, &temp, scale); + bc_divide (num1, num2, &temp, 0); if (quot) quotient = bc_copy_num (temp); bc_multiply (temp, num2, &temp, rscale); diff --git a/ext/bcmath/tests/bug44995.phpt b/ext/bcmath/tests/bug44995.phpt new file mode 100644 index 00000000000..6eb591f92b7 --- /dev/null +++ b/ext/bcmath/tests/bug44995.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #44995 (bcpowmod() fails if scale != 0) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(3) "1.0" +string(7) "17334.0" +===DONE=== From b2919853f867ca7948e1c80c48eb868eae4ba882 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Thu, 7 Sep 2017 00:30:05 +0200 Subject: [PATCH 06/11] Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1) `x mod 1` is always zero; we have to take the scale into account, though. --- NEWS | 1 + ext/bcmath/libbcmath/src/raisemod.c | 23 +++++++++++++++-------- ext/bcmath/tests/bug54598.phpt | 16 ++++++++++++++++ 3 files changed, 32 insertions(+), 8 deletions(-) create mode 100644 ext/bcmath/tests/bug54598.phpt diff --git a/NEWS b/NEWS index 377f4d15406..7fb0cb10657 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,7 @@ PHP NEWS - BCMath: . Fixed bug #44995 (bcpowmod() fails if scale != 0). (cmb) + . Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1). (okano1220, cmb) - CLI server: . Fixed bug #70470 (Built-in server truncates headers spanning over TCP diff --git a/ext/bcmath/libbcmath/src/raisemod.c b/ext/bcmath/libbcmath/src/raisemod.c index 72a838a3646..84a7321ea7a 100644 --- a/ext/bcmath/libbcmath/src/raisemod.c +++ b/ext/bcmath/libbcmath/src/raisemod.c @@ -75,17 +75,24 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale) /* Do the calculation. */ rscale = MAX(scale, base->n_scale); - while ( !bc_is_zero(exponent) ) + if ( !bc_compare(mod, BCG(_one_)) ) { - (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0); - if ( !bc_is_zero(parity) ) + temp = bc_new_num (1, scale); + } + else + { + while ( !bc_is_zero(exponent) ) { - bc_multiply (temp, power, &temp, rscale); - (void) bc_modulo (temp, mod, &temp, scale); - } + (void) bc_divmod (exponent, BCG(_two_), &exponent, &parity, 0); + if ( !bc_is_zero(parity) ) + { + bc_multiply (temp, power, &temp, rscale); + (void) bc_modulo (temp, mod, &temp, scale); + } - bc_multiply (power, power, &power, rscale); - (void) bc_modulo (power, mod, &power, scale); + bc_multiply (power, power, &power, rscale); + (void) bc_modulo (power, mod, &power, scale); + } } /* Assign the value. */ diff --git a/ext/bcmath/tests/bug54598.phpt b/ext/bcmath/tests/bug54598.phpt new file mode 100644 index 00000000000..6ccd61a2d02 --- /dev/null +++ b/ext/bcmath/tests/bug54598.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #54598 (bcpowmod() may return 1 if modulus is 1) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(1) "0" +string(5) "0.000" +===DONE=== From f18cf46d07ebbb212aa1283a19ed531919136c54 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Thu, 7 Sep 2017 16:05:20 -0400 Subject: [PATCH 07/11] Fix typo in zend_symtable_add_new() API name --- Zend/zend_builtin_functions.c | 2 +- Zend/zend_hash.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index a429ca013aa..9c2e4732d02 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1203,7 +1203,7 @@ ZEND_FUNCTION(get_object_vars) zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_len); zend_hash_str_add_new(Z_ARRVAL_P(return_value), prop_name, prop_len, value); } else { - zend_symbtable_add_new(Z_ARRVAL_P(return_value), key, value); + zend_symtable_add_new(Z_ARRVAL_P(return_value), key, value); } } } diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index f3696771964..ffe47f16ea0 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -310,7 +310,7 @@ static zend_always_inline int zend_hash_str_exists_ind(const HashTable *ht, cons Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF); } -static zend_always_inline zval *zend_symbtable_add_new(HashTable *ht, zend_string *key, zval *pData) +static zend_always_inline zval *zend_symtable_add_new(HashTable *ht, zend_string *key, zval *pData) { zend_ulong idx; From 0413feb29c94b065be6a1a2f425c72add5779a67 Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Thu, 7 Sep 2017 17:35:54 -0400 Subject: [PATCH 08/11] Add BC define for users of the typoed zend_symbtable_add_new --- Zend/zend_hash.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h index ffe47f16ea0..499c07c287f 100644 --- a/Zend/zend_hash.h +++ b/Zend/zend_hash.h @@ -321,6 +321,10 @@ static zend_always_inline zval *zend_symtable_add_new(HashTable *ht, zend_string } } +/* This typo snuck into 7.0.17 and 7.1.3, this define exists for BC */ +#define zend_symbtable_add_new(ht, key, pData) \ + zend_symtable_add_new(ht, key, pData) + static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData) { zend_ulong idx; From 44eec946e8c6c830992572e15e4b63b4dd92abdf Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 9 Sep 2017 13:18:26 +0200 Subject: [PATCH 09/11] Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus) Since `bcpowmod()` does not support non-integral operands, we have to truncate these in addition to emitting a respective warning. We also have to work with the truncated values in the following. We recognize that the division by one to enforce the truncation is actually overkill, but we stick with it for now, and shall tackle the issue for PHP 7.3. --- NEWS | 1 + ext/bcmath/libbcmath/src/raisemod.c | 22 +++++++++++++++------- ext/bcmath/tests/bug75178.phpt | 18 ++++++++++++++++++ 3 files changed, 34 insertions(+), 7 deletions(-) create mode 100644 ext/bcmath/tests/bug75178.phpt diff --git a/NEWS b/NEWS index 7fb0cb10657..795d67d860e 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,7 @@ PHP NEWS - BCMath: . Fixed bug #44995 (bcpowmod() fails if scale != 0). (cmb) . Fixed bug #54598 (bcpowmod() may return 1 if modulus is 1). (okano1220, cmb) + . Fixed bug #75178 (bcpowmod() misbehaves for non-integer base or modulus). (cmb) - CLI server: . Fixed bug #70470 (Built-in server truncates headers spanning over TCP diff --git a/ext/bcmath/libbcmath/src/raisemod.c b/ext/bcmath/libbcmath/src/raisemod.c index 84a7321ea7a..84788b4770c 100644 --- a/ext/bcmath/libbcmath/src/raisemod.c +++ b/ext/bcmath/libbcmath/src/raisemod.c @@ -45,7 +45,7 @@ int bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale) { - bc_num power, exponent, parity, temp; + bc_num power, exponent, modulus, parity, temp; int rscale; /* Check for correct numbers. */ @@ -55,12 +55,16 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale) /* Set initial values. */ power = bc_copy_num (base); exponent = bc_copy_num (expo); + modulus = bc_copy_num (mod); temp = bc_copy_num (BCG(_one_)); bc_init_num(&parity); /* Check the base for scale digits. */ - if (base->n_scale != 0) + if (power->n_scale != 0) + { bc_rt_warn ("non-zero scale in base"); + bc_divide (power, BCG(_one_), &power, 0); /*truncate */ + } /* Check the exponent for scale digits. */ if (exponent->n_scale != 0) @@ -70,12 +74,15 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale) } /* Check the modulus for scale digits. */ - if (mod->n_scale != 0) + if (modulus->n_scale != 0) + { bc_rt_warn ("non-zero scale in modulus"); + bc_divide (modulus, BCG(_one_), &modulus, 0); /*truncate */ + } /* Do the calculation. */ - rscale = MAX(scale, base->n_scale); - if ( !bc_compare(mod, BCG(_one_)) ) + rscale = MAX(scale, power->n_scale); + if ( !bc_compare(modulus, BCG(_one_)) ) { temp = bc_new_num (1, scale); } @@ -87,17 +94,18 @@ bc_raisemod (bc_num base, bc_num expo, bc_num mod, bc_num *result, int scale) if ( !bc_is_zero(parity) ) { bc_multiply (temp, power, &temp, rscale); - (void) bc_modulo (temp, mod, &temp, scale); + (void) bc_modulo (temp, modulus, &temp, scale); } bc_multiply (power, power, &power, rscale); - (void) bc_modulo (power, mod, &power, scale); + (void) bc_modulo (power, modulus, &power, scale); } } /* Assign the value. */ bc_free_num (&power); bc_free_num (&exponent); + bc_free_num (&modulus); bc_free_num (result); bc_free_num (&parity); *result = temp; diff --git a/ext/bcmath/tests/bug75178.phpt b/ext/bcmath/tests/bug75178.phpt new file mode 100644 index 00000000000..4e252566481 --- /dev/null +++ b/ext/bcmath/tests/bug75178.phpt @@ -0,0 +1,18 @@ +--TEST-- +Bug #75178 (bcpowmod() misbehaves for non-integer base or modulus) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +bc math warning: non-zero scale in base +string(5) "1.000" +bc math warning: non-zero scale in modulus +string(5) "1.000" +===DONE=== From 3fd08a1595299cdd0558978c4ce4c3fc98a8fb06 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 9 Sep 2017 16:41:38 +0200 Subject: [PATCH 10/11] Fix bug75178.phpt on Windows bug75178.phpt fails on Windows, because the stderr output is not interspersed with stdout output there, but rather is appended to the end. The fix is analogous to bug72093.phpt. --- ext/bcmath/tests/bug75178-win32.phpt | 21 +++++++++++++++++++++ ext/bcmath/tests/bug75178.phpt | 3 +++ 2 files changed, 24 insertions(+) create mode 100644 ext/bcmath/tests/bug75178-win32.phpt diff --git a/ext/bcmath/tests/bug75178-win32.phpt b/ext/bcmath/tests/bug75178-win32.phpt new file mode 100644 index 00000000000..bae590fb5b3 --- /dev/null +++ b/ext/bcmath/tests/bug75178-win32.phpt @@ -0,0 +1,21 @@ +--TEST-- +Bug #75178 (bcpowmod() misbehaves for non-integer base or modulus) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(5) "1.000" +string(5) "1.000" +===DONE=== +bc math warning: non-zero scale in base +bc math warning: non-zero scale in modulus diff --git a/ext/bcmath/tests/bug75178.phpt b/ext/bcmath/tests/bug75178.phpt index 4e252566481..bdfa25a2e17 100644 --- a/ext/bcmath/tests/bug75178.phpt +++ b/ext/bcmath/tests/bug75178.phpt @@ -3,6 +3,9 @@ Bug #75178 (bcpowmod() misbehaves for non-integer base or modulus) --SKIPIF-- --FILE-- Date: Sun, 10 Sep 2017 18:39:29 +0200 Subject: [PATCH 11/11] Fixed bug #73730 (textdomain(null) throws in strict mode) The $text_domain parameter may be NULL, which we have to cater to explicitly with regard to strict_types. --- NEWS | 3 +++ ext/gettext/gettext.c | 8 ++++---- ext/gettext/tests/bug73730.phpt | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 ext/gettext/tests/bug73730.phpt diff --git a/NEWS b/NEWS index 795d67d860e..12c5003acc5 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,9 @@ PHP NEWS . Fixed bug #75124 (gdImageGrayScale() may produce colors). (cmb) . Fixed bug #75139 (libgd/gd_interpolation.c:1786: suspicious if ?). (cmb) +- Gettext: + . Fixed bug #73730 (textdomain(null) throws in strict mode). (cmb) + - Intl: . Fixed bug #75090 (IntlGregorianCalendar doesn't have constants from parent class). (tpunt) diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c index 9cc2ba5a6fe..f4d6694cee7 100644 --- a/ext/gettext/gettext.c +++ b/ext/gettext/gettext.c @@ -161,16 +161,16 @@ PHP_MINFO_FUNCTION(php_gettext) Set the textdomain to "domain". Returns the current domain */ PHP_NAMED_FUNCTION(zif_textdomain) { - char *domain, *domain_name, *retval; - size_t domain_len; + char *domain = NULL, *domain_name, *retval; + size_t domain_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &domain, &domain_len) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &domain, &domain_len) == FAILURE) { return; } PHP_GETTEXT_DOMAIN_LENGTH_CHECK - if (strcmp(domain, "") && strcmp(domain, "0")) { + if (domain != NULL && strcmp(domain, "") && strcmp(domain, "0")) { domain_name = domain; } else { domain_name = NULL; diff --git a/ext/gettext/tests/bug73730.phpt b/ext/gettext/tests/bug73730.phpt new file mode 100644 index 00000000000..df6d7b0f11c --- /dev/null +++ b/ext/gettext/tests/bug73730.phpt @@ -0,0 +1,16 @@ +--TEST-- +Bug #73730 (textdomain(null) throws in strict mode) +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +string(8) "messages" +===DONE===