You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Johan Lindh <jo...@linkdata.se> on 2002/12/23 14:39:10 UTC

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

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

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

Posted by Joe Orton <jo...@manyfish.co.uk>.
On Mon, Dec 23, 2002 at 06:59:44PM +0100, Johan Lindh wrote:
> >Thanks Johan. I took that, cleaned it up a bit, and extended it to map
> >the return values properly.  Does the attached patch still work?
> 
> Um, without actually testing it... from reading the code, it seems like
> set_strerror() will not now return an error message if the return value
> from WSAGetLastError() is unknown. 

That's right, set_strerror doesn't return anything.

> More importantly, if ne_snprintf() takes a char * as it's first argument,
> then you're bashing the ne_socket structure with that call.
> 
> Perhaps ne_snprintf( s->error, ..... ) was intended?

Good point - thanks.  Updated patch attached.

joe

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

Posted by Johan Lindh <jo...@linkdata.se>.
>Thanks Johan. I took that, cleaned it up a bit, and extended it to map
>the return values properly.  Does the attached patch still work?

Um, without actually testing it... from reading the code, it seems like
set_strerror() will not now return an error message if the return value
from WSAGetLastError() is unknown. 

More importantly, if ne_snprintf() takes a char * as it's first argument,
then you're bashing the ne_socket structure with that call.

Perhaps ne_snprintf( s->error, ..... ) was intended?


/J



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

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

Posted by Joe Orton <jo...@manyfish.co.uk>.
On Mon, Dec 23, 2002 at 03:39:10PM +0100, Johan Lindh wrote:
> 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.

Thanks Johan. I took that, cleaned it up a bit, and extended it to map
the return values properly.  Does the attached patch still work?

Brandon, can you apply the attached patch (and undo the buffer size
change) then recompile neon/SVN and try your merge failure case? What
error message do you get now?

Regards,

joe