diff options
Diffstat (limited to 'crypto/pem')
-rw-r--r-- | crypto/pem/pem_lib.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/crypto/pem/pem_lib.c b/crypto/pem/pem_lib.c index 3d7e2f36a5..681153593b 100644 --- a/crypto/pem/pem_lib.c +++ b/crypto/pem/pem_lib.c @@ -971,19 +971,22 @@ int PEM_read_bio_ex(BIO *bp, char **name_out, char **header, headerlen = BIO_get_mem_data(headerB, NULL); *header = pem_malloc(headerlen + 1, flags); *data = pem_malloc(len, flags); - if (*header == NULL || *data == NULL) { - pem_free(*header, flags, 0); - pem_free(*data, flags, 0); - goto end; - } - BIO_read(headerB, *header, headerlen); + if (*header == NULL || *data == NULL) + goto out_free; + if (headerlen != 0 && BIO_read(headerB, *header, headerlen) != headerlen) + goto out_free; (*header)[headerlen] = '\0'; - BIO_read(dataB, *data, len); + if (BIO_read(dataB, *data, len) != len) + goto out_free; *len_out = len; *name_out = name; name = NULL; ret = 1; + goto end; +out_free: + pem_free(*header, flags, 0); + pem_free(*data, flags, 0); end: EVP_ENCODE_CTX_free(ctx); pem_free(name, flags, 0); |