diff options
author | guenther <> | 2014-07-22 06:55:22 +0000 |
---|---|---|
committer | guenther <> | 2014-07-22 06:55:22 +0000 |
commit | 4ed4f9bf6421a1b24b17919b26ff064b4d031b4d (patch) | |
tree | 2702cb7bef3a792a8fef30532d36a70506dc47ce /src | |
parent | 2e3eeccd8125dfe98003dad4c93edf087446f0e9 (diff) | |
download | openbsd-4ed4f9bf6421a1b24b17919b26ff064b4d031b4d.tar.gz openbsd-4ed4f9bf6421a1b24b17919b26ff064b4d031b4d.tar.bz2 openbsd-4ed4f9bf6421a1b24b17919b26ff064b4d031b4d.zip |
Handle failure of NETSCAPE_SPKI_b64_encode() and don't leak memory
when BIO_new_{file,fp}() fails.
inspired by a diff from logan@ ok miod@
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libssl/src/apps/spkac.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/lib/libssl/src/apps/spkac.c b/src/lib/libssl/src/apps/spkac.c index 3eef33061d..b13a83d097 100644 --- a/src/lib/libssl/src/apps/spkac.c +++ b/src/lib/libssl/src/apps/spkac.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: spkac.c,v 1.21 2014/07/14 00:35:10 deraadt Exp $ */ | 1 | /* $OpenBSD: spkac.c,v 1.22 2014/07/22 06:55:22 guenther Exp $ */ |
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
3 | * project 1999. Based on an original idea by Massimiliano Pala | 3 | * project 1999. Based on an original idea by Massimiliano Pala |
4 | * (madwolf@openca.org). | 4 | * (madwolf@openca.org). |
@@ -190,21 +190,25 @@ bad: | |||
190 | NETSCAPE_SPKI_set_pubkey(spki, pkey); | 190 | NETSCAPE_SPKI_set_pubkey(spki, pkey); |
191 | NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); | 191 | NETSCAPE_SPKI_sign(spki, pkey, EVP_md5()); |
192 | spkstr = NETSCAPE_SPKI_b64_encode(spki); | 192 | spkstr = NETSCAPE_SPKI_b64_encode(spki); |
193 | if (spkstr == NULL) { | ||
194 | BIO_printf(bio_err, "Error encoding SPKAC\n"); | ||
195 | ERR_print_errors(bio_err); | ||
196 | goto end; | ||
197 | } | ||
193 | 198 | ||
194 | if (outfile) | 199 | if (outfile) |
195 | out = BIO_new_file(outfile, "w"); | 200 | out = BIO_new_file(outfile, "w"); |
196 | else { | 201 | else |
197 | out = BIO_new_fp(stdout, BIO_NOCLOSE); | 202 | out = BIO_new_fp(stdout, BIO_NOCLOSE); |
198 | } | ||
199 | 203 | ||
200 | if (!out) { | 204 | if (!out) { |
201 | BIO_printf(bio_err, "Error opening output file\n"); | 205 | BIO_printf(bio_err, "Error opening output file\n"); |
202 | ERR_print_errors(bio_err); | 206 | ERR_print_errors(bio_err); |
203 | goto end; | 207 | } else { |
208 | BIO_printf(out, "SPKAC=%s\n", spkstr); | ||
209 | ret = 0; | ||
204 | } | 210 | } |
205 | BIO_printf(out, "SPKAC=%s\n", spkstr); | ||
206 | free(spkstr); | 211 | free(spkstr); |
207 | ret = 0; | ||
208 | goto end; | 212 | goto end; |
209 | } | 213 | } |
210 | if (infile) | 214 | if (infile) |