com php-src: Fixed bug #74402 (segfault on random_bytes, bin2hex, openssl_seal): NEWS ext/openssl/openss l.c ext/openssl/tests/bug74402.phpt

[email protected] (Xinchen Hui)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    42e576ace20355418bdc11226ac045cea4737391
Author:    Xinchen Hui <[email protected]>         Mon, 10 Apr 2017 19:02:50 +0800
Parents:   e6423757645749dca781639d815f8348a4a20c98
Branches:  PHP-7.0 PHP-7.1 master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=42e576ace20355418bdc11226ac045cea4737391

Log:
Fixed bug #74402 (segfault on random_bytes, bin2hex, openssl_seal)

Bugs:
https://bugs.php.net/74402

Changed paths:
  M  NEWS
  M  ext/openssl/openssl.c
  A  ext/openssl/tests/bug74402.phpt


Diff:
diff --git a/NEWS b/NEWS
index 5caecbe..613be68 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,8 @@ PHP                                                                        NEWS
     loss). (Yussuf Khalil)
 
 - OpenSSL:
+  . Fixed bug #74402 (segfault on random_bytes, bin2hex, openssl_seal).
+    (Laruence)
   . Fixed bug #74341 (openssl_x509_parse fails to parse ASN.1 UTCTime without
     seconds). (Moritz Fain)
 
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index 7a8ccc0..1ea4d07 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -5399,7 +5399,6 @@ PHP_FUNCTION(openssl_seal)
 
 	if (len1 + len2 > 0) {
 		zval_dtor(sealdata);
-		buf[len1 + len2] = '\0';
 		ZVAL_NEW_STR(sealdata, zend_string_init((char*)buf, len1 + len2, 0));
 		efree(buf);
 
diff --git a/ext/openssl/tests/bug74402.phpt b/ext/openssl/tests/bug74402.phpt
new file mode 100644
index 0000000..8cd9836
--- /dev/null
+++ b/ext/openssl/tests/bug74402.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #74402 (segfault on random_bytes, bin3hex, openssl_seal)
+--SKIPIF--
+<?php
+if (!extension_loaded("openssl")) {
+	print "skip";
+}
+if (!in_array('AES256', openssl_get_cipher_methods(true))) {
+	print "skip";
+}
+?>
+--FILE--
+<?php
+$data = "23153b1cf683cb16f8d71190a7c42f38fecda27c29a7bc8991c9f6a2a63602bf";
+$key = array("-----BEGIN PUBLIC KEY-----
+MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqvjCLfpS0MyilIjR+IsH
+HPH8TqFUCw4kTAVmTy9SDZV9hHYY2EPgrlTd7gvMP/DWipvBD6Y5w2bPdAQoXr5D
+qEKAGkE+1El4hS8XyuOdYXSYTDH1HPSlFiGdgsnlkFcbh/fJyzIKBaGLnWxsjhiS
+deiI7KuEkI9zt+X2r4KqFt/dhnXz0kcB1M7qyhQ6Rvijgjy/A1LsN4ZAREFLCEjb
+1AP9nk0QAUHWcG5MvbgsE20Pn4R5wFsMFBTvNmb34jHFREgR9j4DYcV5FFR3tKb8
+3XtjE9/kjfK29BSpiyXZs8PSqDhO00vh6txUB4VfkVUD2Bi93rxDeyALnCW7My+l
+YwIDAQAB
+-----END PUBLIC KEY-----");
+$iv = '';
+var_dump(strlen($data));
+var_dump(openssl_seal($data, $sealed_data, $env_keys, $key, 'AES256', $iv));
+?>
+--EXPECTF--
+int(64)
+int(80)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.