diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/asymmetric_keys/pkcs7_parser.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/crypto/asymmetric_keys/pkcs7_parser.c b/crypto/asymmetric_keys/pkcs7_parser.c index 4c4ea35c338b..1e9861da7ee4 100644 --- a/crypto/asymmetric_keys/pkcs7_parser.c +++ b/crypto/asymmetric_keys/pkcs7_parser.c | |||
@@ -81,47 +81,46 @@ EXPORT_SYMBOL_GPL(pkcs7_free_message); | |||
81 | struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen) | 81 | struct pkcs7_message *pkcs7_parse_message(const void *data, size_t datalen) |
82 | { | 82 | { |
83 | struct pkcs7_parse_context *ctx; | 83 | struct pkcs7_parse_context *ctx; |
84 | struct pkcs7_message *msg; | 84 | struct pkcs7_message *msg = ERR_PTR(-ENOMEM); |
85 | long ret; | 85 | int ret; |
86 | 86 | ||
87 | ret = -ENOMEM; | ||
88 | msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL); | ||
89 | if (!msg) | ||
90 | goto error_no_sig; | ||
91 | ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL); | 87 | ctx = kzalloc(sizeof(struct pkcs7_parse_context), GFP_KERNEL); |
92 | if (!ctx) | 88 | if (!ctx) |
93 | goto error_no_ctx; | 89 | goto out_no_ctx; |
90 | ctx->msg = kzalloc(sizeof(struct pkcs7_message), GFP_KERNEL); | ||
91 | if (!ctx->msg) | ||
92 | goto out_no_msg; | ||
94 | ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL); | 93 | ctx->sinfo = kzalloc(sizeof(struct pkcs7_signed_info), GFP_KERNEL); |
95 | if (!ctx->sinfo) | 94 | if (!ctx->sinfo) |
96 | goto error_no_sinfo; | 95 | goto out_no_sinfo; |
97 | 96 | ||
98 | ctx->msg = msg; | ||
99 | ctx->data = (unsigned long)data; | 97 | ctx->data = (unsigned long)data; |
100 | ctx->ppcerts = &ctx->certs; | 98 | ctx->ppcerts = &ctx->certs; |
101 | ctx->ppsinfo = &ctx->msg->signed_infos; | 99 | ctx->ppsinfo = &ctx->msg->signed_infos; |
102 | 100 | ||
103 | /* Attempt to decode the signature */ | 101 | /* Attempt to decode the signature */ |
104 | ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen); | 102 | ret = asn1_ber_decoder(&pkcs7_decoder, ctx, data, datalen); |
105 | if (ret < 0) | 103 | if (ret < 0) { |
106 | goto error_decode; | 104 | msg = ERR_PTR(ret); |
105 | goto out; | ||
106 | } | ||
107 | |||
108 | msg = ctx->msg; | ||
109 | ctx->msg = NULL; | ||
107 | 110 | ||
111 | out: | ||
108 | while (ctx->certs) { | 112 | while (ctx->certs) { |
109 | struct x509_certificate *cert = ctx->certs; | 113 | struct x509_certificate *cert = ctx->certs; |
110 | ctx->certs = cert->next; | 114 | ctx->certs = cert->next; |
111 | x509_free_certificate(cert); | 115 | x509_free_certificate(cert); |
112 | } | 116 | } |
113 | pkcs7_free_signed_info(ctx->sinfo); | 117 | pkcs7_free_signed_info(ctx->sinfo); |
118 | out_no_sinfo: | ||
119 | pkcs7_free_message(ctx->msg); | ||
120 | out_no_msg: | ||
114 | kfree(ctx); | 121 | kfree(ctx); |
122 | out_no_ctx: | ||
115 | return msg; | 123 | return msg; |
116 | |||
117 | error_decode: | ||
118 | pkcs7_free_signed_info(ctx->sinfo); | ||
119 | error_no_sinfo: | ||
120 | kfree(ctx); | ||
121 | error_no_ctx: | ||
122 | pkcs7_free_message(msg); | ||
123 | error_no_sig: | ||
124 | return ERR_PTR(ret); | ||
125 | } | 124 | } |
126 | EXPORT_SYMBOL_GPL(pkcs7_parse_message); | 125 | EXPORT_SYMBOL_GPL(pkcs7_parse_message); |
127 | 126 | ||