diff options
author | Peiwei Hu <jlu.hpw@foxmail.com> | 2021-12-15 16:24:21 +0800 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-12-17 15:10:06 +0100 |
commit | c81eed84e4e9025e933778f5e8326b1e4435e094 (patch) | |
tree | 77ccb532d9c10faf874adb59a8e4dd75d9701323 /demos | |
parent | ec9135a62320c861ab17f7179ebe470686360c64 (diff) | |
download | openssl-c81eed84e4e9025e933778f5e8326b1e4435e094.tar.gz |
X509_STORE_new: memory needs to be freed
Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/17278)
Diffstat (limited to 'demos')
-rw-r--r-- | demos/cms/cms_ver.c | 13 | ||||
-rw-r--r-- | demos/smime/smver.c | 14 |
2 files changed, 17 insertions, 10 deletions
diff --git a/demos/cms/cms_ver.c b/demos/cms/cms_ver.c index cd2b01e1b0..3c0a7aa19e 100644 --- a/demos/cms/cms_ver.c +++ b/demos/cms/cms_ver.c @@ -27,16 +27,18 @@ int main(int argc, char **argv) /* Set up trusted CA certificate store */ st = X509_STORE_new(); + if (st == NULL) + goto err; /* Read in CA certificate */ tbio = BIO_new_file("cacert.pem", "r"); - if (!tbio) + if (tbio == NULL) goto err; cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - if (!cacert) + if (cacert == NULL) goto err; if (!X509_STORE_add_cert(st, cacert)) @@ -46,18 +48,18 @@ int main(int argc, char **argv) in = BIO_new_file("smout.txt", "r"); - if (!in) + if (in == NULL) goto err; /* parse message */ cms = SMIME_read_CMS(in, &cont); - if (!cms) + if (cms == NULL) goto err; /* File to output verified content to */ out = BIO_new_file("smver.txt", "w"); - if (!out) + if (out == NULL) goto err; if (!CMS_verify(cms, NULL, st, cont, out, 0)) { @@ -76,6 +78,7 @@ int main(int argc, char **argv) ERR_print_errors_fp(stderr); } + X509_STORE_free(st); CMS_ContentInfo_free(cms); X509_free(cacert); BIO_free(in); diff --git a/demos/smime/smver.c b/demos/smime/smver.c index 601462a041..5d552b1808 100644 --- a/demos/smime/smver.c +++ b/demos/smime/smver.c @@ -27,16 +27,18 @@ int main(int argc, char **argv) /* Set up trusted CA certificate store */ st = X509_STORE_new(); + if (st == NULL) + goto err; /* Read in signer certificate and private key */ tbio = BIO_new_file("cacert.pem", "r"); - if (!tbio) + if (tbio == NULL) goto err; cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL); - if (!cacert) + if (cacert == NULL) goto err; if (!X509_STORE_add_cert(st, cacert)) @@ -46,18 +48,18 @@ int main(int argc, char **argv) in = BIO_new_file("smout.txt", "r"); - if (!in) + if (in == NULL) goto err; /* Sign content */ p7 = SMIME_read_PKCS7(in, &cont); - if (!p7) + if (p7 == NULL) goto err; /* File to output verified content to */ out = BIO_new_file("smver.txt", "w"); - if (!out) + if (out == NULL) goto err; if (!PKCS7_verify(p7, NULL, st, cont, out, 0)) { @@ -74,6 +76,8 @@ int main(int argc, char **argv) fprintf(stderr, "Error Verifying Data\n"); ERR_print_errors_fp(stderr); } + + X509_STORE_free(st); PKCS7_free(p7); X509_free(cacert); BIO_free(in); |