summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortobhe <>2022-11-09 01:05:45 +0000
committertobhe <>2022-11-09 01:05:45 +0000
commitb71fe696c55af5d47745792c89eeff0e59b39bf5 (patch)
tree1ad8e798fcc7bed585b3cf99aef483caad791dff
parentcb807f8b7e4cd28229e0cbdc51998a66b0e45e3d (diff)
downloadopenbsd-b71fe696c55af5d47745792c89eeff0e59b39bf5.tar.gz
openbsd-b71fe696c55af5d47745792c89eeff0e59b39bf5.tar.bz2
openbsd-b71fe696c55af5d47745792c89eeff0e59b39bf5.zip
Fix possible memory leak in BN_mpi2bn() if BN_bin2bn() fails.
found with CodeChecker feedback from millert@ ok tb@
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
index 4801192b50..9b743cca8c 100644
--- a/src/lib/libcrypto/bn/bn_mpi.c
+++ b/src/lib/libcrypto/bn/bn_mpi.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: bn_mpi.c,v 1.8 2017/01/29 17:49:22 beck Exp $ */ 1/* $OpenBSD: bn_mpi.c,v 1.9 2022/11/09 01:05:45 tobhe 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 *
@@ -92,8 +92,9 @@ BN_bn2mpi(const BIGNUM *a, unsigned char *d)
92} 92}
93 93
94BIGNUM * 94BIGNUM *
95BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a) 95BN_mpi2bn(const unsigned char *d, int n, BIGNUM *ain)
96{ 96{
97 BIGNUM *a = ain;
97 long len; 98 long len;
98 int neg = 0; 99 int neg = 0;
99 100
@@ -121,8 +122,11 @@ BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a)
121 d += 4; 122 d += 4;
122 if ((*d) & 0x80) 123 if ((*d) & 0x80)
123 neg = 1; 124 neg = 1;
124 if (BN_bin2bn(d, (int)len, a) == NULL) 125 if (BN_bin2bn(d, (int)len, a) == NULL) {
126 if (ain == NULL)
127 BN_free(a);
125 return (NULL); 128 return (NULL);
129 }
126 a->neg = neg; 130 a->neg = neg;
127 if (neg) { 131 if (neg) {
128 BN_clear_bit(a, BN_num_bits(a) - 1); 132 BN_clear_bit(a, BN_num_bits(a) - 1);