ws2_32: Convert the magic loopback address back to 127.0.0.1 in gethostbyaddr
Bruno Jesus
00cpxxx at gmail.com
Thu Apr 17 18:45:47 CDT 2014
The patch avoids changing the const user memory. Also a minor style
revision to match the rest of the file.
Fixes bug http://bugs.winehq.org/show_bug.cgi?id=36015
-------------- next part --------------
diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 54e7e2f..2959b58 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -5085,28 +5085,39 @@ struct WS_hostent* WINAPI WS_gethostbyaddr(const char *addr, int len, int type)
struct WS_hostent *retval = NULL;
struct hostent* host;
int unixtype = convert_af_w2u(type);
-
+ char *paddr = (char*) addr;
+ unsigned long loopback;
#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
char *extrabuf;
- int ebufsize=1024;
+ int ebufsize = 1024;
struct hostent hostentry;
- int locerr=ENOBUFS;
+ int locerr = ENOBUFS;
+#endif
+
+ /* convert back the magic loopback address if necessary */
+ if (unixtype == AF_INET && len == 4 && !memcmp(addr, magic_loopback_addr, 4))
+ {
+ loopback = htonl(INADDR_LOOPBACK);
+ paddr = (char*) &loopback;
+ }
+
+#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
host = NULL;
extrabuf=HeapAlloc(GetProcessHeap(),0,ebufsize) ;
while(extrabuf) {
- int res = gethostbyaddr_r(addr, len, unixtype,
+ int res = gethostbyaddr_r(paddr, len, unixtype,
&hostentry, extrabuf, ebufsize, &host, &locerr);
- if( res != ERANGE) break;
+ if (res != ERANGE) break;
ebufsize *=2;
extrabuf=HeapReAlloc(GetProcessHeap(),0,extrabuf,ebufsize) ;
}
if (!host) SetLastError((locerr < 0) ? wsaErrno() : wsaHerrno(locerr));
#else
EnterCriticalSection( &csWSgetXXXbyYYY );
- host = gethostbyaddr(addr, len, unixtype);
+ host = gethostbyaddr(paddr, len, unixtype);
if (!host) SetLastError((h_errno < 0) ? wsaErrno() : wsaHerrno(h_errno));
#endif
- if( host != NULL ) retval = WS_dup_he(host);
+ if (host != NULL) retval = WS_dup_he(host);
#ifdef HAVE_LINUX_GETHOSTBYNAME_R_6
HeapFree(GetProcessHeap(),0,extrabuf);
#else
More information about the wine-patches
mailing list