summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/asn1/a_d2i_fp.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/asn1/a_d2i_fp.c')
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
index a80fbe9ff7..b67b75e7c2 100644
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ b/src/lib/libcrypto/asn1/a_d2i_fp.c
@@ -149,7 +149,12 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
149 ASN1_CTX c; 149 ASN1_CTX c;
150 int want=HEADER_SIZE; 150 int want=HEADER_SIZE;
151 int eos=0; 151 int eos=0;
152#if defined(__GNUC__) && defined(__ia64)
153 /* pathetic compiler bug in all known versions as of Nov. 2002 */
154 long off=0;
155#else
152 int off=0; 156 int off=0;
157#endif
153 int len=0; 158 int len=0;
154 159
155 b=BUF_MEM_new(); 160 b=BUF_MEM_new();
@@ -166,7 +171,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
166 { 171 {
167 want-=(len-off); 172 want-=(len-off);
168 173
169 if (!BUF_MEM_grow(b,len+want)) 174 if (!BUF_MEM_grow_clean(b,len+want))
170 { 175 {
171 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); 176 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
172 goto err; 177 goto err;
@@ -221,18 +226,23 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
221 if (want > (len-off)) 226 if (want > (len-off))
222 { 227 {
223 want-=(len-off); 228 want-=(len-off);
224 if (!BUF_MEM_grow(b,len+want)) 229 if (!BUF_MEM_grow_clean(b,len+want))
225 { 230 {
226 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); 231 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
227 goto err; 232 goto err;
228 } 233 }
229 i=BIO_read(in,&(b->data[len]),want); 234 while (want > 0)
230 if (i <= 0)
231 { 235 {
232 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA); 236 i=BIO_read(in,&(b->data[len]),want);
233 goto err; 237 if (i <= 0)
238 {
239 ASN1err(ASN1_F_ASN1_D2I_BIO,
240 ASN1_R_NOT_ENOUGH_DATA);
241 goto err;
242 }
243 len+=i;
244 want -= i;
234 } 245 }
235 len+=i;
236 } 246 }
237 off+=(int)c.slen; 247 off+=(int)c.slen;
238 if (eos <= 0) 248 if (eos <= 0)