windows library: Mainly add socket functions, some other stuff and tests. (#1095)

Add Windows Socket 2 type/function configuration. There are still many
(microsoft specific) socket functions that are not yet configured.
Add configuration for GetUserName(), GetWindowText() and _fileno().
On Windows __wchar_t is a synonym for wchar_t, so an according define is
added.
This commit is contained in:
Sebastian 2018-02-23 12:51:37 +01:00 committed by GitHub
parent 211b5ba9fb
commit 346704b2e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 594 additions and 0 deletions

View File

@ -787,6 +787,12 @@
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="u_char" value="char">
<unsigned/>
<platform type="win32A"/>
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="UHALF_PTR" value="short">
<unsigned/>
<platform type="win32A"/>
@ -802,6 +808,12 @@
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="u_int" value="int">
<unsigned/>
<platform type="win32A"/>
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="UINT8" value="char">
<unsigned/>
<platform type="win32A"/>
@ -844,6 +856,12 @@
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="u_long" value="long">
<unsigned/>
<platform type="win32A"/>
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="ULONG32" value="int">
<unsigned/>
<platform type="win32A"/>
@ -880,6 +898,12 @@
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="u_short" value="short">
<unsigned/>
<platform type="win32A"/>
<platform type="win32W"/>
<platform type="win64"/>
</platformtype>
<platformtype name="USN" value="long">
<long/>
<platform type="win32A"/>
@ -4341,6 +4365,512 @@ HFONT CreateFont(
<returnValue type="HANDLE"/>
<use-retval/>
</function>
<!--BOOL WINAPI GetUserName(
_Out_ LPTSTR lpBuffer,
_Inout_ LPDWORD lpnSize);-->
<function name="GetUserName,GetUserNameA,GetUserNameW">
<noreturn>false</noreturn>
<returnValue type="BOOL"/>
<leak-ignore/>
<arg nr="1">
<!-- Allowed to be nullptr if variable pointed to by arg2 is 0 -->
</arg>
<arg nr="2">
<not-null/>
<not-uninit/>
</arg>
</function>
<!--int WINAPI GetWindowText(
_In_ HWND hWnd,
_Out_ LPTSTR lpString,
_In_ int nMaxCount);-->
<function name="GetWindowText,GetWindowTextA,GetWindowTextW">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<!-- The function does nothing (useful) if arg1 is nullptr or arg2 is nullptr or arg3 is 0 -->
<arg nr="1">
<not-null/>
</arg>
<arg nr="2">
<not-null/>
<!-- TODO: #8335 arg3 is the number of characters, not bytes. -->
<minsize type="argvalue" arg="3"/>
</arg>
<arg nr="3">
<not-uninit/>
<valid>1:</valid>
</arg>
</function>
<!--SOCKET WSAAPI socket(
__in int af,
__in int type,
__in int protocol);-->
<function name="socket">
<noreturn>false</noreturn>
<returnValue type="SOCKET"/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!--int closesocket(
__in SOCKET s);-->
<function name="closesocket">
<noreturn>false</noreturn>
<returnValue type="int"/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--SOCKET accept(
__in SOCKET s,
__out struct sockaddr *addr,
__inout int *addrlen);-->
<function name="accept">
<noreturn>false</noreturn>
<returnValue type="SOCKET"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
</function>
<!--int bind(
__in SOCKET s,
__in const struct sockaddr *name,
__in int namelen)-->
<function name="bind">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="3"/>
</arg>
<arg nr="3">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--int connect(
__in SOCKET s,
__in const struct sockaddr *name,
__in int namelen);-->
<function name="connect">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="3"/>
</arg>
<arg nr="3">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--int getpeername(
__in SOCKET s,
__out struct sockaddr *name,
__inout int *namelen);-->
<function name="getpeername">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
</arg>
</function>
<!--int getsockname(
__in SOCKET s,
__out struct sockaddr *name,
__inout int *namelen);-->
<function name="getsockname">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
</arg>
</function>
<!--int getsockopt(
__in SOCKET s,
__in int level,
__in int optname,
__out char *optval,
__inout int *optlen);-->
<function name="getsockopt">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-null/>
</arg>
<arg nr="5">
<not-null/>
<not-uninit/>
</arg>
</function>
<!--u_long WSAAPI htonl(
__in u_long hostlong);-->
<function name="htonl">
<noreturn>false</noreturn>
<returnValue type="u_long"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--u_short WSAAPI htons(
__in u_short hostshort);-->
<function name="htons">
<noreturn>false</noreturn>
<returnValue type="u_short"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--unsigned long inet_addr(
__in const char *cp);-->
<function name="inet_addr">
<noreturn>false</noreturn>
<returnValue type="unsigned long"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-null/>
<not-uninit/>
<strz/>
</arg>
</function>
<!--char* FAR inet_ntoa(
__in struct in_addr in);-->
<function name="inet_ntoa">
<noreturn>false</noreturn>
<returnValue type="char *"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--int ioctlsocket(
__in SOCKET s,
__in long cmd,
__inout u_long *argp);-->
<function name="ioctlsocket">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-null/>
</arg>
</function>
<!--int listen(
__in SOCKET s,
__in int backlog);-->
<function name="listen">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
</function>
<!--u_long WSAAPI ntohl(
__in u_long netlong);-->
<function name="ntohl">
<noreturn>false</noreturn>
<returnValue type="u_long"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--u_short WSAAPI ntohs(
__in u_short netshort);-->
<function name="ntohs">
<noreturn>false</noreturn>
<returnValue type="u_short"/>
<leak-ignore/>
<use-retval/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--int recv(
__in SOCKET s,
__out char *buf,
__in int len,
__in int flags);-->
<function name="recv">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="5"/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
</function>
<!--int recvfrom(
__in SOCKET s,
__out char *buf,
__in int len,
__in int flags,
__out struct sockaddr *from,
__inout_opt int *fromlen);-->
<function name="recvfrom">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="5"/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
<arg nr="5">
</arg>
<arg nr="6">
</arg>
</function>
<!--int select(
__in int nfds,
__inout fd_set *readfds,
__inout fd_set *writefds,
__inout fd_set *exceptfds,
__in const struct timeval *timeout);-->
<function name="select">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<!-- ignored -->
</arg>
<arg nr="2">
<!-- optional -->
</arg>
<arg nr="3">
<!-- optional -->
</arg>
<arg nr="4">
<!-- optional -->
</arg>
<arg nr="5">
<not-uninit/>
</arg>
</function>
<!--int send(
__in SOCKET s,
__in const char *buf,
__in int len,
__in int flags);-->
<function name="send">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="3"/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
</function>
<!--int sendto(
__in SOCKET s,
__in const char *buf,
__in int len,
__in int flags,
__in const struct sockaddr *to,
__in int tolen);-->
<function name="sendto">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
<minsize type="argvalue" arg="3"/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
<arg nr="5">
<not-uninit/>
</arg>
<arg nr="6">
<not-uninit/>
</arg>
</function>
<!--int setsockopt(
__in SOCKET s,
__in int level,
__in int optname,
__in const char *optval,
__in int optlen);-->
<function name="setsockopt">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
<arg nr="3">
<not-uninit/>
</arg>
<arg nr="4">
<not-null/>
<minsize type="argvalue" arg="5"/>
</arg>
<arg nr="5">
<not-uninit/>
<valid>0:</valid>
</arg>
</function>
<!--int shutdown(
__in SOCKET s,
__in int how);-->
<function name="shutdown">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-uninit/>
</arg>
</function>
<!--int WSAStartup(
__in WORD wVersionRequested,
__out LPWSADATA lpWSAData);-->
<function name="WSAStartup">
<noreturn>false</noreturn>
<returnValue type="int"/>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
<arg nr="2">
<not-null/>
</arg>
</function>
<!--int WSACleanup(void);-->
<function name="WSACleanup">
<noreturn>false</noreturn>
<returnValue type="int"/>
</function>
<!--int WSAGetLastError(void);-->
<function name="WSAGetLastError">
<noreturn>false</noreturn>
<returnValue type="int"/>
<use-retval/>
</function>
<!--void WSASetLastError(
__in int iError);-->
<function name="WSASetLastError">
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1">
<not-uninit/>
</arg>
</function>
<!--int _fileno(FILE *stream);-->
<function name="_fileno">
<noreturn>false</noreturn>
<returnValue type="int"/>
<use-retval/>
<leak-ignore/>
<arg nr="1">
<not-null/>
<not-uninit/>
<not-bool/>
</arg>
</function>
<podtype name="LARGE_INTEGER" sign="s" size="8"/>
<podtype name="POINTER_SIGNED" sign="s"/>
<podtype name="POINTER_UNSIGNED" sign="u"/>
@ -4357,4 +4887,5 @@ HFONT CreateFont(
<define name="__pragma(x)" value=""/>
<define name="TEXT(str)" value="str"/>
<define name="_countof(_Array)" value="(sizeof(_Array) / sizeof(_Array[0]))"/>
<define name="__wchar_t" value="wchar_t"/>
</def>

View File

@ -116,6 +116,21 @@ void validCode()
_stprintf(bufTC, _countof(bufTC), TEXT("%d"), 2);
_tprintf(TEXT("%s"), bufTC);
DWORD dwordInit = 0;
GetUserName(NULL, &dwordInit);
dwordInit = 10;
GetUserName(bufTC, _countof(bufTC));
WSADATA wsaData = {0};
WSAStartup(2, &wsaData);
SOCKET sock = socket(1, 2, 3);
u_long ulongInit = 0;
ioctlsocket(sock, FIONBIO, &ulongInit);
if (sock != INVALID_SOCKET) {
closesocket(sock);
}
WSACleanup();
// Valid Library usage, no leaks, valid arguments
HINSTANCE hInstLib = LoadLibrary(L"My.dll");
FreeLibrary(hInstLib);
@ -194,6 +209,31 @@ void nullPointer()
GetSystemTime(NULL);
// cppcheck-suppress nullPointer
GetLocalTime(NULL);
// TODO: error message: arg1 must not be nullptr if variable pointed to by arg2 is not 0
DWORD dwordInit = 10;
GetUserName(NULL, &dwordInit);
TCHAR bufTC[10];
// cppcheck-suppress nullPointer
GetUserName(bufTC, NULL);
SOCKET socketInit = {0};
sockaddr sockaddrUninit;
int intInit = 0;
int *pIntNull = NULL;
char charArray[] = "test";
// cppcheck-suppress nullPointer
WSAStartup(1, NULL);
// cppcheck-suppress nullPointer
bind(socketInit, NULL, 5);
// cppcheck-suppress nullPointer
getpeername(socketInit, NULL, &intInit);
// cppcheck-suppress nullPointer
getpeername(socketInit, &sockaddrUninit, pIntNull);
// cppcheck-suppress nullPointer
getsockopt(sockInit, 1, 2, NULL, &intInit);
// cppcheck-suppress nullPointer
getsockopt(sockInit, 1, 2, charArray, pIntNull);
}
void memleak_malloca()
@ -303,6 +343,14 @@ void resourceLeak_OpenEventW()
// cppcheck-suppress resourceLeak
}
void resourceLeak_socket()
{
SOCKET sock;
// cppcheck-suppress unreadVariable
sock = socket(1, 2, 3);
// cppcheck-suppress resourceLeak
}
void ignoredReturnValue()
{
// cppcheck-suppress leakReturnValNotUsed
@ -350,6 +398,12 @@ void ignoredReturnValue()
HeapAlloc(GetProcessHeap(), 0, 10);
// cppcheck-suppress leakReturnValNotUsed
HeapReAlloc(GetProcessHeap(), 0, 1, 0);
// cppcheck-suppress leakReturnValNotUsed
socket(1, 2, 3);
// cppcheck-suppress ignoredReturnValue
_fileno(stdio);
}
void invalidFunctionArg()
@ -435,6 +489,15 @@ void uninitvar()
DWORD dwordUninit;
// cppcheck-suppress uninitvar
SetLastError(dwordUninit);
DWORD dwordUninit;
// cppcheck-suppress uninitvar
GetUserName(NULL, &dwordUninit);
FILE *pFileUninit;
// cppcheck-suppress uninitvar
// cppcheck-suppress ignoredReturnValue
_fileno(pFileUninit);
}
void errorPrintf()