From 163a1dca5fc708f99db9e6a67d368e29f90e345e Mon Sep 17 00:00:00 2001 From: Nick Zitzmann Date: Mon, 28 Jan 2013 19:34:35 -0700 Subject: darwinssl: Fix bug where packets were sometimes transmitted twice There was a bug where, if SSLWrite() returned errSSLWouldBlock but did succeed in transmitting at least something, then we'd incorrectly resend the packet. Now we never take errSSLWouldBlock as a sign that nothing was transferred to/from the server. Bug: http://curl.haxx.se/mail/lib-2013-01/0295.html Reported by: Bruno de Carvalho --- lib/curl_darwinssl.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/curl_darwinssl.c b/lib/curl_darwinssl.c index e8fa2758b..827c876e0 100644 --- a/lib/curl_darwinssl.c +++ b/lib/curl_darwinssl.c @@ -5,8 +5,8 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 2012, Nick Zitzmann, . - * Copyright (C) 2012, Daniel Stenberg, , et al. + * Copyright (C) 2012-2013, Nick Zitzmann, . + * Copyright (C) 2012-2013, Daniel Stenberg, , et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -1383,12 +1383,14 @@ static ssize_t darwinssl_send(struct connectdata *conn, { /*struct SessionHandle *data = conn->data;*/ struct ssl_connect_data *connssl = &conn->ssl[sockindex]; - size_t processed; + size_t processed = 0UL; OSStatus err = SSLWrite(connssl->ssl_ctx, mem, len, &processed); if(err != noErr) { switch (err) { - case errSSLWouldBlock: /* we're not done yet; keep sending */ + case errSSLWouldBlock: /* return how much we sent (if anything) */ + if(processed) + return (ssize_t)processed; *curlcode = CURLE_AGAIN; return -1; break; @@ -1411,12 +1413,14 @@ static ssize_t darwinssl_recv(struct connectdata *conn, { /*struct SessionHandle *data = conn->data;*/ struct ssl_connect_data *connssl = &conn->ssl[num]; - size_t processed; + size_t processed = 0UL; OSStatus err = SSLRead(connssl->ssl_ctx, buf, buffersize, &processed); if(err != noErr) { switch (err) { - case errSSLWouldBlock: /* we're not done yet; keep reading */ + case errSSLWouldBlock: /* return how much we read (if anything) */ + if(processed) + return (ssize_t)processed; *curlcode = CURLE_AGAIN; return -1; break; -- cgit v1.2.3