Skip to content

ext/standard/md5: Improve types #18518

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
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
19 changes: 7 additions & 12 deletions ext/standard/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,29 @@
#include "php.h"
#include "md5.h"

PHPAPI void make_digest(char *md5str, const unsigned char *digest) /* {{{ */
PHPAPI void make_digest(char *md5str, const unsigned char *digest)
{
make_digest_ex(md5str, digest, 16);
}
/* }}} */

PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len) /* {{{ */
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len)
{
static const char hexits[17] = "0123456789abcdef";
int i;

for (i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
md5str[i * 2] = hexits[digest[i] >> 4];
md5str[(i * 2) + 1] = hexits[digest[i] & 0x0F];
}
md5str[len * 2] = '\0';
}
/* }}} */

/* {{{ Calculate the md5 hash of a string */
/* Calculate the md5 hash of a string */
PHP_FUNCTION(md5)
{
zend_string *arg;
bool raw_output = 0;
PHP_MD5_CTX context;
unsigned char digest[16];
bool raw_output = false;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(arg)
Expand All @@ -63,14 +60,13 @@ PHP_FUNCTION(md5)
}

}
/* }}} */

/* {{{ Calculate the md5 hash of given filename */
/* Calculate the md5 hash of given filename */
PHP_FUNCTION(md5_file)
{
char *arg;
size_t arg_len;
bool raw_output = 0;
bool raw_output = false;
unsigned char buf[1024];
unsigned char digest[16];
PHP_MD5_CTX context;
Expand Down Expand Up @@ -113,7 +109,6 @@ PHP_FUNCTION(md5_file)
make_digest_ex(Z_STRVAL_P(return_value), digest, 16);
}
}
/* }}} */

/*
* This is an OpenSSL-compatible implementation of the RSA Data Security,
Expand Down
2 changes: 1 addition & 1 deletion ext/standard/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define MD5_H

PHPAPI void make_digest(char *md5str, const unsigned char *digest);
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, int len);
PHPAPI void make_digest_ex(char *md5str, const unsigned char *digest, size_t len);

/*
* This is an OpenSSL-compatible implementation of the RSA Data Security,
Expand Down