Lines 1-162
Link Here
|
1 |
--- crypto/pkcs7/pk7_doit.c.orig 2015-02-09 01:31:52 UTC |
|
|
2 |
+++ crypto/pkcs7/pk7_doit.c |
3 |
@@ -1,4 +1,4 @@ |
4 |
-/* $OpenBSD: pk7_doit.c,v 1.30 2014/10/22 13:02:04 jsing Exp $ */ |
5 |
+/* $OpenBSD: pk7_doit.c,v 1.31 2015/02/07 13:19:15 doug Exp $ */ |
6 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
7 |
* All rights reserved. |
8 |
* |
9 |
@@ -261,6 +261,28 @@ PKCS7_dataInit(PKCS7 *p7, BIO *bio) |
10 |
PKCS7_RECIP_INFO *ri = NULL; |
11 |
ASN1_OCTET_STRING *os = NULL; |
12 |
|
13 |
+ if (p7 == NULL) { |
14 |
+ PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_INVALID_NULL_POINTER); |
15 |
+ return NULL; |
16 |
+ } |
17 |
+ |
18 |
+ /* |
19 |
+ * The content field in the PKCS7 ContentInfo is optional, |
20 |
+ * but that really only applies to inner content (precisely, |
21 |
+ * detached signatures). |
22 |
+ * |
23 |
+ * When reading content, missing outer content is therefore |
24 |
+ * treated as an error. |
25 |
+ * |
26 |
+ * When creating content, PKCS7_content_new() must be called |
27 |
+ * before calling this method, so a NULL p7->d is always |
28 |
+ * an error. |
29 |
+ */ |
30 |
+ if (p7->d.ptr == NULL) { |
31 |
+ PKCS7err(PKCS7_F_PKCS7_DATAINIT, PKCS7_R_NO_CONTENT); |
32 |
+ return NULL; |
33 |
+ } |
34 |
+ |
35 |
i = OBJ_obj2nid(p7->type); |
36 |
p7->state = PKCS7_S_HEADER; |
37 |
|
38 |
@@ -417,6 +439,17 @@ PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pk |
39 |
unsigned char *ek = NULL, *tkey = NULL; |
40 |
int eklen = 0, tkeylen = 0; |
41 |
|
42 |
+ if (p7 == NULL) { |
43 |
+ PKCS7err(PKCS7_F_PKCS7_DATADECODE, |
44 |
+ PKCS7_R_INVALID_NULL_POINTER); |
45 |
+ return NULL; |
46 |
+ } |
47 |
+ |
48 |
+ if (p7->d.ptr == NULL) { |
49 |
+ PKCS7err(PKCS7_F_PKCS7_DATADECODE, PKCS7_R_NO_CONTENT); |
50 |
+ return NULL; |
51 |
+ } |
52 |
+ |
53 |
i = OBJ_obj2nid(p7->type); |
54 |
p7->state = PKCS7_S_HEADER; |
55 |
|
56 |
@@ -691,6 +724,17 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) |
57 |
STACK_OF(PKCS7_SIGNER_INFO) *si_sk = NULL; |
58 |
ASN1_OCTET_STRING *os = NULL; |
59 |
|
60 |
+ if (p7 == NULL) { |
61 |
+ PKCS7err(PKCS7_F_PKCS7_DATAFINAL, |
62 |
+ PKCS7_R_INVALID_NULL_POINTER); |
63 |
+ return 0; |
64 |
+ } |
65 |
+ |
66 |
+ if (p7->d.ptr == NULL) { |
67 |
+ PKCS7err(PKCS7_F_PKCS7_DATAFINAL, PKCS7_R_NO_CONTENT); |
68 |
+ return 0; |
69 |
+ } |
70 |
+ |
71 |
EVP_MD_CTX_init(&ctx_tmp); |
72 |
i = OBJ_obj2nid(p7->type); |
73 |
p7->state = PKCS7_S_HEADER; |
74 |
@@ -736,6 +780,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) |
75 |
/* If detached data then the content is excluded */ |
76 |
if (PKCS7_type_is_data(p7->d.sign->contents) && p7->detached) { |
77 |
M_ASN1_OCTET_STRING_free(os); |
78 |
+ os = NULL; |
79 |
p7->d.sign->contents->d.data = NULL; |
80 |
} |
81 |
break; |
82 |
@@ -750,6 +795,7 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) |
83 |
if (PKCS7_type_is_data(p7->d.digest->contents) && |
84 |
p7->detached) { |
85 |
M_ASN1_OCTET_STRING_free(os); |
86 |
+ os = NULL; |
87 |
p7->d.digest->contents->d.data = NULL; |
88 |
} |
89 |
break; |
90 |
@@ -815,22 +861,32 @@ PKCS7_dataFinal(PKCS7 *p7, BIO *bio) |
91 |
M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len); |
92 |
} |
93 |
|
94 |
- if (!PKCS7_is_detached(p7) && !(os->flags & ASN1_STRING_FLAG_NDEF)) { |
95 |
- char *cont; |
96 |
- long contlen; |
97 |
- btmp = BIO_find_type(bio, BIO_TYPE_MEM); |
98 |
- if (btmp == NULL) { |
99 |
- PKCS7err(PKCS7_F_PKCS7_DATAFINAL, |
100 |
- PKCS7_R_UNABLE_TO_FIND_MEM_BIO); |
101 |
+ if (!PKCS7_is_detached(p7)) { |
102 |
+ /* |
103 |
+ * NOTE: only reach os == NULL here because detached |
104 |
+ * digested data support is broken? |
105 |
+ */ |
106 |
+ if (os == NULL) |
107 |
goto err; |
108 |
+ if (!(os->flags & ASN1_STRING_FLAG_NDEF)) { |
109 |
+ char *cont; |
110 |
+ long contlen; |
111 |
+ |
112 |
+ btmp = BIO_find_type(bio, BIO_TYPE_MEM); |
113 |
+ if (btmp == NULL) { |
114 |
+ PKCS7err(PKCS7_F_PKCS7_DATAFINAL, |
115 |
+ PKCS7_R_UNABLE_TO_FIND_MEM_BIO); |
116 |
+ goto err; |
117 |
+ } |
118 |
+ contlen = BIO_get_mem_data(btmp, &cont); |
119 |
+ /* |
120 |
+ * Mark the BIO read only then we can use its copy |
121 |
+ * of the data instead of making an extra copy. |
122 |
+ */ |
123 |
+ BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY); |
124 |
+ BIO_set_mem_eof_return(btmp, 0); |
125 |
+ ASN1_STRING_set0(os, (unsigned char *)cont, contlen); |
126 |
} |
127 |
- contlen = BIO_get_mem_data(btmp, &cont); |
128 |
- /* Mark the BIO read only then we can use its copy of the data |
129 |
- * instead of making an extra copy. |
130 |
- */ |
131 |
- BIO_set_flags(btmp, BIO_FLAGS_MEM_RDONLY); |
132 |
- BIO_set_mem_eof_return(btmp, 0); |
133 |
- ASN1_STRING_set0(os, (unsigned char *)cont, contlen); |
134 |
} |
135 |
ret = 1; |
136 |
err: |
137 |
@@ -905,6 +961,17 @@ PKCS7_dataVerify(X509_STORE *cert_store, |
138 |
STACK_OF(X509) *cert; |
139 |
X509 *x509; |
140 |
|
141 |
+ if (p7 == NULL) { |
142 |
+ PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, |
143 |
+ PKCS7_R_INVALID_NULL_POINTER); |
144 |
+ return 0; |
145 |
+ } |
146 |
+ |
147 |
+ if (p7->d.ptr == NULL) { |
148 |
+ PKCS7err(PKCS7_F_PKCS7_DATAVERIFY, PKCS7_R_NO_CONTENT); |
149 |
+ return 0; |
150 |
+ } |
151 |
+ |
152 |
if (PKCS7_type_is_signed(p7)) { |
153 |
cert = p7->d.sign->cert; |
154 |
} else if (PKCS7_type_is_signedAndEnveloped(p7)) { |
155 |
@@ -941,6 +1008,7 @@ PKCS7_dataVerify(X509_STORE *cert_store, |
156 |
|
157 |
return PKCS7_signatureVerify(bio, p7, si, x509); |
158 |
err: |
159 |
+ |
160 |
return ret; |
161 |
} |
162 |
|