Module: wine Branch: master Commit: 5fc17a280046346627661e17903d2cea473e7139 URL: http://source.winehq.org/git/wine.git/?a=commit;h=5fc17a280046346627661e1790...
Author: Hans Leidekker hans@codeweavers.com Date: Tue Jul 20 14:50:19 2010 +0200
winhttp: Handle errors from SSL_read.
---
dlls/winhttp/net.c | 24 +++++++++++++++++++----- dlls/winhttp/tests/winhttp.c | 8 ++++++++ 2 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/dlls/winhttp/net.c b/dlls/winhttp/net.c index ab7a4a7..e60bd16 100644 --- a/dlls/winhttp/net.c +++ b/dlls/winhttp/net.c @@ -111,6 +111,7 @@ MAKE_FUNCPTR( SSL_connect ); MAKE_FUNCPTR( SSL_shutdown ); MAKE_FUNCPTR( SSL_write ); MAKE_FUNCPTR( SSL_read ); +MAKE_FUNCPTR( SSL_get_error ); MAKE_FUNCPTR( SSL_get_ex_new_index ); MAKE_FUNCPTR( SSL_get_ex_data ); MAKE_FUNCPTR( SSL_set_ex_data ); @@ -440,6 +441,7 @@ BOOL netconn_init( netconn_t *conn, BOOL secure ) LOAD_FUNCPTR( SSL_shutdown ); LOAD_FUNCPTR( SSL_write ); LOAD_FUNCPTR( SSL_read ); + LOAD_FUNCPTR( SSL_get_error ); LOAD_FUNCPTR( SSL_get_ex_new_index ); LOAD_FUNCPTR( SSL_get_ex_data ); LOAD_FUNCPTR( SSL_set_ex_data ); @@ -713,6 +715,8 @@ BOOL netconn_send( netconn_t *conn, const void *msg, size_t len, int flags, int
BOOL netconn_recv( netconn_t *conn, void *buf, size_t len, int flags, int *recvd ) { + int ret; + *recvd = 0; if (!netconn_connected( conn )) return FALSE; if (!len) return TRUE; @@ -751,19 +755,29 @@ BOOL netconn_recv( netconn_t *conn, void *buf, size_t len, int flags, int *recvd /* check if we have enough data from the peek buffer */ if (!(flags & MSG_WAITALL) || (*recvd == len)) return TRUE; } - *recvd += pSSL_read( conn->ssl_conn, (char *)buf + *recvd, len - *recvd ); + ret = pSSL_read( conn->ssl_conn, (char *)buf + *recvd, len - *recvd ); + if (ret < 0) + return FALSE; + + /* check if EOF was received */ + if (!ret && (pSSL_get_error( conn->ssl_conn, ret ) == SSL_ERROR_ZERO_RETURN || + pSSL_get_error( conn->ssl_conn, ret ) == SSL_ERROR_SYSCALL )) + { + netconn_close( conn ); + return TRUE; + } if (flags & MSG_PEEK) /* must copy into buffer */ { - conn->peek_len = *recvd; - if (!*recvd) + conn->peek_len = ret; + if (!ret) { heap_free( conn->peek_msg_mem ); conn->peek_msg_mem = NULL; conn->peek_msg = NULL; } - else memcpy( conn->peek_msg, buf, *recvd ); + else memcpy( conn->peek_msg, buf, ret ); } - if (*recvd < 1) return FALSE; + *recvd = ret; return TRUE; #else return FALSE; diff --git a/dlls/winhttp/tests/winhttp.c b/dlls/winhttp/tests/winhttp.c index 21cc501..3c725cf 100644 --- a/dlls/winhttp/tests/winhttp.c +++ b/dlls/winhttp/tests/winhttp.c @@ -771,6 +771,7 @@ static void test_secure_connection(void) BOOL ret; CERT_CONTEXT *cert; WINHTTP_CERTIFICATE_INFO info; + char buffer[32];
ses = WinHttpOpen(test_useragent, 0, NULL, NULL, 0); ok(ses != NULL, "failed to open session %u\n", GetLastError()); @@ -847,6 +848,13 @@ static void test_secure_connection(void) ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, NULL, &size, NULL); ok(!ret, "succeeded unexpectedly\n");
+ for (;;) + { + size = 0; + ret = WinHttpReadData(req, buffer, sizeof(buffer), &size); + if (!size) break; + } + cleanup: WinHttpCloseHandle(req); WinHttpCloseHandle(con);