Fossil SCM

Replaced the "manual" TLS EOF tracking with BIO_eof(), analog to how is done in althttpd.

stephan 2022-01-24 06:54 trunk
Commit 06e300e5bd325792a9a1995a8c6a8feb0f42268c9672ab8cf93fdcbb480222ec
1 file changed +5 -8
+5 -8
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770770
}
771771
}
772772
773773
typedef struct SslServerConn {
774774
SSL *ssl; /* The SSL codec */
775
- int atEof; /* True when EOF reached. */
776775
int iSocket; /* The socket */
777776
BIO *bio; /* BIO object. Needed for EOF detection. */
778777
} SslServerConn;
779778
780779
/*
@@ -784,11 +783,10 @@
784783
*/
785784
void *ssl_new_server(int iSocket){
786785
SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
787786
BIO *b = BIO_new_socket(iSocket, 0);
788787
pServer->ssl = SSL_new(sslCtx);
789
- pServer->atEof = 0;
790788
pServer->iSocket = iSocket;
791789
pServer->bio = b;
792790
SSL_set_bio(pServer->ssl, b, b);
793791
SSL_accept(pServer->ssl);
794792
return (void*)pServer;
@@ -807,11 +805,11 @@
807805
** Return TRUE if there are no more bytes available to be read from
808806
** the client.
809807
*/
810808
int ssl_eof(void *pServerArg){
811809
SslServerConn *pServer = (SslServerConn*)pServerArg;
812
- return pServer->atEof;
810
+ return BIO_eof(pServer->bio);
813811
}
814812
815813
/*
816814
** Read cleartext bytes that have been received from the client and
817815
** decrypted by the SSL server codec.
@@ -819,20 +817,19 @@
819817
size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){
820818
int n, err = 0;
821819
size_t rc = 0;
822820
SslServerConn *pServer = (SslServerConn*)pServerArg;
823821
if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
824
- while( 0==err && nBuf!=rc && 0==pServer->atEof ){
822
+ else if( BIO_eof(pServer->bio) ) return 0;
823
+ while( 0==err && nBuf!=rc ){
825824
n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
826825
if( n==0 ){
827
- pServer->atEof = 1;
828826
break;
829827
}
830828
err = SSL_get_error(pServer->ssl, n);
831829
if(0==err){
832830
rc += n;
833
- pServer->atEof = BIO_eof(pServer->bio);
834831
}else{
835832
fossil_fatal("SSL read error.");
836833
}
837834
}
838835
return rc;
@@ -843,12 +840,12 @@
843840
*/
844841
char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
845842
int n = 0;
846843
int i;
847844
SslServerConn *pServer = (SslServerConn*)pServerArg;
848
-
849
- if( pServer->atEof ) return 0;
845
+
846
+ if( BIO_eof(pServer->bio) ) return 0;
850847
for(i=0; i<nBuf-1; i++){
851848
n = SSL_read(pServer->ssl, &zBuf[i], 1);
852849
if( n<=0 ){
853850
return 0;
854851
}
855852
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770 }
771 }
772
773 typedef struct SslServerConn {
774 SSL *ssl; /* The SSL codec */
775 int atEof; /* True when EOF reached. */
776 int iSocket; /* The socket */
777 BIO *bio; /* BIO object. Needed for EOF detection. */
778 } SslServerConn;
779
780 /*
@@ -784,11 +783,10 @@
784 */
785 void *ssl_new_server(int iSocket){
786 SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
787 BIO *b = BIO_new_socket(iSocket, 0);
788 pServer->ssl = SSL_new(sslCtx);
789 pServer->atEof = 0;
790 pServer->iSocket = iSocket;
791 pServer->bio = b;
792 SSL_set_bio(pServer->ssl, b, b);
793 SSL_accept(pServer->ssl);
794 return (void*)pServer;
@@ -807,11 +805,11 @@
807 ** Return TRUE if there are no more bytes available to be read from
808 ** the client.
809 */
810 int ssl_eof(void *pServerArg){
811 SslServerConn *pServer = (SslServerConn*)pServerArg;
812 return pServer->atEof;
813 }
814
815 /*
816 ** Read cleartext bytes that have been received from the client and
817 ** decrypted by the SSL server codec.
@@ -819,20 +817,19 @@
819 size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){
820 int n, err = 0;
821 size_t rc = 0;
822 SslServerConn *pServer = (SslServerConn*)pServerArg;
823 if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
824 while( 0==err && nBuf!=rc && 0==pServer->atEof ){
 
825 n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
826 if( n==0 ){
827 pServer->atEof = 1;
828 break;
829 }
830 err = SSL_get_error(pServer->ssl, n);
831 if(0==err){
832 rc += n;
833 pServer->atEof = BIO_eof(pServer->bio);
834 }else{
835 fossil_fatal("SSL read error.");
836 }
837 }
838 return rc;
@@ -843,12 +840,12 @@
843 */
844 char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
845 int n = 0;
846 int i;
847 SslServerConn *pServer = (SslServerConn*)pServerArg;
848
849 if( pServer->atEof ) return 0;
850 for(i=0; i<nBuf-1; i++){
851 n = SSL_read(pServer->ssl, &zBuf[i], 1);
852 if( n<=0 ){
853 return 0;
854 }
855
--- src/http_ssl.c
+++ src/http_ssl.c
@@ -770,11 +770,10 @@
770 }
771 }
772
773 typedef struct SslServerConn {
774 SSL *ssl; /* The SSL codec */
 
775 int iSocket; /* The socket */
776 BIO *bio; /* BIO object. Needed for EOF detection. */
777 } SslServerConn;
778
779 /*
@@ -784,11 +783,10 @@
783 */
784 void *ssl_new_server(int iSocket){
785 SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer));
786 BIO *b = BIO_new_socket(iSocket, 0);
787 pServer->ssl = SSL_new(sslCtx);
 
788 pServer->iSocket = iSocket;
789 pServer->bio = b;
790 SSL_set_bio(pServer->ssl, b, b);
791 SSL_accept(pServer->ssl);
792 return (void*)pServer;
@@ -807,11 +805,11 @@
805 ** Return TRUE if there are no more bytes available to be read from
806 ** the client.
807 */
808 int ssl_eof(void *pServerArg){
809 SslServerConn *pServer = (SslServerConn*)pServerArg;
810 return BIO_eof(pServer->bio);
811 }
812
813 /*
814 ** Read cleartext bytes that have been received from the client and
815 ** decrypted by the SSL server codec.
@@ -819,20 +817,19 @@
817 size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){
818 int n, err = 0;
819 size_t rc = 0;
820 SslServerConn *pServer = (SslServerConn*)pServerArg;
821 if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); }
822 else if( BIO_eof(pServer->bio) ) return 0;
823 while( 0==err && nBuf!=rc ){
824 n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc));
825 if( n==0 ){
 
826 break;
827 }
828 err = SSL_get_error(pServer->ssl, n);
829 if(0==err){
830 rc += n;
 
831 }else{
832 fossil_fatal("SSL read error.");
833 }
834 }
835 return rc;
@@ -843,12 +840,12 @@
840 */
841 char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){
842 int n = 0;
843 int i;
844 SslServerConn *pServer = (SslServerConn*)pServerArg;
845
846 if( BIO_eof(pServer->bio) ) return 0;
847 for(i=0; i<nBuf-1; i++){
848 n = SSL_read(pServer->ssl, &zBuf[i], 1);
849 if( n<=0 ){
850 return 0;
851 }
852

Keyboard Shortcuts

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