Skip to content

Commit c790373

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Update NEWS Update NEWS Update NEWS Fix phpGH-11382 add missing hash header for bin2hex Fix missing randomness check and insufficient random bytes for SOAP HTTP Digest
2 parents 919f27b + 269d6c5 commit c790373

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

ext/soap/php_http.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "ext/standard/base64.h"
2121
#include "ext/standard/md5.h"
2222
#include "ext/random/php_random.h"
23+
#include "ext/hash/php_hash.h"
2324

2425
static char *get_http_header_value_nodup(char *headers, char *type, size_t *len);
2526
static char *get_http_header_value(char *headers, char *type);
@@ -657,18 +658,23 @@ int make_http_soap_request(zval *this_ptr,
657658
has_authorization = 1;
658659
if (Z_TYPE_P(digest) == IS_ARRAY) {
659660
char HA1[33], HA2[33], response[33], cnonce[33], nc[9];
660-
zend_long nonce;
661+
unsigned char nonce[16];
661662
PHP_MD5_CTX md5ctx;
662663
unsigned char hash[16];
663664

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+
}
666675

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;
672678

673679
if ((tmp = zend_hash_str_find(Z_ARRVAL_P(digest), "nc", sizeof("nc")-1)) != NULL &&
674680
Z_TYPE_P(tmp) == IS_LONG) {

0 commit comments

Comments
 (0)