diff options
author | Xinchen Hui <laruence@gmail.com> | 2017-02-25 11:10:37 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2017-02-25 11:10:37 +0800 |
commit | d1f36d6d8ebd76b2d1014a1fcccdf75baa70cdb0 (patch) | |
tree | 106198433b6c710208498a92b1aec221da458070 | |
parent | afca29c4361429a18b5f7dd60c289d034cca2aaf (diff) | |
parent | f678b0eae2766a91e3a9e680b3d71befe7e4879c (diff) | |
download | php-git-d1f36d6d8ebd76b2d1014a1fcccdf75baa70cdb0.tar.gz |
Merge branch 'PHP-7.1' of git.php.net:/php-src into PHP-7.1
* 'PHP-7.1' of git.php.net:/php-src:
Fix bug #73127
Support run or test target invoked within debugger
Update test for bug #74159
Update NEWS
Fix bug #74159
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | ext/hash/hash_gost.c | 5 | ||||
-rw-r--r-- | ext/hash/tests/bug73127.phpt | 27 | ||||
-rw-r--r-- | ext/openssl/tests/bug74159.phpt | 106 | ||||
-rw-r--r-- | ext/openssl/xp_ssl.c | 10 | ||||
-rw-r--r-- | win32/build/Makefile | 17 |
6 files changed, 164 insertions, 7 deletions
@@ -28,6 +28,10 @@ PHP NEWS . Fixed bug #69860 (php-fpm process accounting is broken with keepalive). (Denis Yeldandi) +- Hash: + . Fixed bug #73127 (gost-crypto hash incorrect if input data contains long + 0xFF sequence). (Grundik) + - GD: . Fixed bug #74031 (ReflectionFunction for imagepng is missing last two parameters). (finwe) @@ -43,6 +47,8 @@ PHP NEWS . Fixed bug #74022 (PHP Fast CGI crashes when reading from a pfx file). (Anatol) . Fixed bug #74099 (Memory leak with openssl_encrypt()). (Andrew Nester) + . Fixed bug #74159 (Writing a large buffer to a non-blocking encrypted stream + fails with "bad write retry"). (trowski) - Standard: . Fixed bug #74005 (mail.add_x_header causes RFC-breaking lone line feed). diff --git a/ext/hash/hash_gost.c b/ext/hash/hash_gost.c index 7961fc6c3a..95c61a9399 100644 --- a/ext/hash/hash_gost.c +++ b/ext/hash/hash_gost.c @@ -227,14 +227,13 @@ static inline void Gost(PHP_GOST_CTX *context, uint32_t data[8]) static inline void GostTransform(PHP_GOST_CTX *context, const unsigned char input[32]) { int i, j; - uint32_t data[8], temp = 0, save = 0; + uint32_t data[8], temp = 0; for (i = 0, j = 0; i < 8; ++i, j += 4) { data[i] = ((uint32_t) input[j]) | (((uint32_t) input[j + 1]) << 8) | (((uint32_t) input[j + 2]) << 16) | (((uint32_t) input[j + 3]) << 24); - save = context->state[i + 8]; context->state[i + 8] += data[i] + temp; - temp = ((context->state[i + 8] < data[i]) || (context->state[i + 8] < save)) ? 1 : 0; + temp = context->state[i + 8] < data[i] ? 1 : (context->state[i + 8] == data[i] ? temp : 0); } Gost(context, data); diff --git a/ext/hash/tests/bug73127.phpt b/ext/hash/tests/bug73127.phpt new file mode 100644 index 0000000000..d9f1f7dca1 --- /dev/null +++ b/ext/hash/tests/bug73127.phpt @@ -0,0 +1,27 @@ +--TEST-- +Bug #73127 (gost-crypto hash incorrect if input data contains long 0xFF sequence) +--FILE-- +<?php // $Id$ + +$test1 = str_repeat("\xFF", 40); +$test2 = str_repeat("\x00", 40); +echo hash('gost-crypto', $test1), + "\n", + hash('gost', $test1), + "\n", + hash('gost-crypto', $test2), + "\n", + hash('gost', $test2), + "\n", + hash('gost-crypto', ''), + "\n", + hash('gost', '') + ; +?> +--EXPECT-- +231d8bb980d3faa30fee6ec475df5669cf6c24bbce22f46d6737470043a99f8e +9eaf96ba62f90fae6707f1d4274d1a9d6680f5a121d4387815aa3a6ec42439c5 +bbf1f3179409c853cd3e396d67b0e10a266c218a4fd19f149c39aa4f6d37a007 +a0be0b90fea5a5b50c90c9429d07bb98fa0c06f0c30210e94c7d80c3125c67ac +981e5f3ca30c841487830f84fb433e13ac1101569b9c13584ac483234cd656c0 +ce85b99cc46752fffee35cab9a7b0278abb4c2d2055cff685af4912c49490f8d diff --git a/ext/openssl/tests/bug74159.phpt b/ext/openssl/tests/bug74159.phpt new file mode 100644 index 0000000000..2aaa68bf70 --- /dev/null +++ b/ext/openssl/tests/bug74159.phpt @@ -0,0 +1,106 @@ +--TEST-- +Bug #74159: Writing a large buffer to non-blocking encrypted streams fails +--SKIPIF-- +<?php +if (!extension_loaded("openssl")) die("skip openssl not loaded"); +if (!function_exists("proc_open")) die("skip no proc_open"); +--FILE-- +<?php +$serverCode = <<<'CODE' + $serverUri = "ssl://127.0.0.1:64321"; + $serverFlags = STREAM_SERVER_BIND | STREAM_SERVER_LISTEN; + $serverCtx = stream_context_create(['ssl' => [ + 'local_cert' => __DIR__ . '/bug54992.pem', + 'crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_2_SERVER, + ]]); + + $server = stream_socket_server($serverUri, $errno, $errstr, $serverFlags, $serverCtx); + phpt_notify(); + + $client = stream_socket_accept($server, 1); + + if (!$client) { + exit(); + } + + $data = ''; + while (strlen($data) < 0xfffff) { + $buffer = fread($client, 8192); + if (empty($buffer)) { + exit(); + } + $data .= $buffer; + usleep(100); + } + + fclose($client); +CODE; + +$clientCode = <<<'CODE' + function streamRead($stream) : int { + return strlen(fread($stream, 8192)); + } + + function streamWrite($stream, $data) : int { + return fwrite($stream, $data); + } + + function waitForWrite(...$streams) : bool { + $read = null; + $except = null; + while($streams && !($n = stream_select($read, $streams, $except, 1))); + return $n > 0; + } + + function waitForRead(...$streams) : bool { + $write = null; + $except = null; + while ($streams && !($n = stream_select($streams, $write, $except, 1))); + return $n > 0; + } + + set_error_handler(function ($errno, $errstr) { + exit("$errstr\n"); + }); + + $serverUri = "tcp://127.0.0.1:64321"; + $clientFlags = STREAM_CLIENT_CONNECT; + $clientCtx = stream_context_create(['ssl' => [ + 'verify_peer' => true, + 'cafile' => __DIR__ . '/bug54992-ca.pem', + 'peer_name' => 'bug54992.local', + ]]); + + phpt_wait(); + + $fp = stream_socket_client($serverUri, $errno, $errstr, 1, $clientFlags, $clientCtx); + + stream_set_blocking($fp, false); + while (0 === ($n = stream_socket_enable_crypto($fp, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT))); + + $data = str_repeat("a", 0xfffff); + $written = 0; + $total = $written; + while(!empty($data)) { + $written = streamWrite($fp, $data); + $total += $written; + $data = substr($data, $written); + waitForWrite($fp); + } + printf("Written %d bytes\n", $total); + + while(waitForRead($fp)) { + streamRead($fp); + if (feof($fp)) { + break; + } + } + + exit("DONE\n"); +CODE; + +include 'ServerClientTestCase.inc'; +ServerClientTestCase::getInstance()->run($clientCode, $serverCode); +--EXPECTF-- +Written 1048575 bytes +DONE diff --git a/ext/openssl/xp_ssl.c b/ext/openssl/xp_ssl.c index 6fa25b505d..6a09038e3a 100644 --- a/ext/openssl/xp_ssl.c +++ b/ext/openssl/xp_ssl.c @@ -1640,6 +1640,16 @@ int php_openssl_setup_crypto(php_stream *stream, SSL_set_mode(sslsock->ssl_handle, mode | SSL_MODE_RELEASE_BUFFERS); } while (0); #endif + + do { + long mode = SSL_get_mode(sslsock->ssl_handle); + SSL_set_mode(sslsock->ssl_handle, mode | SSL_MODE_ENABLE_PARTIAL_WRITE); + } while (0); + + do { + long mode = SSL_get_mode(sslsock->ssl_handle); + SSL_set_mode(sslsock->ssl_handle, mode | SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER); + } while (0); if (cparam->inputs.session) { if (cparam->inputs.session->ops != &php_openssl_socket_ops) { diff --git a/win32/build/Makefile b/win32/build/Makefile index 3293050b83..5389358787 100644 --- a/win32/build/Makefile +++ b/win32/build/Makefile @@ -29,6 +29,14 @@ MCFILE=$(BUILD_DIR)\wsyslog.rc BUILD_DIR_DEV_NAME=php-$(PHP_VERSION_STRING)-devel-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE) BUILD_DIR_DEV=$(BUILD_DIR)\$(BUILD_DIR_DEV_NAME) +!if "$(DEBUGGER)" == "1" +DEBUGGER_CMD=devenv +DEBUGGER_ARGS=/debugexe +!else +DEBUGGER_CMD= +DEBUGGER_ARGS= +!endif + all: generated_files $(EXT_TARGETS) $(PECL_TARGETS) $(SAPI_TARGETS) build_dirs: $(BUILD_DIR) $(BUILD_DIRS_SUB) $(BUILD_DIR_DEV) @@ -151,18 +159,19 @@ clean-pgo: clean-all -del /f /q $(BUILD_DIR)\pecl-$(PHP_VERSION_STRING)$(PHP_ZTS_ARCHIVE_POSTFIX)-Win32-$(PHP_COMPILER_SHORT)-$(PHP_ARCHITECTURE).zip -del /f /q $(BUILD_DIR)\php-test-pack-$(PHP_VERSION_STRING).zip + !if $(PHP_TEST_INI_PATH) == "" test: set-tmp-env - "$(BUILD_DIR)\php.exe" -d open_basedir= -d output_buffering=0 run-tests.php $(TESTS) -p "$(BUILD_DIR)\php.exe" + $(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -d open_basedir= -d output_buffering=0 run-tests.php $(TESTS) -p "$(BUILD_DIR)\php.exe" run: set-tmp-env - "$(BUILD_DIR)\php.exe" $(ARGS) + $(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" $(ARGS) !else test: set-tmp-env - "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) -d open_basedir= -d output_buffering=0 -d memory_limit=-1 run-tests.php -p "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(TESTS) + $(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) -d open_basedir= -d output_buffering=0 -d memory_limit=-1 run-tests.php -p "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(TESTS) run: set-tmp-env - "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(ARGS) + $(DEBUGGER_CMD) $(DEBUGGER_ARGS) "$(BUILD_DIR)\php.exe" -n -c $(PHP_TEST_INI_PATH) $(ARGS) !endif build-snap: set-tmp-env generated_files |