Fossil SCM
Replaced the "manual" TLS EOF tracking with BIO_eof(), analog to how is done in althttpd.
Commit
06e300e5bd325792a9a1995a8c6a8feb0f42268c9672ab8cf93fdcbb480222ec
Parent
1cb182ac18de0bb…
1 file changed
+5
-8
+5
-8
| --- src/http_ssl.c | ||
| +++ src/http_ssl.c | ||
| @@ -770,11 +770,10 @@ | ||
| 770 | 770 | } |
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | typedef struct SslServerConn { |
| 774 | 774 | SSL *ssl; /* The SSL codec */ |
| 775 | - int atEof; /* True when EOF reached. */ | |
| 776 | 775 | int iSocket; /* The socket */ |
| 777 | 776 | BIO *bio; /* BIO object. Needed for EOF detection. */ |
| 778 | 777 | } SslServerConn; |
| 779 | 778 | |
| 780 | 779 | /* |
| @@ -784,11 +783,10 @@ | ||
| 784 | 783 | */ |
| 785 | 784 | void *ssl_new_server(int iSocket){ |
| 786 | 785 | SslServerConn *pServer = fossil_malloc_zero(sizeof(*pServer)); |
| 787 | 786 | BIO *b = BIO_new_socket(iSocket, 0); |
| 788 | 787 | pServer->ssl = SSL_new(sslCtx); |
| 789 | - pServer->atEof = 0; | |
| 790 | 788 | pServer->iSocket = iSocket; |
| 791 | 789 | pServer->bio = b; |
| 792 | 790 | SSL_set_bio(pServer->ssl, b, b); |
| 793 | 791 | SSL_accept(pServer->ssl); |
| 794 | 792 | return (void*)pServer; |
| @@ -807,11 +805,11 @@ | ||
| 807 | 805 | ** Return TRUE if there are no more bytes available to be read from |
| 808 | 806 | ** the client. |
| 809 | 807 | */ |
| 810 | 808 | int ssl_eof(void *pServerArg){ |
| 811 | 809 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 812 | - return pServer->atEof; | |
| 810 | + return BIO_eof(pServer->bio); | |
| 813 | 811 | } |
| 814 | 812 | |
| 815 | 813 | /* |
| 816 | 814 | ** Read cleartext bytes that have been received from the client and |
| 817 | 815 | ** decrypted by the SSL server codec. |
| @@ -819,20 +817,19 @@ | ||
| 819 | 817 | size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){ |
| 820 | 818 | int n, err = 0; |
| 821 | 819 | size_t rc = 0; |
| 822 | 820 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 823 | 821 | 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 ){ | |
| 825 | 824 | n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc)); |
| 826 | 825 | if( n==0 ){ |
| 827 | - pServer->atEof = 1; | |
| 828 | 826 | break; |
| 829 | 827 | } |
| 830 | 828 | err = SSL_get_error(pServer->ssl, n); |
| 831 | 829 | if(0==err){ |
| 832 | 830 | rc += n; |
| 833 | - pServer->atEof = BIO_eof(pServer->bio); | |
| 834 | 831 | }else{ |
| 835 | 832 | fossil_fatal("SSL read error."); |
| 836 | 833 | } |
| 837 | 834 | } |
| 838 | 835 | return rc; |
| @@ -843,12 +840,12 @@ | ||
| 843 | 840 | */ |
| 844 | 841 | char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){ |
| 845 | 842 | int n = 0; |
| 846 | 843 | int i; |
| 847 | 844 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 848 | - | |
| 849 | - if( pServer->atEof ) return 0; | |
| 845 | + | |
| 846 | + if( BIO_eof(pServer->bio) ) return 0; | |
| 850 | 847 | for(i=0; i<nBuf-1; i++){ |
| 851 | 848 | n = SSL_read(pServer->ssl, &zBuf[i], 1); |
| 852 | 849 | if( n<=0 ){ |
| 853 | 850 | return 0; |
| 854 | 851 | } |
| 855 | 852 |
| --- 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 |