| | @@ -811,37 +811,41 @@ |
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | /* |
| 814 | 814 | ** Read cleartext bytes that have been received from the client and |
| 815 | 815 | ** decrypted by the SSL server codec. |
| 816 | +** |
| 817 | +** If the expected payload size unknown, i.e. if the HTTP |
| 818 | +** Content-Length: header field has not been parsed, the doLoop |
| 819 | +** argument should be 0, or SSL_read() may block and wait for more |
| 820 | +** data than is eventually going to arrive (on Windows). On |
| 821 | +** non-Windows builds, it has been our experience that the final |
| 822 | +** argument must always be true, as discussed at length at: |
| 823 | +** |
| 824 | +** https://fossil-scm.org/forum/forumpost/2f818850abb72719 |
| 816 | 825 | */ |
| 817 | | -size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf){ |
| 826 | +size_t ssl_read_server(void *pServerArg, char *zBuf, size_t nBuf, int doLoop){ |
| 818 | 827 | int n; |
| 819 | 828 | size_t rc = 0; |
| 820 | 829 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 821 | 830 | if( nBuf>0x7fffffff ){ fossil_fatal("SSL read too big"); } |
| 822 | | - else if( BIO_eof(pServer->bio) ) return 0; |
| 823 | | - while( nBuf!=rc ){ |
| 831 | + while( nBuf!=rc && BIO_eof(pServer->bio)==0 ){ |
| 824 | 832 | n = SSL_read(pServer->ssl, zBuf + rc, (int)(nBuf - rc)); |
| 825 | | - if( n<=0 ){ |
| 826 | | - break; |
| 827 | | - }else if(n>0){ |
| 833 | + if( n>0 ){ |
| 828 | 834 | rc += n; |
| 829 | 835 | } |
| 830 | | -#ifdef _WIN32 |
| 831 | | - /* Windows (XP and 10 tested with openssl 1.1.1m and 3.0.1) does |
| 832 | | - ** not require reading in a loop, returning all data in a single |
| 833 | | - ** call. If we read in a loop on Windows, SSL reads fail. Details: |
| 834 | | - ** https://fossil-scm.org/forum/forumpost/2f818850abb72719 */ |
| 835 | | - break; |
| 836 | | -#endif |
| 836 | + if( doLoop==0 || n<=0 ){ |
| 837 | + break; |
| 838 | + } |
| 837 | 839 | } |
| 838 | 840 | return rc; |
| 839 | 841 | } |
| 840 | 842 | |
| 841 | 843 | /* |
| 842 | | -** Read a single line of text from the client. |
| 844 | +** Read a single line of text from the client, up to nBuf-1 bytes. On |
| 845 | +** success, writes nBuf-1 bytes to zBuf and NUL-terminates zBuf. |
| 846 | +** Returns NULL on an I/O error or at EOF. |
| 843 | 847 | */ |
| 844 | 848 | char *ssl_gets(void *pServerArg, char *zBuf, int nBuf){ |
| 845 | 849 | int n = 0; |
| 846 | 850 | int i; |
| 847 | 851 | SslServerConn *pServer = (SslServerConn*)pServerArg; |
| 848 | 852 | |