summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-09-08 18:39:25 +0200
committerWolfgang Wiedmeyer <wolfgit@wiedmeyer.de>2017-09-08 18:39:25 +0200
commit5e890dbf71b90164de36b46862af3be9378c1a26 (patch)
tree64b8e22e08b803ad2d05005edb52f526951c4439
parent45718dc804b3523770c47a8afabae3325e7e21a6 (diff)
parent5f52622aa9140f75927fb1c94547c08c5212899e (diff)
downloadexternal_boringssl-5e890dbf71b90164de36b46862af3be9378c1a26.tar.gz
external_boringssl-5e890dbf71b90164de36b46862af3be9378c1a26.tar.bz2
external_boringssl-5e890dbf71b90164de36b46862af3be9378c1a26.zip
Merge remote-tracking branch 'lineageos/cm-13.0' into replicant-6.0replicant-6.0-0002
-rw-r--r--src/crypto/asn1/a_d2i_fp.c47
1 files changed, 31 insertions, 16 deletions
diff --git a/src/crypto/asn1/a_d2i_fp.c b/src/crypto/asn1/a_d2i_fp.c
index 6022c74..5c5d775 100644
--- a/src/crypto/asn1/a_d2i_fp.c
+++ b/src/crypto/asn1/a_d2i_fp.c
@@ -62,7 +62,7 @@
#include <openssl/err.h>
#include <openssl/mem.h>
-
+#define ASN1_CHUNK_INITIAL_SIZE (16 * 1024)
static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
#ifndef NO_OLD_ASN1
@@ -231,6 +231,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
want=c.slen;
if (want > (len-off))
{
+ size_t chunk_max = ASN1_CHUNK_INITIAL_SIZE;
want-=(len-off);
if (want > INT_MAX /* BIO_read takes an int length */ ||
len+want < len)
@@ -238,23 +239,37 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
OPENSSL_PUT_ERROR(ASN1, asn1_d2i_read_bio, ASN1_R_TOO_LONG);
goto err;
}
- if (!BUF_MEM_grow_clean(b,len+want))
- {
- OPENSSL_PUT_ERROR(ASN1, asn1_d2i_read_bio, ERR_R_MALLOC_FAILURE);
- goto err;
- }
while (want > 0)
{
- i=BIO_read(in,&(b->data[len]),want);
- if (i <= 0)
- {
- OPENSSL_PUT_ERROR(ASN1, asn1_d2i_read_bio, ASN1_R_NOT_ENOUGH_DATA);
- goto err;
- }
- /* This can't overflow because
- * |len+want| didn't overflow. */
- len+=i;
- want-=i;
+
+ /*
+ * Read content in chunks of increasing size
+ * so we can return an error for EOF without
+ * having to allocate the entire content length
+ * in one go.
+ */
+ size_t chunk = want > chunk_max ? chunk_max : want;
+
+ if (!BUF_MEM_grow_clean(b, len + chunk)) {
+ OPENSSL_PUT_ERROR(ASN1, asn1_d2i_read_bio, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+ want -= chunk;
+ while (chunk > 0) {
+ i = BIO_read(in, &(b->data[len]), chunk);
+ if (i <= 0) {
+ OPENSSL_PUT_ERROR(ASN1, asn1_d2i_read_bio, ASN1_R_NOT_ENOUGH_DATA);
+ goto err;
+ }
+ /*
+ * This can't overflow because |len+want| didn't
+ * overflow.
+ */
+ len += i;
+ chunk -= i;
+ }
+ if (chunk_max < INT_MAX/2)
+ chunk_max *= 2;
}
}
if (off + c.slen < off)