Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ext/openssl/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions ext/openssl/openssl_backend_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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';
}

Expand Down
10 changes: 4 additions & 6 deletions ext/standard/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would probably be nicer if zend_bin2hex() either returned the end pointer or the length of data written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I generally agree it's a good suggestion, but it doesn't directly relate to the changes in this PR - the same pattern exists in other places where it was substituted previously. I'd rather implement this suggestion in a separate PR and for all the places.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather implement this suggestion in a separate PR and for all the places.

Yes, I didn't mean to say that it should be done as part of this PR. I just noticed when looking at this one for a possible follow-up.

}

Expand Down
Loading