summaryrefslogtreecommitdiff
path: root/Cryptlib/OpenSSL/crypto/evp/bio_md.c
diff options
context:
space:
mode:
Diffstat (limited to 'Cryptlib/OpenSSL/crypto/evp/bio_md.c')
-rw-r--r--Cryptlib/OpenSSL/crypto/evp/bio_md.c25
1 files changed, 18 insertions, 7 deletions
diff --git a/Cryptlib/OpenSSL/crypto/evp/bio_md.c b/Cryptlib/OpenSSL/crypto/evp/bio_md.c
index 9f0024b9..f0b0c0c0 100644
--- a/Cryptlib/OpenSSL/crypto/evp/bio_md.c
+++ b/Cryptlib/OpenSSL/crypto/evp/bio_md.c
@@ -134,7 +134,9 @@ static int md_read(BIO *b, char *out, int outl)
ret = BIO_read(b->next_bio, out, outl);
if (b->init) {
if (ret > 0) {
- EVP_DigestUpdate(ctx, (unsigned char *)out, (unsigned int)ret);
+ if (EVP_DigestUpdate(ctx, (unsigned char *)out,
+ (unsigned int)ret) <= 0)
+ return (-1);
}
}
BIO_clear_retry_flags(b);
@@ -155,12 +157,17 @@ static int md_write(BIO *b, const char *in, int inl)
ret = BIO_write(b->next_bio, in, inl);
if (b->init) {
if (ret > 0) {
- EVP_DigestUpdate(ctx, (const unsigned char *)in,
- (unsigned int)ret);
+ if (!EVP_DigestUpdate(ctx, (const unsigned char *)in,
+ (unsigned int)ret)) {
+ BIO_clear_retry_flags(b);
+ return 0;
+ }
}
}
- BIO_clear_retry_flags(b);
- BIO_copy_next_retry(b);
+ if (b->next_bio != NULL) {
+ BIO_clear_retry_flags(b);
+ BIO_copy_next_retry(b);
+ }
return (ret);
}
@@ -193,6 +200,7 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_C_GET_MD_CTX:
pctx = ptr;
*pctx = ctx;
+ b->init = 1;
break;
case BIO_C_SET_MD_CTX:
if (b->init)
@@ -215,7 +223,8 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
case BIO_CTRL_DUP:
dbio = ptr;
dctx = dbio->ptr;
- EVP_MD_CTX_copy_ex(dctx, ctx);
+ if (!EVP_MD_CTX_copy_ex(dctx, ctx))
+ return 0;
b->init = 1;
break;
default:
@@ -247,7 +256,9 @@ static int md_gets(BIO *bp, char *buf, int size)
ctx = bp->ptr;
if (size < ctx->digest->md_size)
return (0);
- EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret);
+ if (EVP_DigestFinal_ex(ctx, (unsigned char *)buf, &ret) <= 0)
+ return -1;
+
return ((int)ret);
}