summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2018-06-14 17:14:12 +0000
committerjsing <>2018-06-14 17:14:12 +0000
commit79620b4c52c925d67e045a74f684717cb6cc0856 (patch)
tree935d43e6234c1286ace54aa96d3c1845135a1904 /src
parente5b20cdab05d12e65e8a92db59c2a96ef66cce0a (diff)
downloadopenbsd-79620b4c52c925d67e045a74f684717cb6cc0856.tar.gz
openbsd-79620b4c52c925d67e045a74f684717cb6cc0856.tar.bz2
openbsd-79620b4c52c925d67e045a74f684717cb6cc0856.zip
Fix a potential leak/incorrect return value in DSA signature generation.
In the very unlikely case where we have to repeat the signature generation, the DSA_SIG return value has already been allocated. This will either result in a leak when we allocate again on the next iteration, or it will give a false success (with missing signature values) if any error occurs on the next iteration. ok tb@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
index 7c23bb4909..d864875266 100644
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: dsa_ossl.c,v 1.33 2018/06/13 18:01:04 jsing Exp $ */ 1/* $OpenBSD: dsa_ossl.c,v 1.34 2018/06/14 17:14:12 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -146,9 +146,6 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
146 if (!BN_mod_mul(s, s, kinv, dsa->q, ctx)) 146 if (!BN_mod_mul(s, s, kinv, dsa->q, ctx))
147 goto err; 147 goto err;
148 148
149 ret = DSA_SIG_new();
150 if (ret == NULL)
151 goto err;
152 /* 149 /*
153 * Redo if r or s is zero as required by FIPS 186-3: this is very 150 * Redo if r or s is zero as required by FIPS 186-3: this is very
154 * unlikely. 151 * unlikely.
@@ -160,6 +157,11 @@ dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
160 } 157 }
161 goto redo; 158 goto redo;
162 } 159 }
160
161 if ((ret = DSA_SIG_new()) == NULL) {
162 reason = ERR_R_MALLOC_FAILURE;
163 goto err;
164 }
163 ret->r = r; 165 ret->r = r;
164 ret->s = s; 166 ret->s = s;
165 167