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)
(cherry picked from commit c81eed84e4e9025e933778f5e8326b1e4435e094)
Peiwei Hu authored 2 years ago
Tomas Mraz committed 2 years ago
26 | 26 |
/* Set up trusted CA certificate store */
|
27 | 27 |
|
28 | 28 |
st = X509_STORE_new();
|
|
29 |
if (st == NULL)
|
|
30 |
goto err;
|
29 | 31 |
|
30 | 32 |
/* Read in CA certificate */
|
31 | 33 |
tbio = BIO_new_file("cacert.pem", "r");
|
32 | 34 |
|
33 | |
if (!tbio)
|
|
35 |
if (tbio == NULL)
|
34 | 36 |
goto err;
|
35 | 37 |
|
36 | 38 |
cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
|
37 | 39 |
|
38 | |
if (!cacert)
|
|
40 |
if (cacert == NULL)
|
39 | 41 |
goto err;
|
40 | 42 |
|
41 | 43 |
if (!X509_STORE_add_cert(st, cacert))
|
|
45 | 47 |
|
46 | 48 |
in = BIO_new_file("smout.txt", "r");
|
47 | 49 |
|
48 | |
if (!in)
|
|
50 |
if (in == NULL)
|
49 | 51 |
goto err;
|
50 | 52 |
|
51 | 53 |
/* parse message */
|
52 | 54 |
cms = SMIME_read_CMS(in, &cont);
|
53 | 55 |
|
54 | |
if (!cms)
|
|
56 |
if (cms == NULL)
|
55 | 57 |
goto err;
|
56 | 58 |
|
57 | 59 |
/* File to output verified content to */
|
58 | 60 |
out = BIO_new_file("smver.txt", "w");
|
59 | |
if (!out)
|
|
61 |
if (out == NULL)
|
60 | 62 |
goto err;
|
61 | 63 |
|
62 | 64 |
if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
|
|
75 | 77 |
ERR_print_errors_fp(stderr);
|
76 | 78 |
}
|
77 | 79 |
|
|
80 |
X509_STORE_free(st);
|
78 | 81 |
CMS_ContentInfo_free(cms);
|
79 | 82 |
X509_free(cacert);
|
80 | 83 |
BIO_free(in);
|
26 | 26 |
/* Set up trusted CA certificate store */
|
27 | 27 |
|
28 | 28 |
st = X509_STORE_new();
|
|
29 |
if (st == NULL)
|
|
30 |
goto err;
|
29 | 31 |
|
30 | 32 |
/* Read in signer certificate and private key */
|
31 | 33 |
tbio = BIO_new_file("cacert.pem", "r");
|
32 | 34 |
|
33 | |
if (!tbio)
|
|
35 |
if (tbio == NULL)
|
34 | 36 |
goto err;
|
35 | 37 |
|
36 | 38 |
cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
|
37 | 39 |
|
38 | |
if (!cacert)
|
|
40 |
if (cacert == NULL)
|
39 | 41 |
goto err;
|
40 | 42 |
|
41 | 43 |
if (!X509_STORE_add_cert(st, cacert))
|
|
45 | 47 |
|
46 | 48 |
in = BIO_new_file("smout.txt", "r");
|
47 | 49 |
|
48 | |
if (!in)
|
|
50 |
if (in == NULL)
|
49 | 51 |
goto err;
|
50 | 52 |
|
51 | 53 |
/* Sign content */
|
52 | 54 |
p7 = SMIME_read_PKCS7(in, &cont);
|
53 | 55 |
|
54 | |
if (!p7)
|
|
56 |
if (p7 == NULL)
|
55 | 57 |
goto err;
|
56 | 58 |
|
57 | 59 |
/* File to output verified content to */
|
58 | 60 |
out = BIO_new_file("smver.txt", "w");
|
59 | |
if (!out)
|
|
61 |
if (out == NULL)
|
60 | 62 |
goto err;
|
61 | 63 |
|
62 | 64 |
if (!PKCS7_verify(p7, NULL, st, cont, out, 0)) {
|
|
73 | 75 |
fprintf(stderr, "Error Verifying Data\n");
|
74 | 76 |
ERR_print_errors_fp(stderr);
|
75 | 77 |
}
|
|
78 |
|
|
79 |
X509_STORE_free(st);
|
76 | 80 |
PKCS7_free(p7);
|
77 | 81 |
X509_free(cacert);
|
78 | 82 |
BIO_free(in);
|