diff options
author | David Howells <dhowells@redhat.com> | 2014-09-16 12:29:03 -0400 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2014-09-16 12:29:03 -0400 |
commit | 3cd0920cde6a726b9965b60184f9d5a54358304d (patch) | |
tree | 94f4fc4be81e0d6d4dd21962ffa206a3815d99ca /crypto | |
parent | 54e2c2c1a9d6cbb270b0999a38545fa9a69bee43 (diff) |
PKCS#7: Provide a single place to do signed info block freeing
The code to free a signed info block is repeated several times, so move the
code to do it into a function of its own. This gives us a place to add clean
ups for stuff that gets added to pkcs7_signed_info.
Signed-off-by: David Howells <dhowells@redhat.com>
Acked-by: Vivek Goyal <vgoyal@redhat.com>
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asymmetric_keys/pkcs7_parser.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 42e56aa7d277..4c4ea35c338b 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c | |||
@@ -31,6 +31,18 @@ struct pkcs7_parse_context { | |||
31 | unsigned sinfo_index; | 31 | unsigned sinfo_index; |
32 | }; | 32 | }; |
33 | 33 | ||
34 | /* | ||
35 | * Free a signed information block. | ||
36 | */ | ||
37 | static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo) | ||
38 | { | ||
39 | if (sinfo) { | ||
40 | mpi_free(sinfo->sig.mpi[0]); | ||
41 | kfree(sinfo->sig.digest); | ||
42 | kfree(sinfo); | ||
43 | } | ||
44 | } | ||
45 | |||
34 | /** | 46 | /** |
35 | * pkcs7_free_message - Free a PKCS#7 message | 47 | * pkcs7_free_message - Free a PKCS#7 message |
36 | * @pkcs7: The PKCS#7 message to free | 48 | * @pkcs7: The PKCS#7 message to free |
@@ -54,9 +66,7 @@ void pkcs7_free_message(struct pkcs7_message *pkcs7) | |||
54 | while (pkcs7->signed_infos) { | 66 | while (pkcs7->signed_infos) { |
55 | sinfo = pkcs7->signed_infos; | 67 | sinfo = pkcs7->signed_infos; |
56 | pkcs7->signed_infos = sinfo->next; | 68 | pkcs7->signed_infos = sinfo->next; |
57 | mpi_free(sinfo->sig.mpi[0]); | 69 | pkcs7_free_signed_info(sinfo); |
58 | kfree(sinfo->sig.digest); | ||
59 | kfree(sinfo); | ||
60 | } | 70 | } |
61 | kfree(pkcs7); | 71 | kfree(pkcs7); |
62 | } | 72 | } |
@@ -100,16 +110,12 @@ struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen) | |||
100 | ctx->certs = cert->next; | 110 | ctx->certs = cert->next; |
101 | x509_free_certificate(cert); | 111 | x509_free_certificate(cert); |
102 | } | 112 | } |
103 | mpi_free(ctx->sinfo->sig.mpi[0]); | 113 | pkcs7_free_signed_info(ctx->sinfo); |
104 | kfree(ctx->sinfo->sig.digest); | ||
105 | kfree(ctx->sinfo); | ||
106 | kfree(ctx); | 114 | kfree(ctx); |
107 | return msg; | 115 | return msg; |
108 | 116 | ||
109 | error_decode: | 117 | error_decode: |
110 | mpi_free(ctx->sinfo->sig.mpi[0]); | 118 | pkcs7_free_signed_info(ctx->sinfo); |
111 | kfree(ctx->sinfo->sig.digest); | ||
112 | kfree(ctx->sinfo); | ||
113 | error_no_sinfo: | 119 | error_no_sinfo: |
114 | kfree(ctx); | 120 | kfree(ctx); |
115 | error_no_ctx: | 121 | error_no_ctx: |