|
20 | 20 | #include "ext/standard/base64.h" |
21 | 21 | #include "ext/standard/md5.h" |
22 | 22 | #include "ext/standard/php_random.h" |
| 23 | +#include "ext/hash/php_hash.h" |
23 | 24 |
|
24 | 25 | static char *get_http_header_value_nodup(char *headers, char *type, size_t *len); |
25 | 26 | static char *get_http_header_value(char *headers, char *type); |
@@ -657,18 +658,23 @@ int make_http_soap_request(zval *this_ptr, |
657 | 658 | has_authorization = 1; |
658 | 659 | if (Z_TYPE_P(digest) == IS_ARRAY) { |
659 | 660 | char HA1[33], HA2[33], response[33], cnonce[33], nc[9]; |
660 | | - zend_long nonce; |
| 661 | + unsigned char nonce[16]; |
661 | 662 | PHP_MD5_CTX md5ctx; |
662 | 663 | unsigned char hash[16]; |
663 | 664 |
|
664 | | - php_random_bytes_throw(&nonce, sizeof(nonce)); |
665 | | - nonce &= 0x7fffffff; |
| 665 | + if (UNEXPECTED(php_random_bytes_throw(&nonce, sizeof(nonce)) != SUCCESS)) { |
| 666 | + ZEND_ASSERT(EG(exception)); |
| 667 | + php_stream_close(stream); |
| 668 | + convert_to_null(Z_CLIENT_HTTPURL_P(this_ptr)); |
| 669 | + convert_to_null(Z_CLIENT_HTTPSOCKET_P(this_ptr)); |
| 670 | + convert_to_null(Z_CLIENT_USE_PROXY_P(this_ptr)); |
| 671 | + smart_str_free(&soap_headers_z); |
| 672 | + smart_str_free(&soap_headers); |
| 673 | + return FALSE; |
| 674 | + } |
666 | 675 |
|
667 | | - PHP_MD5Init(&md5ctx); |
668 | | - snprintf(cnonce, sizeof(cnonce), ZEND_LONG_FMT, nonce); |
669 | | - PHP_MD5Update(&md5ctx, (unsigned char*)cnonce, strlen(cnonce)); |
670 | | - PHP_MD5Final(hash, &md5ctx); |
671 | | - make_digest(cnonce, hash); |
| 676 | + php_hash_bin2hex(cnonce, nonce, sizeof(nonce)); |
| 677 | + cnonce[32] = 0; |
672 | 678 |
|
673 | 679 | if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nc", sizeof("nc")-1)) != NULL && |
674 | 680 | Z_TYPE_P(tmp) == IS_LONG) { |
|
0 commit comments