From 091fc1014784a7b39af7325e5965defd49ec5160 Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Fri, 9 Dec 2016 13:16:17 -0700 Subject: [PATCH] adjust read ahead, some sanity checks and rebase --- examples/client/client.c | 4 +++- src/internal.c | 45 +--------------------------------------- tests/api.c | 2 ++ wolfcrypt/src/evp.c | 8 +++---- 4 files changed, 10 insertions(+), 49 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index 34aaf7565..e0cc24125 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -1292,7 +1292,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args) if (wolfSSL_CTX_get_read_ahead(ctx) != 0) { err_sys("bad read ahead default value"); } - /* wolfSSL_CTX_set_read_ahead(ctx, 1); use not recommended */ + if (wolfSSL_CTX_set_read_ahead(ctx, 1) != SSL_SUCCESS) { + err_sys("error setting read ahead value"); + } #endif ssl = wolfSSL_new(ctx); diff --git a/src/internal.c b/src/internal.c index 09a482d5e..67264caf0 100644 --- a/src/internal.c +++ b/src/internal.c @@ -9384,15 +9384,6 @@ static int GetInputData(WOLFSSL *ssl, word32 size) return MEMORY_E; } -#ifdef OPENSSL_EXTRA - /* if read ahead then try to read the full buffer size */ - if (ssl->readAhead != 0 && ssl->options.usingNonblock) { - if (maxLength > inSz) { - inSz = maxLength; - } - } -#endif /* OPENSSL_EXTRA */ - /* Put buffer data at start if not there */ if (usedLength > 0 && ssl->buffers.inputBuffer.idx != 0) XMEMMOVE(ssl->buffers.inputBuffer.buffer, @@ -9504,7 +9495,7 @@ int ProcessReply(WOLFSSL* ssl) int ret = 0, type, readSz; int atomicUser = 0; word32 startIdx = 0; -#if defined(WOLFSSL_DTLS) || defined(OPENSSL_EXTRA) +#if defined(WOLFSSL_DTLS) int used; #endif @@ -9535,18 +9526,6 @@ int ProcessReply(WOLFSSL* ssl) /* get header or return error */ if (!ssl->options.dtls) { - #ifdef OPENSSL_EXTRA - (void)used; - if (ssl->readAhead != 0 && ssl->options.usingNonblock) { - /* read ahead may already have header */ - used = ssl->buffers.inputBuffer.length - - ssl->buffers.inputBuffer.idx; - if (used < readSz) - if ((ret = GetInputData(ssl, readSz)) < 0) - return ret; - } - else - #endif /* OPENSSL_EXTRA */ if ((ret = GetInputData(ssl, readSz)) < 0) return ret; } else { @@ -9603,17 +9582,6 @@ int ProcessReply(WOLFSSL* ssl) /* get sz bytes or return error */ if (!ssl->options.dtls) { - #ifdef OPENSSL_EXTRA - if (ssl->readAhead != 0 && ssl->options.usingNonblock) { - /* read ahead may already have */ - used = ssl->buffers.inputBuffer.length - - ssl->buffers.inputBuffer.idx; - if (used < ssl->curSize) - if ((ret = GetInputData(ssl, ssl->curSize)) < 0) - return ret; - } - else - #endif /* OPENSSL_EXTRA */ if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; } else { @@ -9675,17 +9643,6 @@ int ProcessReply(WOLFSSL* ssl) /* get sz bytes or return error */ if (!ssl->options.dtls) { - #ifdef OPENSSL_EXTRA - if (ssl->readAhead != 0 && ssl->options.usingNonblock) { - /* read ahead may already have header */ - used = ssl->buffers.inputBuffer.length - - ssl->buffers.inputBuffer.idx; - if (used < ssl->curSize) - if ((ret = GetInputData(ssl, ssl->curSize)) < 0) - return ret; - } - else - #endif /* OPENSSL_EXTRA */ if ((ret = GetInputData(ssl, ssl->curSize)) < 0) return ret; } else { diff --git a/tests/api.c b/tests/api.c index 2281b2f0b..3022d7b92 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2991,6 +2991,8 @@ static void test_wolfSSL_BIO(void) AssertIntEQ(BIO_write(f_bio2, cert, sizeof(cert)), sizeof(cert)); AssertIntEQ((int)BIO_get_fp(f_bio2, &f2), SSL_SUCCESS); + AssertIntEQ(BIO_reset(f_bio2), 0); + AssertIntEQ(BIO_seek(f_bio2, 4), 0); BIO_free(f_bio1); BIO_free(f_bio2); diff --git a/wolfcrypt/src/evp.c b/wolfcrypt/src/evp.c index fc309d1a9..36c8bb07b 100644 --- a/wolfcrypt/src/evp.c +++ b/wolfcrypt/src/evp.c @@ -78,7 +78,7 @@ WOLFSSL_API void wolfSSL_EVP_CIPHER_CTX_free(WOLFSSL_EVP_CIPHER_CTX *ctx) WOLFSSL_API int wolfSSL_EVP_EncryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { - if (ctx->enc){ + if (ctx && ctx->enc){ WOLFSSL_ENTER("wolfSSL_EVP_EncryptFinal"); return wolfSSL_EVP_CipherFinal(ctx, out, outl); } @@ -89,7 +89,7 @@ WOLFSSL_API int wolfSSL_EVP_EncryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, WOLFSSL_API int wolfSSL_EVP_EncryptFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { - if (ctx->enc){ + if (ctx && ctx->enc){ WOLFSSL_ENTER("wolfSSL_EVP_EncryptFinal_ex"); return wolfSSL_EVP_CipherFinal(ctx, out, outl); } @@ -100,7 +100,7 @@ WOLFSSL_API int wolfSSL_EVP_EncryptFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx, WOLFSSL_API int wolfSSL_EVP_DecryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { - if (ctx->enc) + if (ctx && ctx->enc) return 0; else{ WOLFSSL_ENTER("wolfSSL_EVP_DecryptFinal"); @@ -111,7 +111,7 @@ WOLFSSL_API int wolfSSL_EVP_DecryptFinal(WOLFSSL_EVP_CIPHER_CTX *ctx, WOLFSSL_API int wolfSSL_EVP_DecryptFinal_ex(WOLFSSL_EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) { - if (ctx->enc) + if (ctx && ctx->enc) return 0; else{ WOLFSSL_ENTER("wolfSSL_EVP_CipherFinal_ex");