WSAStartup16

Francois Gouget fgouget at free.fr
Fri Aug 24 10:38:02 CDT 2001


   WSAStartup16 seems wrong.
   As I understand it all the Win16 structures have a 1 byte alignment.
Thus the WSASTARTUP structure used by WSAStartup16 should have a 1 byte
alignment. But WSAStartup16 uses the Win32 structure! Why is this
important? Here's why:
 - the last field, lpVendorInfo, will be misaligned
 - the structure will be larger than it should (by 2 bytes). And since
we do a memcpy of sizeof(WSADATA) to the pointer provided by the
application we could have a buffer overflow
 - this creates a dependency between winsock16.h and winsock.h which
greatly bothers me

   Or did I miss something?


Changelog:

 * include/wine/winsock16.h,
   dlls/winsock/socket.c

   Add WSASTARTUP16 a 1 byte alignment version of WSASTARTUP for win16



--
Francois Gouget         fgouget at free.fr        http://fgouget.free.fr/
  Any sufficiently advanced Operating System is indistinguishable from Linux
-------------- next part --------------
Index: include/wine/winsock16.h
===================================================================
RCS file: /home/wine/wine/include/wine/winsock16.h,v
retrieving revision 1.2
diff -u -r1.2 winsock16.h
--- include/wine/winsock16.h	2000/09/26 22:20:53	1.2
+++ include/wine/winsock16.h	2001/08/24 13:29:46
@@ -46,6 +46,17 @@
         INT     n_net;          /* network # */
 } _ws_netent16;
 
+typedef struct WSAData16
+{
+    WORD                    wVersion;
+    WORD                    wHighVersion;
+    char                    szDescription[WSADESCRIPTION_LEN+1];
+    char                    szSystemStatus[WSASYS_STATUS_LEN+1];
+    WORD                    iMaxSockets;
+    WORD                    iMaxUdpDg;
+    char                   *lpVendorInfo;
+} WSADATA16, *LPWSADATA16;
+
 #include "poppack.h"
 
 #define WS_FD_CLR16(fd, set)   __WS_FD_CLR((fd),(set), ws_fd_set16)
@@ -56,7 +67,7 @@
 #define INVALID_SOCKET16  ((SOCKET16)(~0))
 
 INT16     WINAPI __WSAFDIsSet16( SOCKET16, ws_fd_set16 * );
-INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA lpWSAData);
+INT16     WINAPI WSAStartup16(UINT16 wVersionRequired, LPWSADATA16 lpWSAData);
 void      WINAPI WSASetLastError16(INT16 iError);
 INT16     WINAPI WSAUnhookBlockingHook16(void);
 FARPROC16 WINAPI WSASetBlockingHook16(FARPROC16 lpBlockFunc);
Index: dlls/winsock/socket.c
===================================================================
RCS file: /home/wine/wine/dlls/winsock/socket.c,v
retrieving revision 1.57
diff -u -r1.57 socket.c
--- dlls/winsock/socket.c	2001/08/23 23:25:33	1.57
+++ dlls/winsock/socket.c	2001/08/24 13:29:43
@@ -530,9 +533,9 @@
  * Create socket control struct, attach it to the global list and
  * update a pointer in the task struct.
  */
-INT16 WINAPI WSAStartup16(UINT16 wVersionRequested, LPWSADATA lpWSAData)
+INT16 WINAPI WSAStartup16(UINT16 wVersionRequested, LPWSADATA16 lpWSAData)
 {
-    WSADATA WINSOCK_data = { 0x0101, 0x0101,
+    WSADATA16 WINSOCK_data = { 0x0101, 0x0101,
                           "WINE Sockets 1.1",
                         #ifdef linux
                                 "Linux/i386",


More information about the wine-devel mailing list