Fossil SCM

Cherrypicked [5fd1ca6f] (was checked in to wrong branch).

stephan 2022-01-15 13:58 trunk
Commit 8d456a5b772edadd2adefaad8da9d6c03758bce0d5b21fe75ef1fffc901f0e44
1 file changed +17 -5
+17 -5
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -750,10 +750,11 @@
750750
751751
typedef struct SslServerConn {
752752
SSL *ssl; /* The SSL codec */
753753
int atEof; /* True when EOF reached. */
754754
int iSocket; /* The socket */
755
+ BIO *bio; /* BIO object. Needed for EOF detection. */
755756
} SslServerConn;
756757
757758
/*
758759
** Create a new server-side codec. The argument is the socket's file
759760
** descriptor from which the codec reads and writes. The returned
@@ -763,10 +764,11 @@
763764
SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
764765
BIO *b = BIO_new_socket(iSocket, 0);
765766
pServer->ssl = SSL_new(sslCtx);
766767
pServer->atEof = 0;
767768
pServer->iSocket = iSocket;
769
+ pServer->bio = b;
768770
SSL_set_bio(pServer->ssl, b, b);
769771
SSL_accept(pServer->ssl);
770772
return (void*)pServer;
771773
}
772774
@@ -791,17 +793,27 @@
791793
/*
792794
** Read cleartext bytes that have been received from the client and
793795
** decrypted by the SSL server codec.
794796
*/
795797
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;
797800
SslServerConn *pServer = (SslServerConn*)pServerArg;
798
- if( pServer->atEof ) return 0;
799801
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;
803815
}
804816
805817
/*
806818
** Read a single line of text from the client.
807819
*/
808820
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button