com php-src: Merge branch 'PHP-5.6': ext/mcrypt/mcrypt.c ext/mcrypt/php_mcrypt.h
| From: | JulienPauli | Date: | Wed, 13 May 2015 12:21:19 +0000 |
| Subject: | com php-src: Merge branch 'PHP-5.6': ext/mcrypt/mcrypt.c ext/mcrypt/php_mcrypt.h | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-86740@lists.php.net to get a copy of this message | ||
Commit: 420961524d9a6482b01f90ebbb7a5d2622bcc176
Author: Julien Pauli <jpauli@php.net> Wed, 13 May 2015 14:21:19 +0200
Parents: 4f5ab6fca49843657e241eddf6e4b08fbdf226b4 c09fad97d68d07d6b528d56d5cef1f8cbb9fc5ec
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=420961524d9a6482b01f90ebbb7a5d2622bcc176
Log:
Merge branch 'PHP-5.6'
* PHP-5.6:
Close fd at the end, otherwise people complain
Add file descriptor caching to mcrypt_create_iv()
Conflicts:
ext/mcrypt/mcrypt.c
Changed paths:
MM ext/mcrypt/mcrypt.c
MM ext/mcrypt/php_mcrypt.h
Diff:
diff --cc ext/mcrypt/mcrypt.c
index 1cdedd5,8eeb86d..f6d8c91
--- a/ext/mcrypt/mcrypt.c
+++ b/ext/mcrypt/mcrypt.c
@@@ -400,18 -441,29 +406,29 @@@ static PHP_MINIT_FUNCTION(mcrypt) /* {{
MCRYPT_ENTRY2_2_4(MODE_STREAM, "stream");
REGISTER_INI_ENTRIES();
- php_stream_filter_register_factory("mcrypt.*", &php_mcrypt_filter_factory
TSRMLS_CC);
- php_stream_filter_register_factory("mdecrypt.*", &php_mcrypt_filter_factory
TSRMLS_CC);
+ php_stream_filter_register_factory("mcrypt.*", &php_mcrypt_filter_factory);
+ php_stream_filter_register_factory("mdecrypt.*", &php_mcrypt_filter_factory);
+ MCG(fd[RANDOM]) = -1;
+ MCG(fd[URANDOM]) = -1;
+
return SUCCESS;
}
/* }}} */
static PHP_MSHUTDOWN_FUNCTION(mcrypt) /* {{{ */
{
- php_stream_filter_unregister_factory("mcrypt.*" TSRMLS_CC);
- php_stream_filter_unregister_factory("mdecrypt.*" TSRMLS_CC);
+ php_stream_filter_unregister_factory("mcrypt.*");
+ php_stream_filter_unregister_factory("mdecrypt.*");
+ if (MCG(fd[RANDOM]) > 0) {
+ close(MCG(fd[RANDOM]));
+ }
+
+ if (MCG(fd[URANDOM]) > 0) {
+ close(MCG(fd[URANDOM]));
+ }
+
UNREGISTER_INI_ENTRIES();
return SUCCESS;
}
@@@ -1332,32 -1435,35 +1349,35 @@@ PHP_FUNCTION(mcrypt_create_iv
BYTE *iv_b = (BYTE *) iv;
if (php_win32_get_random_bytes(iv_b, (size_t) size) == FAILURE){
efree(iv);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not gather sufficient random
data");
+ php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data");
RETURN_FALSE;
}
- n = size;
+ n = (int)size;
#else
- int fd;
+ int *fd = &MCG(fd[source]);
size_t read_bytes = 0;
- fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY);
- if (fd < 0) {
- efree(iv);
- php_error_docref(NULL, E_WARNING, "Cannot open source device");
- RETURN_FALSE;
+ if (*fd < 0) {
+ *fd = open(source == RANDOM ? "/dev/random" : "/dev/urandom", O_RDONLY);
+ if (*fd < 0) {
+ efree(iv);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cannot open source device");
++ php_error_docref(NULL, E_WARNING, "Cannot open source device");
+ RETURN_FALSE;
+ }
}
+
while (read_bytes < size) {
- n = read(fd, iv + read_bytes, size - read_bytes);
+ n = read(*fd, iv + read_bytes, size - read_bytes);
if (n < 0) {
break;
}
read_bytes += n;
}
n = read_bytes;
- close(fd);
+
if (n < size) {
efree(iv);
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Could not gather sufficient random
data");
+ php_error_docref(NULL, E_WARNING, "Could not gather sufficient random data");
RETURN_FALSE;
}
#endif