Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 919594f

Browse files
author
Neil Conway
committed
Some builds (depends on crypto engine support?) of OpenSSL
0.9.7x have EVP_DigestFinal function which which clears all of EVP_MD_CTX. This makes pgcrypto crash in functions which re-use one digest context several times: hmac() and crypt() with md5 algorithm. Following patch fixes it by carring the digest info around EVP_DigestFinal and re-initializing cipher. Marko Kreen.
1 parent 852ef58 commit 919594f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

contrib/pgcrypto/openssl.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.13 2003/11/29 22:39:28 pgsql Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/openssl.c,v 1.14 2005/03/12 06:53:54 neilc Exp $
3030
*/
3131

3232
#include <postgres.h>
@@ -73,8 +73,15 @@ static void
7373
digest_finish(PX_MD * h, uint8 *dst)
7474
{
7575
EVP_MD_CTX *ctx = (EVP_MD_CTX *) h->p.ptr;
76+
const EVP_MD *md = EVP_MD_CTX_md(ctx);
7677

7778
EVP_DigestFinal(ctx, dst, NULL);
79+
80+
/*
81+
* Some builds of 0.9.7x clear all of ctx in EVP_DigestFinal.
82+
* Fix it by reinitializing ctx.
83+
*/
84+
EVP_DigestInit(ctx, md);
7885
}
7986

8087
static void

0 commit comments

Comments
 (0)