From eca64717be0db135926ebb7a05e05c0b304420cf Mon Sep 17 00:00:00 2001 From: David Garske Date: Thu, 2 Aug 2018 13:05:32 -0700 Subject: [PATCH] Fix for `BIO_wpending` to work correctly. --- src/bio.c | 33 ++++++++++++++++++++++++++++----- wolfssl/openssl/ssl.h | 3 ++- wolfssl/ssl.h | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/bio.c b/src/bio.c index a6b2d0174..dc067f599 100644 --- a/src/bio.c +++ b/src/bio.c @@ -499,7 +499,6 @@ int wolfSSL_BIO_write(WOLFSSL_BIO* bio, const void* data, int len) } -/*** TBD ***/ WOLFSSL_API long wolfSSL_BIO_ctrl(WOLFSSL_BIO *bio, int cmd, long larg, void *parg) { (void)bio; @@ -507,8 +506,8 @@ WOLFSSL_API long wolfSSL_BIO_ctrl(WOLFSSL_BIO *bio, int cmd, long larg, void *pa (void)larg; (void)parg; - WOLFSSL_ENTER("BIO_ctrl"); - return 1; + WOLFSSL_STUB("BIO_ctrl"); + return 0; } @@ -688,6 +687,31 @@ WOLFSSL_BIO* wolfSSL_BIO_next(WOLFSSL_BIO* bio) return bio->next; } +/* BIO_wpending returns the number of bytes pending to be written. */ +size_t wolfSSL_BIO_wpending(const WOLFSSL_BIO *bio) +{ + WOLFSSL_ENTER("BIO_wpending"); + + if (bio == NULL) + return 0; + + if (bio->ssl != NULL) { + return (long)wolfSSL_pending(bio->ssl); + } + + if (bio->type == WOLFSSL_BIO_MEMORY) { + return bio->wrSz; + } + + /* type BIO_BIO then check paired buffer */ + if (bio->type == WOLFSSL_BIO_BIO && bio->pair != NULL) { + WOLFSSL_BIO* pair = bio->pair; + return pair->wrIdx; + } + + return 0; + +} /* Return the number of pending bytes in read and write buffers */ size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *bio) @@ -741,14 +765,13 @@ long wolfSSL_BIO_get_mem_ptr(WOLFSSL_BIO *bio, WOLFSSL_BUF_MEM **ptr) return SSL_SUCCESS; } -/*** TBD ***/ WOLFSSL_API long wolfSSL_BIO_int_ctrl(WOLFSSL_BIO *bp, int cmd, long larg, int iarg) { (void) bp; (void) cmd; (void) larg; (void) iarg; - WOLFSSL_ENTER("BIO_int_ctrl"); + WOLFSSL_STUB("BIO_int_ctrl"); return 0; } diff --git a/wolfssl/openssl/ssl.h b/wolfssl/openssl/ssl.h index 3d041b00b..4765cca06 100644 --- a/wolfssl/openssl/ssl.h +++ b/wolfssl/openssl/ssl.h @@ -649,7 +649,7 @@ typedef STACK_OF(WOLFSSL_ASN1_OBJECT) GENERAL_NAMES; #define GENERAL_NAMES_free(GENERAL_NAMES)NULL #define SSL_set_mode(ssl,op) wolfSSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL) -#define BIO_wpending(b) wolfSSL_BIO_ctrl(b,BIO_CTRL_WPENDING,0,NULL) + #define SSL_CTX_use_certificate_ASN1 wolfSSL_CTX_use_certificate_ASN1 #define SSL_CTX_set0_chain(ctx,sk) \ wolfSSL_CTX_ctrl(ctx,SSL_CTRL_CHAIN,0,(char *)(sk)) @@ -663,6 +663,7 @@ typedef STACK_OF(WOLFSSL_ASN1_OBJECT) GENERAL_NAMES; #define BIO_new_file wolfSSL_BIO_new_file #define BIO_ctrl wolfSSL_BIO_ctrl #define BIO_ctrl_pending wolfSSL_BIO_ctrl_pending +#define BIO_wpending wolfSSL_BIO_wpending #define BIO_get_mem_ptr wolfSSL_BIO_get_mem_ptr #define BIO_int_ctrl wolfSSL_BIO_int_ctrl #define BIO_reset wolfSSL_BIO_reset diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 450bde165..21e77df97 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -2599,6 +2599,7 @@ WOLFSSL_API WOLFSSL_X509* wolfSSL_d2i_X509_bio(WOLFSSL_BIO* bio, WOLFSSL_X509** x509); WOLFSSL_API WOLFSSL_X509_STORE* wolfSSL_CTX_get_cert_store(WOLFSSL_CTX* ctx); +WOLFSSL_API size_t wolfSSL_BIO_wpending(const WOLFSSL_BIO *bio); WOLFSSL_API size_t wolfSSL_BIO_ctrl_pending(WOLFSSL_BIO *b); WOLFSSL_API size_t wolfSSL_get_server_random(const WOLFSSL *ssl, unsigned char *out, size_t outlen);