From: Yann Ylavic Date: Sun, 10 May 2020 15:23:08 +0000 (+0000) Subject: util_md5: avoid temporary stack result in ap_md5_binary(). X-Git-Tag: 2.5.0-alpha2-ci-test-only~1454 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce3b16e9881e6644eeb5a82888b3b76be4dbb635;p=thirdparty%2Fapache%2Fhttpd.git util_md5: avoid temporary stack result in ap_md5_binary(). git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1877551 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/util_md5.c b/server/util_md5.c index 148c60ceb43..bba3b88e423 100644 --- a/server/util_md5.c +++ b/server/util_md5.c @@ -54,7 +54,7 @@ AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int le { apr_md5_ctx_t my_md5; unsigned char hash[APR_MD5_DIGESTSIZE]; - char result[2 * APR_MD5_DIGESTSIZE + 1]; + char *result; /* * Take the MD5 hash of the string argument. @@ -67,9 +67,9 @@ AP_DECLARE(char *) ap_md5_binary(apr_pool_t *p, const unsigned char *buf, int le apr_md5_update(&my_md5, buf, (unsigned int)length); apr_md5_final(hash, &my_md5); - ap_bin2hex(hash, APR_MD5_DIGESTSIZE, result); - - return apr_pstrndup(p, result, APR_MD5_DIGESTSIZE*2); + result = apr_palloc(p, 2 * APR_MD5_DIGESTSIZE + 1); + ap_bin2hex(hash, APR_MD5_DIGESTSIZE, result); /* sets final '\0' */ + return result; } AP_DECLARE(char *) ap_md5(apr_pool_t *p, const unsigned char *string)