[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [neon] Re: [azverkan@yahoo.com: Joe Orton please read: Overrrun a neon buffer size during svn merge URL URL]

From: Johan Lindh <johan_at_linkdata.se>
Date: 2002-12-23 15:39:10 CET

On 2002-12-23 at 00:39 Joe Orton wrote:
>The code in question is all inside neon's socket abstraction,
>ne_socket.[ch] - only read_raw/write_raw/readable_raw should need
>changing, it should be pretty clear what needs to be done.

Unfortunately, ./configure from neon cvs bombs on my machine, so I couldn't test this properly.
But anyway, here's a diff that at least does the minimum. That is, changes set_strerror() to
a) write the Win32 error message and b) change the value of errno to something more reasonable.

As is, the patch will not affect the return values in a consistent way, though, just the error message.
If the read_raw() and others would call set_strerror() -before- checking the value of errno, the
return value should get meaningful values on Win32 too.

/J

--- ne_socket.c.org Mon Dec 23 15:18:01 2002
+++ ne_socket.c Mon Dec 23 15:26:02 2002
@@ -52,6 +52,23 @@
 #ifdef WIN32
 #include <winsock2.h>
 #include <stddef.h>
+#include <errno.h>
+#if !defined(ECONNRESET)
+#define ECONNRESET WSAECONNRESET
+#endif
+#if !defined(EINTR)
+#define EINTR WSAEINTR
+#endif
+#if !defined(EFAULT)
+#define EFAULT WSAEFAULT
+#endif
+#if !defined(ENETDOWN)
+#define ENETDOWN WSAENETDOWN
+#endif
+#if !defined(ENOTCONN)
+#define ENOTCONN WSAENOTCONN
+#endif
+static const char* ne_win32_map_errno(void);
 #else
 #include <netinet/in.h>
 #include <netdb.h>
@@ -181,7 +198,39 @@
 #define set_error(s, str) ne_strnzcpy((s)->error, (str), sizeof (s)->error)
 
 /* set_strerror: set socket error to system error string for 'e' */
+#ifdef WIN32
+static const char* ne_win32_map_errno(void)
+{
+ switch( WSAGetLastError() )
+ {
+ case WSANOTINITIALISED: errno=ENOENT; return "A successful WSAStartup call must occur before using this function.";
+ case WSAENETDOWN: errno=ENETDOWN; return "The network subsystem has failed.";
+ case WSAEFAULT: errno=EFAULT; return "Referenced data outside the process address space";
+ case WSAENOTCONN: errno=ENOTCONN; return "The socket is not connected.";
+ case WSAEINTR: errno=EINTR; return "Call was interrupted.";
+ case WSAEINPROGRESS: errno=EINTR; return "A blocking call is in progess.";
+ case WSAENETRESET: errno=ECONNRESET; return "The connection was reset during keep-alive activity.";
+ case WSAENOTSOCK: errno=EBADF; return "The descriptor is not a socket.";
+ case WSAEOPNOTSUPP: errno=EINVAL; return "Operation not supported for this socket type.";
+ case WSAESHUTDOWN: errno=ENOTCONN; return "The socket has been shut down.";
+ case WSAEWOULDBLOCK: errno=EAGAIN; return "The socket is marked as nonblocking and the receive operation would block.";
+ case WSAEMSGSIZE: errno=EINVAL; return "The message was too large to fit into the specified buffer and was truncated.";
+ case WSAEINVAL: errno=EINVAL; return "The socket has not been bound with bind, or an unknown/unsupported flag/operation was specified.";
+ case WSAECONNABORTED: errno=ECONNRESET; return "The virtual circuit was terminated due to a time-out or other failure.";
+ case WSAETIMEDOUT: errno=EAGAIN; return "The connection has been dropped because of a network failure or because the peer system failed to respond.";
+ case WSAECONNRESET: errno=ECONNRESET; return "The virtual circuit was reset by the remote side executing a hard or abortive close.";
+ default: break;
+ }
+ return strerror(errno);
+}
+static void set_strerror(ne_socket *s, int e)
+{
+ strncpy( s->error, ne_win32_map_errno(), sizeof( s->error ) );
+ s->error[ sizeof( s->error ) - 1 ] = 0;
+}
+#else
 #define set_strerror(s, e) ne_strerror((e), (s)->error, sizeof (s)->error)
+#endif
 
 #ifdef NEON_SSL
 static int prng_seeded = 0;

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Dec 23 15:43:13 2002

This is an archived mail posted to the Subversion Dev mailing list.