]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
Roland Blom filed bug report #1481217
authorDaniel Stenberg <daniel@haxx.se>
Thu, 4 May 2006 22:39:47 +0000 (22:39 +0000)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 4 May 2006 22:39:47 +0000 (22:39 +0000)
(http://curl.haxx.se/bug/view.cgi?id=1481217), with follow-ups by Michele Bini
and David Byron. libcurl previously wrongly used GetLastError() on windows to
get error details after socket-related function calls, when it really should
use WSAGetLastError() instead.

When changing to this, the former function Curl_ourerrno() is now instead
called Curl_sockerrno() as it is necessary to only use it to get errno from
socket-related functions as otherwise it won't work as intended on Windows.

18 files changed:
CHANGES
RELEASE-NOTES
lib/connect.c
lib/connect.h
lib/dict.c
lib/file.c
lib/ftp.c
lib/hostares.c
lib/hostasyn.c
lib/hostip.c
lib/hostip6.c
lib/hostsyn.c
lib/http.c
lib/http_negotiate.c
lib/sendf.c
lib/ssluse.c
lib/telnet.c
lib/tftp.c

diff --git a/CHANGES b/CHANGES
index 4154ff20ac5fa12e7186c55b39b72971e04a499a..c4f050072e0c665cc9c804a40895989414774552 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,17 @@
 
                                   Changelog
 
+Daniel (5 May 2006)
+- Roland Blom filed bug report #1481217
+  (http://curl.haxx.se/bug/view.cgi?id=1481217), with follow-ups by Michele
+  Bini and David Byron. libcurl previously wrongly used GetLastError() on
+  windows to get error details after socket-related function calls, when it
+  really should use WSAGetLastError() instead.
+
+  When changing to this, the former function Curl_ourerrno() is now instead
+  called Curl_sockerrno() as it is necessary to only use it to get errno from
+  socket-related functions as otherwise it won't work as intended on Windows.
+
 Daniel (4 May 2006)
 - Mark Eichin submitted bug report #1480821
   (http://curl.haxx.se/bug/view.cgi?id=1480821) He found and identified a
index 1fe83f38c0117acdef210e5ae2f28a9d0a30bbd5..f4f2230d78778248fdce1ceb515497eb23f86a1b 100644 (file)
@@ -20,6 +20,7 @@ This release includes the following changes:
 
 This release includes the following bugfixes:
 
+ o WSAGetLastError() is now used (better) on Windows
  o GnuTLS non-block case that could cause data trashing
  o deflate code survives lack of zlib header
  o CURLOPT_INTERFACE works with hostname
@@ -47,6 +48,6 @@ advice from friends like these:
 
  Dan Fandrich, Ilja van Sprundel, David McCreedy, Tor Arntsen, Xavier Bouchoux,
  David Byron, Michele Bini, Ates Goral, Katie Wang, Robson Braga Araujo,
- Ale Vesely, Paul Querna, Gisle Vanem, Mark Eichin
+ Ale Vesely, Paul Querna, Gisle Vanem, Mark Eichin, Roland Blom
 
         Thanks! (and sorry if I forgot to mention someone)
index b3372f42a58d6499cd708105b7f176b39a11adb6..1ba87099f6bf669c53e04114ad59716b62ae11a0 100644 (file)
@@ -114,13 +114,13 @@ singleipconnect(struct connectdata *conn,
                 bool *connected);
 
 /*
- * Curl_ourerrno() returns the errno (or equivalent) on this platform to
- * hide platform specific for the function that calls this.
+ * Curl_sockerrno() returns the *socket-related* errno (or equivalent) on this
+ * platform to hide platform specific for the function that calls this.
  */
-int Curl_ourerrno(void)
+int Curl_sockerrno(void)
 {
 #ifdef WIN32
-  return (int)GetLastError();
+  return (int)WSAGetLastError();
 #else
   return errno;
 #endif
@@ -330,7 +330,7 @@ static CURLcode bindlocal(struct connectdata *conn,
       if (setsockopt(sockfd, SOL_SOCKET, SO_BINDTODEVICE,
                      data->set.device, strlen(data->set.device)+1) != 0) {
         /* printf("Failed to BINDTODEVICE, socket: %d  device: %s error: %s\n",
-           sockfd, data->set.device, Curl_strerror(Curl_ourerrno())); */
+           sockfd, data->set.device, Curl_strerror(Curl_sockerrno())); */
         infof(data, "SO_BINDTODEVICE %s failed\n",
               data->set.device);
         /* This is typically "errno 1, error: Operation not permitted" if
@@ -408,7 +408,7 @@ static CURLcode bindlocal(struct connectdata *conn,
       break;
   } while(1);
 
-  data->state.os_errno = Curl_ourerrno();
+  data->state.os_errno = Curl_sockerrno();
   failf(data, "bind failure: %s",
         Curl_strerror(conn, data->state.os_errno));
   return CURLE_HTTP_PORT_FAILED;
@@ -452,7 +452,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
 
   if( -1 == getsockopt(sockfd, SOL_SOCKET, SO_ERROR,
                        (void *)&err, &errSize))
-    err = Curl_ourerrno();
+    err = Curl_sockerrno();
 
 #ifdef _WIN32_WCE
   /* Always returns this error, bug in CE? */
@@ -471,7 +471,7 @@ static bool verifyconnect(curl_socket_t sockfd, int *error)
 #else
   (void)sockfd;
   if (error)
-    *error = Curl_ourerrno();
+    *error = Curl_sockerrno();
 #endif
   return rc;
 }
@@ -610,7 +610,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
       infof(data, "Connection failed\n");
 
     if(trynextip(conn, sockindex, connected)) {
-      error = Curl_ourerrno();
+      error = Curl_sockerrno();
       data->state.os_errno = error;
       failf(data, "Failed connect to %s:%d; %s",
             conn->host.name, conn->port, Curl_strerror(conn,error));
@@ -642,7 +642,7 @@ static void tcpnodelay(struct connectdata *conn,
   if(setsockopt(sockfd, proto, TCP_NODELAY, (void *)&onoff,
                 sizeof(onoff)) < 0)
     infof(data, "Could not set TCP_NODELAY: %s\n",
-          Curl_strerror(conn, Curl_ourerrno()));
+          Curl_strerror(conn, Curl_sockerrno()));
   else
     infof(data,"TCP_NODELAY set\n");
 #else
@@ -664,7 +664,7 @@ static void nosigpipe(struct connectdata *conn,
   if(setsockopt(sockfd, SOL_SOCKET, SO_NOSIGPIPE, (void *)&onoff,
                 sizeof(onoff)) < 0)
     infof(data, "Could not set SO_NOSIGPIPE: %s\n",
-          Curl_strerror(conn, Curl_ourerrno()));
+          Curl_strerror(conn, Curl_sockerrno()));
 }
 #else
 #define nosigpipe(x,y)
@@ -717,7 +717,7 @@ singleipconnect(struct connectdata *conn,
     rc = 0;
 
   if(-1 == rc) {
-    error = Curl_ourerrno();
+    error = Curl_sockerrno();
 
     switch (error) {
     case EINPROGRESS:
index 50a9e346400d648251be5ad63f5307a6a3506308..0f593817f9984243e998dea3a9ddbad00e2d195c 100644 (file)
@@ -7,7 +7,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -37,7 +37,7 @@ CURLcode Curl_connecthost(struct connectdata *conn,
                           bool *connected /* truly connected? */
                           );
 
-int Curl_ourerrno(void);
+int Curl_sockerrno(void);
 
 CURLcode Curl_store_ip_addr(struct connectdata *conn);
 
index 1c687292f3695704c2f9fdbca51d82fe29ded67d..b7efa02a1c3d8de39dd3816db4200b3fbea0b912 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -38,8 +38,6 @@
 #include <sys/stat.h>
 #endif
 
-#include <errno.h>
-
 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
 #include <time.h>
 #include <io.h>
index d39b12d435c5a7f4eb28d25994220e01a0872aa4..7415d8a7876a7aeadb0fb34394a013b095241744 100644 (file)
@@ -37,8 +37,6 @@
 #include <sys/stat.h>
 #endif
 
-#include <errno.h>
-
 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
 #include <time.h>
 #include <io.h>
index 9b6ba21546b35112c6010cbaf6508c83978bf56c..8f328ab91c0402e34187d58e67f923a24ad4e584 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -29,7 +29,6 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <ctype.h>
-#include <errno.h>
 
 #ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
 #endif
 
-#if defined(WIN32) && defined(__GNUC__) || defined(__MINGW32__)
-#include <errno.h>
-#endif
-
 #if (defined(NETWARE) && defined(__NOVELL_LIBC__))
 #undef in_addr_t
 #define in_addr_t unsigned long
@@ -492,7 +487,8 @@ CURLcode Curl_GetFTPResponse(ssize_t *nreadp, /* return number of bytes read */
       switch (Curl_select(sockfd, CURL_SOCKET_BAD, interval_ms)) {
       case -1: /* select() error, stop reading */
         result = CURLE_RECV_ERROR;
-        failf(data, "FTP response aborted due to select() error: %d", errno);
+        failf(data, "FTP response aborted due to select() error: %d",
+              Curl_sockerrno());
         break;
       case 0: /* timeout */
         if(Curl_pgrsUpdate(conn))
@@ -871,7 +867,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
 
     portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
     if (portsock == CURL_SOCKET_BAD) {
-      error = Curl_ourerrno();
+      error = Curl_sockerrno();
       continue;
     }
     break;
@@ -903,7 +899,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
       ((struct sockaddr_in6 *)sa)->sin6_port =0;
 
     if(bind(portsock, (struct sockaddr *)sa, sslen) < 0) {
-      failf(data, "bind failed: %s", Curl_strerror(conn, Curl_ourerrno()));
+      failf(data, "bind failed: %s", Curl_strerror(conn, Curl_sockerrno()));
       sclose(portsock);
       return CURLE_FTP_PORT_FAILED;
     }
@@ -914,14 +910,14 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
   sslen = sizeof(ss);
   if(getsockname(portsock, (struct sockaddr *)sa, &sslen)<0) {
     failf(data, "getsockname() failed: %s",
-          Curl_strerror(conn, Curl_ourerrno()) );
+          Curl_strerror(conn, Curl_sockerrno()) );
     return CURLE_FTP_PORT_FAILED;
   }
 
   /* step 4, listen on the socket */
 
   if (listen(portsock, 1) < 0) {
-    error = Curl_ourerrno();
+    error = Curl_sockerrno();
     sclose(portsock);
     failf(data, "socket failure: %s", Curl_strerror(conn, error));
     return CURLE_FTP_PORT_FAILED;
index 6ea6e51d5df7d6bcb0f0f852fd5a91d296c499ff..0f438477ccc0c281b2c516eada5f82b619f6f648 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -24,7 +24,6 @@
 #include "setup.h"
 
 #include <string.h>
-#include <errno.h>
 
 #ifdef HAVE_MALLOC_H  /* Win32 */
 #include <malloc.h>
@@ -208,7 +207,7 @@ CURLcode Curl_wait_for_resolv(struct connectdata *conn,
       break;
     tvp = ares_timeout(data->state.areschannel, &store, &tv);
     count = select(nfds, &read_fds, &write_fds, NULL, tvp);
-    if (count < 0 && errno != EINVAL)
+    if (count < 0 && Curl_sockerrno() != EINVAL)
       break;
 
     ares_process(data->state.areschannel, &read_fds, &write_fds);
index f9e9edbefb79a9531be5ce1d7a055d9dce2b2cce..63d138934a778a0fbcafcf9c8f09755841e0c45d 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -24,7 +24,6 @@
 #include "setup.h"
 
 #include <string.h>
-#include <errno.h>
 
 #ifdef HAVE_MALLOC_H  /* Win32 */
 #include <malloc.h>
index 407c6b2f8927a063ddaed554271f3ede3135fda0..ca08524ea9affa281af0790386b50245dd9c2398 100644 (file)
@@ -24,7 +24,6 @@
 #include "setup.h"
 
 #include <string.h>
-#include <errno.h>
 
 #ifdef HAVE_MALLOC_H  /* Win32 */
 #include <malloc.h>
index 693b98e4c18ccd747f6b56134a726316edacabcd..2168f255fb5d80c0285d1cf6b4ef871d018f20c0 100644 (file)
@@ -24,7 +24,6 @@
 #include "setup.h"
 
 #include <string.h>
-#include <errno.h>
 
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
index 30dc4963a3165b442f7164d798bc26fb6ed853c0..fecde5f63526733da1be08d1263ec571b6cef46a 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -24,7 +24,6 @@
 #include "setup.h"
 
 #include <string.h>
-#include <errno.h>
 
 #ifdef HAVE_MALLOC_H
 #include <malloc.h>
index 5a43f2478620b90cb0e5743ef3d30d3a9e99a2b8..3b6d579772adddbf16b26d36ecca33509f743b3e 100644 (file)
@@ -37,8 +37,6 @@
 #include <sys/stat.h>
 #endif
 
-#include <errno.h>
-
 #if defined(WIN32) && !defined(__GNUC__) || defined(__MINGW32__)
 #include <time.h>
 #include <io.h>
index f407d50904f094c26abac9c471c0dec4286ed0c7..70062f85ae33ca78cc9bc14715834bf8b3dd1fa0 100644 (file)
@@ -5,7 +5,7 @@
  *                            | (__| |_| |  _ <| |___
  *                             \___|\___/|_| \_\_____|
  *
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, Daniel Stenberg, <daniel@haxx.se>, et al.
  *
  * This software is licensed as described in the file COPYING, which
  * you should have received as part of this distribution. The terms
@@ -34,7 +34,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <ctype.h>
-#include <errno.h>
 
 #include "urldata.h"
 #include "sendf.h"
index a9cb583630350c4bf136edcf1f67d07d17bcd35c..c922ce38e6f91b3620dcafd89755d4acf64b5ee7 100644 (file)
@@ -335,7 +335,7 @@ CURLcode Curl_write(struct connectdata *conn,
       bytes_written = (ssize_t)swrite(sockfd, mem, len);
 
     if(-1 == bytes_written) {
-      int err = Curl_ourerrno();
+      int err = Curl_sockerrno();
 
       if(
 #ifdef WSAEWOULDBLOCK
@@ -466,7 +466,7 @@ int Curl_read(struct connectdata *conn, /* connection data */
       nread = sread(sockfd, buf, buffersize);
 
     if(-1 == nread) {
-      int err = Curl_ourerrno();
+      int err = Curl_sockerrno();
 #ifdef WIN32
       if(WSAEWOULDBLOCK == err)
 #else
index 1623f9822c9353d27dee38c195edabcc609bedd8..ce1947bace8310e9061f3b25c17d84e234b3da8e 100644 (file)
@@ -1611,7 +1611,7 @@ Curl_ossl_connect_common(struct connectdata *conn,
         }
         else {
           /* anything that gets here is fatally bad */
-          failf(data, "select on SSL socket, errno: %d", Curl_ourerrno());
+          failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
           return CURLE_SSL_CONNECT_ERROR;
         }
       } /* while()-loop for the select() */
@@ -1691,7 +1691,7 @@ int Curl_ossl_send(struct connectdata *conn,
       return 0;
     case SSL_ERROR_SYSCALL:
       failf(conn->data, "SSL_write() returned SYSCALL, errno = %d\n",
-            Curl_ourerrno());
+            Curl_sockerrno());
       return -1;
     case SSL_ERROR_SSL:
       /*  A failure in the SSL library occurred, usually a protocol error.
@@ -1743,7 +1743,7 @@ ssize_t Curl_ossl_recv(struct connectdata *conn, /* connection data */
       sslerror = ERR_get_error();
       failf(conn->data, "SSL read: %s, errno %d",
             ERR_error_string(sslerror, error_buffer),
-            Curl_ourerrno() );
+            Curl_sockerrno() );
       return -1;
     }
   }
index 2384dda5b9cccd40a62ab685d9cb5776a961ddfd..a609cd09231718c4d6fa2592809730ef66a422ad 100644 (file)
@@ -36,7 +36,6 @@
 #ifdef HAVE_SYS_STAT_H
 #include <sys/stat.h>
 #endif
-#include <errno.h>
 
 #if defined(WIN32)
 #include <time.h>
index 9c459a975b1800fa685332643d1a97d435eab908..d8a23b0360c3ca896ac3bd6d555c3cbbd59992bd 100644 (file)
@@ -582,7 +582,7 @@ CURLcode Curl_tftp_connect(struct connectdata *conn, bool *done)
             conn->ip_addr->ai_addrlen);
   if(rc) {
     failf(conn->data, "bind() failed; %s\n",
-          Curl_strerror(conn,Curl_ourerrno()));
+          Curl_strerror(conn, Curl_sockerrno()));
     return CURLE_COULDNT_CONNECT;
   }
 
@@ -645,7 +645,7 @@ CURLcode Curl_tftp(struct connectdata *conn, bool *done)
 
     if(rc == -1) {
       /* bail out */
-      int error = Curl_ourerrno();
+      int error = Curl_sockerrno();
       failf(data, "%s\n", Curl_strerror(conn, error));
       event = TFTP_EVENT_ERROR;
     }