Fossil SCM
Cherrypicked [5fd1ca6f] (was checked in to wrong branch).
Commit
8d456a5b772edadd2adefaad8da9d6c03758bce0d5b21fe75ef1fffc901f0e44
Parent
9769c4f756390a7…
1 file changed
+17
-5
+17
-5
| --- src/http_ssl.c | ||
| +++ src/http_ssl.c | ||
| @@ -750,10 +750,11 @@ | ||
| 750 | 750 | |
| 751 | 751 | typedef struct SslServerConn { |
| 752 | 752 | SSL *ssl; /* The SSL codec */ |
| 753 | 753 | int atEof; /* True when EOF reached. */ |
| 754 | 754 | int iSocket; /* The socket */ |
| 755 | + BIO *bio; /* BIO object. Needed for EOF detection. */ | |
| 755 | 756 | } SslServerConn; |
| 756 | 757 | |
| 757 | 758 | /* |
| 758 | 759 | ** Create a new server-side codec. The argument is the socket's file |
| 759 | 760 | ** descriptor from which the codec reads and writes. The returned |
| @@ -763,10 +764,11 @@ | ||
| 763 | 764 | SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer)); |
| 764 | 765 | BIO *b = BIO_new_socket(iSocket, 0); |
| 765 | 766 | pServer->ssl = SSL_new(sslCtx); |
| 766 | 767 | pServer->atEof = 0; |
| 767 | 768 | pServer->iSocket = iSocket; |
| 769 | + pServer->bio = b; | |
| 768 | 770 | SSL_set_bio(pServer->ssl, b, b); |
| 769 | 771 | SSL_accept(pServer->ssl); |
| 770 | 772 | return (void*)pServer; |
| 771 | 773 | } |
| 772 | 774 | |
| @@ -791,17 +793,27 @@ | ||
| 791 | 793 | /* |
| 792 | 794 | ** Read cleartext bytes that have been received from the client and |
| 793 | 795 | ** decrypted by the SSL server codec. |
| 794 | 796 | */ |
| 795 | 797 | size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){ |
| 796 | - int n; | |
| 798 | + int n, err = 0; | |
| 799 | + size_t rc = 0; | |
| 797 | 800 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 798 | - if( pServer->atEof ) return 0; | |
| 799 | 801 | if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); } |
| 800 | - n = SSL_read(pServer->ssl, zBuf, (int)nBuf); | |
| 801 | - if( n==0 ) pServer->atEof = 1; | |
| 802 | - return n<=0 ? 0 : n; | |
| 802 | + while( 0==err && nBuf!=rc && 0==pServer->atEof ){ | |
| 803 | + n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc)); | |
| 804 | + if( n==0 ){ | |
| 805 | + pServer->atEof = 1; | |
| 806 | + break; | |
| 807 | + } | |
| 808 | + err = SSL_get_error(pServer->ssl, n); | |
| 809 | + if(0==err){ | |
| 810 | + rc += n; | |
| 811 | + pServer->atEof = BIO_eof(pServer->bio); | |
| 812 | + } | |
| 813 | + } | |
| 814 | + return rc; | |
| 803 | 815 | } |
| 804 | 816 | |
| 805 | 817 | /* |
| 806 | 818 | ** Read a single line of text from the client. |
| 807 | 819 | */ |
| 808 | 820 |
| --- src/http_ssl.c | |
| +++ src/http_ssl.c | |
| @@ -750,10 +750,11 @@ | |
| 750 | |
| 751 | typedef struct SslServerConn { |
| 752 | SSL *ssl; /* The SSL codec */ |
| 753 | int atEof; /* True when EOF reached. */ |
| 754 | int iSocket; /* The socket */ |
| 755 | } SslServerConn; |
| 756 | |
| 757 | /* |
| 758 | ** Create a new server-side codec. The argument is the socket's file |
| 759 | ** descriptor from which the codec reads and writes. The returned |
| @@ -763,10 +764,11 @@ | |
| 763 | SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer)); |
| 764 | BIO *b = BIO_new_socket(iSocket, 0); |
| 765 | pServer->ssl = SSL_new(sslCtx); |
| 766 | pServer->atEof = 0; |
| 767 | pServer->iSocket = iSocket; |
| 768 | SSL_set_bio(pServer->ssl, b, b); |
| 769 | SSL_accept(pServer->ssl); |
| 770 | return (void*)pServer; |
| 771 | } |
| 772 | |
| @@ -791,17 +793,27 @@ | |
| 791 | /* |
| 792 | ** Read cleartext bytes that have been received from the client and |
| 793 | ** decrypted by the SSL server codec. |
| 794 | */ |
| 795 | size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){ |
| 796 | int n; |
| 797 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 798 | if( pServer->atEof ) return 0; |
| 799 | if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); } |
| 800 | n = SSL_read(pServer->ssl, zBuf, (int)nBuf); |
| 801 | if( n==0 ) pServer->atEof = 1; |
| 802 | return n<=0 ? 0 : n; |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | ** Read a single line of text from the client. |
| 807 | */ |
| 808 |
| --- src/http_ssl.c | |
| +++ src/http_ssl.c | |
| @@ -750,10 +750,11 @@ | |
| 750 | |
| 751 | typedef struct SslServerConn { |
| 752 | SSL *ssl; /* The SSL codec */ |
| 753 | int atEof; /* True when EOF reached. */ |
| 754 | int iSocket; /* The socket */ |
| 755 | BIO *bio; /* BIO object. Needed for EOF detection. */ |
| 756 | } SslServerConn; |
| 757 | |
| 758 | /* |
| 759 | ** Create a new server-side codec. The argument is the socket's file |
| 760 | ** descriptor from which the codec reads and writes. The returned |
| @@ -763,10 +764,11 @@ | |
| 764 | SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer)); |
| 765 | BIO *b = BIO_new_socket(iSocket, 0); |
| 766 | pServer->ssl = SSL_new(sslCtx); |
| 767 | pServer->atEof = 0; |
| 768 | pServer->iSocket = iSocket; |
| 769 | pServer->bio = b; |
| 770 | SSL_set_bio(pServer->ssl, b, b); |
| 771 | SSL_accept(pServer->ssl); |
| 772 | return (void*)pServer; |
| 773 | } |
| 774 | |
| @@ -791,17 +793,27 @@ | |
| 793 | /* |
| 794 | ** Read cleartext bytes that have been received from the client and |
| 795 | ** decrypted by the SSL server codec. |
| 796 | */ |
| 797 | size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){ |
| 798 | int n, err = 0; |
| 799 | size_t rc = 0; |
| 800 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 801 | if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); } |
| 802 | while( 0==err && nBuf!=rc && 0==pServer->atEof ){ |
| 803 | n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc)); |
| 804 | if( n==0 ){ |
| 805 | pServer->atEof = 1; |
| 806 | break; |
| 807 | } |
| 808 | err = SSL_get_error(pServer->ssl, n); |
| 809 | if(0==err){ |
| 810 | rc += n; |
| 811 | pServer->atEof = BIO_eof(pServer->bio); |
| 812 | } |
| 813 | } |
| 814 | return rc; |
| 815 | } |
| 816 | |
| 817 | /* |
| 818 | ** Read a single line of text from the client. |
| 819 | */ |
| 820 |