[php-src] master: md5, sha1, openssl - using zend_bin2hex instead of local helper (#23819)
| From: | Alexander Danilov via GitHub | Date: | Mon, 21 Sep 2026 11:59:38 +0000 |
| Subject: | [php-src] master: md5, sha1, openssl - using zend_bin2hex instead of local helper (#23819) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141323@lists.php.net to get a copy of this message | ||
Author: Alexander Danilov (adapik)
Committer: GitHub (web-flow)
Pusher: Girgias
Date: 2026-09-21T12:59:35+01:00
Commit: https://github.com/php/php-src/commit/39d8aee27c00bacfc5cfa1d63f1f3e826d8790b8
Raw diff: https://github.com/php/php-src/commit/39d8aee27c00bacfc5cfa1d63f1f3e826d8790b8.diff
md5, sha1, openssl - using zend_bin2hex instead of local helper (#23819)
Changed paths:
M ext/openssl/openssl.c
M ext/openssl/openssl_backend_common.c
M ext/standard/md5.c
Diff:
diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c
index c8ca39ad0aab..5ea2a7737434 100644
--- a/ext/openssl/openssl.c
+++ b/ext/openssl/openssl.c
@@ -32,7 +32,6 @@
#include "ext/standard/file.h"
#include "ext/standard/info.h"
#include "ext/standard/php_fopen_wrappers.h"
-#include "ext/standard/md5.h" /* For make_digest_ex() */
#include "ext/standard/base64.h"
#ifdef PHP_WIN32
# include "win32/winutil.h"
@@ -4973,7 +4972,7 @@ PHP_FUNCTION(openssl_digest)
int digest_str_len = siglen * 2;
zend_string *digest_str = zend_string_alloc(digest_str_len, 0);
- make_digest_ex(ZSTR_VAL(digest_str), (unsigned char*)ZSTR_VAL(sigbuf), siglen);
+ zend_bin2hex(ZSTR_VAL(digest_str), (unsigned char*)ZSTR_VAL(sigbuf), siglen);
ZSTR_VAL(digest_str)[digest_str_len] = '\0';
zend_string_release_ex(sigbuf, 0);
RETVAL_NEW_STR(digest_str);
diff --git a/ext/openssl/openssl_backend_common.c b/ext/openssl/openssl_backend_common.c
index 2ebee973ff86..8ea132a1ab0c 100644
--- a/ext/openssl/openssl_backend_common.c
+++ b/ext/openssl/openssl_backend_common.c
@@ -15,7 +15,6 @@
#include "php_openssl_backend.h"
#include "zend_exceptions.h"
-#include "ext/standard/md5.h" /* For make_digest_ex() */
#include "ext/standard/base64.h"
#ifdef PHP_WIN32
# include "win32/winutil.h"
@@ -611,7 +610,7 @@ zend_string* php_openssl_x509_fingerprint(X509 *peer, const char *method, bool r
ret = zend_string_init((char*)md, n, 0);
} else {
ret = zend_string_alloc(n * 2, 0);
- make_digest_ex(ZSTR_VAL(ret), md, n);
+ zend_bin2hex(ZSTR_VAL(ret), md, n);
ZSTR_VAL(ret)[n * 2] = '\0';
}
diff --git a/ext/standard/md5.c b/ext/standard/md5.c
index 204514053cf0..c5badcd6b859 100644
--- a/ext/standard/md5.c
+++ b/ext/standard/md5.c
@@ -24,12 +24,10 @@ PHPAPI void make_digest(char *md5str, const unsigned char *digest)
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len)
{
- static const char hexits[17] = "0123456789abcdef";
-
- for (size_t i = 0; i < len; i++) {
- md5str[i * 2] = hexits[digest[i] >> 4];
- md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
- }
+ zend_bin2hex(md5str, digest, len);
+ /* Some callers (e.g. ext/soap's WSDL cache key) memcpy() the whole
+ buffer including this terminator, so it must still be written here;
+ zend_bin2hex() itself does not null-terminate. */
md5str[len * 2] = '\0';
}