You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by yl...@apache.org on 2020/05/10 15:23:09 UTC

svn commit: r1877551 - /httpd/httpd/trunk/server/util_md5.c

Author: ylavic
Date: Sun May 10 15:23:08 2020
New Revision: 1877551

URL: http://svn.apache.org/viewvc?rev=1877551&view=rev
Log:
util_md5: avoid temporary stack result in ap_md5_binary().

Modified:
    httpd/httpd/trunk/server/util_md5.c

Modified: httpd/httpd/trunk/server/util_md5.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/util_md5.c?rev=1877551&r1=1877550&r2=1877551&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util_md5.c (original)
+++ httpd/httpd/trunk/server/util_md5.c Sun May 10 15:23:08 2020
@@ -54,7 +54,7 @@ AP_DECLARE(char *) ap_md5_binary(apr_poo
 {
     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_poo
     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)