From a035c9b4d1d438028f5041f0c6d1bfc228946f19 Mon Sep 17 00:00:00 2001 From: Mathias Vorreiter Pedersen Date: Fri, 14 Mar 2025 20:04:45 +0000 Subject: [PATCH] C++: Also update source-sink tests. --- .../dataflow/source-sink-tests/atl.cpp | 660 +++++++++--------- 1 file changed, 332 insertions(+), 328 deletions(-) diff --git a/cpp/ql/test/library-tests/dataflow/source-sink-tests/atl.cpp b/cpp/ql/test/library-tests/dataflow/source-sink-tests/atl.cpp index 7df5e3dc1a0..24340195517 100644 --- a/cpp/ql/test/library-tests/dataflow/source-sink-tests/atl.cpp +++ b/cpp/ql/test/library-tests/dataflow/source-sink-tests/atl.cpp @@ -13,377 +13,381 @@ typedef long long LONGLONG; typedef unsigned long* ULONG_PTR; typedef char *LPTSTR; typedef DWORD* LPDWORD; -typedef ULONG REGSAM; -typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; -typedef PVOID PSECURITY_DESCRIPTOR; -typedef struct _GUID { - unsigned long Data1; - unsigned short Data2; - unsigned short Data3; - unsigned char Data4[8]; -} GUID; -typedef GUID* REFGUID; - -typedef struct _SECURITY_ATTRIBUTES { - DWORD nLength; - LPVOID lpSecurityDescriptor; - BOOL bInheritHandle; -} SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; - -typedef struct _FILETIME { - DWORD dwLowDateTime; - DWORD dwHighDateTime; -} FILETIME, *PFILETIME, *LPFILETIME; using size_t = decltype(sizeof(int)); using SIZE_T = size_t; -typedef struct _OVERLAPPED { - ULONG_PTR Internal; - ULONG_PTR InternalHigh; - union { - struct { - DWORD Offset; - DWORD OffsetHigh; - } DUMMYSTRUCTNAME; - PVOID Pointer; - } DUMMYUNIONNAME; - HANDLE hEvent; -} OVERLAPPED, *LPOVERLAPPED; +namespace ATL { -using LPOVERLAPPED_COMPLETION_ROUTINE = void(DWORD, DWORD, LPOVERLAPPED); + typedef ULONG REGSAM; + typedef DWORD SECURITY_INFORMATION, *PSECURITY_INFORMATION; + typedef PVOID PSECURITY_DESCRIPTOR; + typedef struct _GUID { + unsigned long Data1; + unsigned short Data2; + unsigned short Data3; + unsigned char Data4[8]; + } GUID; + typedef GUID* REFGUID; -using HKEY = void*; + typedef struct _SECURITY_ATTRIBUTES { + DWORD nLength; + LPVOID lpSecurityDescriptor; + BOOL bInheritHandle; + } SECURITY_ATTRIBUTES, *PSECURITY_ATTRIBUTES, *LPSECURITY_ATTRIBUTES; -class CAtlTransactionManager; + typedef struct _FILETIME { + DWORD dwLowDateTime; + DWORD dwHighDateTime; + } FILETIME, *PFILETIME, *LPFILETIME; -class CHandle { - CHandle() throw(); - CHandle(CHandle& h) throw(); - explicit CHandle(HANDLE h) throw(); -}; + typedef struct _OVERLAPPED { + ULONG_PTR Internal; + ULONG_PTR InternalHigh; + union { + struct { + DWORD Offset; + DWORD OffsetHigh; + } DUMMYSTRUCTNAME; + PVOID Pointer; + } DUMMYUNIONNAME; + HANDLE hEvent; + } OVERLAPPED, *LPOVERLAPPED; -struct CAtlFile : public CHandle { - CAtlFile() throw(); - CAtlFile(CAtlTransactionManager* pTM) throw(); - CAtlFile(CAtlFile& file) throw(); - explicit CAtlFile(HANDLE hFile) throw(); + using LPOVERLAPPED_COMPLETION_ROUTINE = void(DWORD, DWORD, LPOVERLAPPED); - HRESULT Create( - LPCTSTR szFilename, - DWORD dwDesiredAccess, - DWORD dwShareMode, - DWORD dwCreationDisposition, - DWORD dwFlagsAndAttributes, - LPSECURITY_ATTRIBUTES lpsa, - HANDLE hTemplateFile) throw(); + using HKEY = void*; + class CAtlTransactionManager; + + class CHandle { + CHandle() throw(); + CHandle(CHandle& h) throw(); + explicit CHandle(HANDLE h) throw(); + }; + + struct CAtlFile : public CHandle { + CAtlFile() throw(); + CAtlFile(CAtlTransactionManager* pTM) throw(); + CAtlFile(CAtlFile& file) throw(); + explicit CAtlFile(HANDLE hFile) throw(); + + HRESULT Create( + LPCTSTR szFilename, + DWORD dwDesiredAccess, + DWORD dwShareMode, + DWORD dwCreationDisposition, + DWORD dwFlagsAndAttributes, + LPSECURITY_ATTRIBUTES lpsa, + HANDLE hTemplateFile) throw(); + + HRESULT Flush() throw(); + HRESULT GetOverlappedResult( + LPOVERLAPPED pOverlapped, + DWORD& dwBytesTransferred, + BOOL bWait + ) throw(); + + HRESULT GetPosition(ULONGLONG& nPos) const throw(); + HRESULT GetSize(ULONGLONG& nLen) const throw(); + HRESULT LockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); + + HRESULT Read( + LPVOID pBuffer, + DWORD nBufSize) throw(); + + HRESULT Read( + LPVOID pBuffer, + DWORD nBufSize, + DWORD& nBytesRead) throw(); + HRESULT Read( + LPVOID pBuffer, + DWORD nBufSize, + LPOVERLAPPED pOverlapped) throw(); + HRESULT Read( + LPVOID pBuffer, + DWORD nBufSize, + LPOVERLAPPED pOverlapped, + LPOVERLAPPED_COMPLETION_ROUTINE pfnCompletionRoutine) throw(); + + HRESULT Seek( + LONGLONG nOffset, + DWORD dwFrom) throw(); + + HRESULT SetSize(ULONGLONG nNewLen) throw(); + HRESULT UnlockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); + HRESULT Write( + LPCVOID pBuffer, + DWORD nBufSize, + LPOVERLAPPED pOverlapped, + LPOVERLAPPED_COMPLETION_ROUTINE pfnCompletionRoutine) throw(); + + HRESULT Write( + LPCVOID pBuffer, + DWORD nBufSize, + DWORD* pnBytesWritten) throw(); + + HRESULT Write( + LPCVOID pBuffer, + DWORD nBufSize, + LPOVERLAPPED pOverlapped) throw(); + }; + + void test_CAtlFile() { + CAtlFile catFile; + char buffer[1024]; + catFile.Read(buffer, 1024); // $ local_source + } + + struct CAtlFileMappingBase { + CAtlFileMappingBase(CAtlFileMappingBase& orig); + CAtlFileMappingBase() throw(); + ~CAtlFileMappingBase() throw(); + + HRESULT CopyFrom(CAtlFileMappingBase& orig) throw(); + void* GetData() const throw(); + HANDLE GetHandle() throw (); + SIZE_T GetMappingSize() throw(); + + HRESULT MapFile( + HANDLE hFile, + SIZE_T nMappingSize, + ULONGLONG nOffset, + DWORD dwMappingProtection, + DWORD dwViewDesiredAccess) throw(); + + HRESULT MapSharedMem( + SIZE_T nMappingSize, + LPCTSTR szName, + BOOL* pbAlreadyExisted, + LPSECURITY_ATTRIBUTES lpsa, + DWORD dwMappingProtection, + DWORD dwViewDesiredAccess) throw(); + + HRESULT OpenMapping( + LPCTSTR szName, + SIZE_T nMappingSize, + ULONGLONG nOffset, + DWORD dwViewDesiredAccess) throw(); + + HRESULT Unmap() throw(); + }; + + template + struct CAtlFileMapping : public CAtlFileMappingBase { + operator T*() const throw(); + }; + + void test_CAtlFileMapping(CAtlFileMapping mapping) { + char* data = static_cast(mapping); // $ local_source + void* data2 = mapping.GetData(); // $ local_source + } + + struct CAtlTemporaryFile { + CAtlTemporaryFile() throw(); + ~CAtlTemporaryFile() throw(); + HRESULT Close(LPCTSTR szNewName) throw(); + HRESULT Create(LPCTSTR pszDir, DWORD dwDesiredAccess) throw(); HRESULT Flush() throw(); - HRESULT GetOverlappedResult( - LPOVERLAPPED pOverlapped, - DWORD& dwBytesTransferred, - BOOL bWait - ) throw(); - HRESULT GetPosition(ULONGLONG& nPos) const throw(); HRESULT GetSize(ULONGLONG& nLen) const throw(); + HRESULT HandsOff() throw(); + HRESULT HandsOn() throw(); HRESULT LockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); - + HRESULT Read( - LPVOID pBuffer, - DWORD nBufSize) throw(); + LPVOID pBuffer, + DWORD nBufSize, + DWORD& nBytesRead) throw(); + HRESULT Seek(LONGLONG nOffset, DWORD dwFrom) throw(); + + HRESULT SetSize(ULONGLONG nNewLen) throw(); + LPCTSTR TempFileName() throw(); + HRESULT UnlockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); + + HRESULT Write( + LPCVOID pBuffer, + DWORD nBufSize, + DWORD* pnBytesWritten) throw(); + operator HANDLE() throw(); + }; - HRESULT Read( - LPVOID pBuffer, - DWORD nBufSize, - DWORD& nBytesRead) throw(); - HRESULT Read( - LPVOID pBuffer, - DWORD nBufSize, - LPOVERLAPPED pOverlapped) throw(); - HRESULT Read( - LPVOID pBuffer, - DWORD nBufSize, - LPOVERLAPPED pOverlapped, - LPOVERLAPPED_COMPLETION_ROUTINE pfnCompletionRoutine) throw(); + void test_CAtlTemporaryFile() { + CAtlTemporaryFile file; + char buffer[1024]; + DWORD bytesRead; + file.Read(buffer, 1024, bytesRead); // $ local_source + } - HRESULT Seek( - LONGLONG nOffset, - DWORD dwFrom) throw(); + struct CRegKey { + CRegKey() throw(); + CRegKey(CRegKey& key) throw(); + explicit CRegKey(HKEY hKey) throw(); + CRegKey(CAtlTransactionManager* pTM) throw(); - HRESULT SetSize(ULONGLONG nNewLen) throw(); - HRESULT UnlockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); - HRESULT Write( - LPCVOID pBuffer, - DWORD nBufSize, - LPOVERLAPPED pOverlapped, - LPOVERLAPPED_COMPLETION_ROUTINE pfnCompletionRoutine) throw(); + ~CRegKey() throw(); + void Attach(HKEY hKey) throw(); + LONG Close() throw(); - HRESULT Write( - LPCVOID pBuffer, - DWORD nBufSize, - DWORD* pnBytesWritten) throw(); + LONG Create( + HKEY hKeyParent, + LPCTSTR lpszKeyName, + LPTSTR lpszClass, + DWORD dwOptions, + REGSAM samDesired, + LPSECURITY_ATTRIBUTES lpSecAttr, + LPDWORD lpdwDisposition) throw(); - HRESULT Write( - LPCVOID pBuffer, - DWORD nBufSize, - LPOVERLAPPED pOverlapped) throw(); -}; + LONG DeleteSubKey(LPCTSTR lpszSubKey) throw(); + LONG DeleteValue(LPCTSTR lpszValue) throw(); + HKEY Detach() throw(); + + LONG EnumKey( + DWORD iIndex, + LPTSTR pszName, + LPDWORD pnNameLength, + FILETIME* pftLastWriteTime) throw(); + + LONG Flush() throw(); -void test_CAtlFile() { - CAtlFile catFile; - char buffer[1024]; - catFile.Read(buffer, 1024); // $ local_source -} + LONG GetKeySecurity( + SECURITY_INFORMATION si, + PSECURITY_DESCRIPTOR psd, + LPDWORD pnBytes) throw(); + + LONG NotifyChangeKeyValue( + BOOL bWatchSubtree, + DWORD dwNotifyFilter, + HANDLE hEvent, + BOOL bAsync) throw(); -struct CAtlFileMappingBase { - CAtlFileMappingBase(CAtlFileMappingBase& orig); - CAtlFileMappingBase() throw(); - ~CAtlFileMappingBase() throw(); + LONG Open( + HKEY hKeyParent, + LPCTSTR lpszKeyName, + REGSAM samDesired) throw(); - HRESULT CopyFrom(CAtlFileMappingBase& orig) throw(); - void* GetData() const throw(); - HANDLE GetHandle() throw (); - SIZE_T GetMappingSize() throw(); - - HRESULT MapFile( - HANDLE hFile, - SIZE_T nMappingSize, - ULONGLONG nOffset, - DWORD dwMappingProtection, - DWORD dwViewDesiredAccess) throw(); - - HRESULT MapSharedMem( - SIZE_T nMappingSize, - LPCTSTR szName, - BOOL* pbAlreadyExisted, - LPSECURITY_ATTRIBUTES lpsa, - DWORD dwMappingProtection, - DWORD dwViewDesiredAccess) throw(); - - HRESULT OpenMapping( - LPCTSTR szName, - SIZE_T nMappingSize, - ULONGLONG nOffset, - DWORD dwViewDesiredAccess) throw(); - - HRESULT Unmap() throw(); -}; - -template -struct CAtlFileMapping : public CAtlFileMappingBase { - operator T*() const throw(); -}; - -void test_CAtlFileMapping(CAtlFileMapping mapping) { - char* data = static_cast(mapping); // $ local_source - void* data2 = mapping.GetData(); // $ local_source -} - -struct CAtlTemporaryFile { - CAtlTemporaryFile() throw(); - ~CAtlTemporaryFile() throw(); - HRESULT Close(LPCTSTR szNewName) throw(); - HRESULT Create(LPCTSTR pszDir, DWORD dwDesiredAccess) throw(); - HRESULT Flush() throw(); - HRESULT GetPosition(ULONGLONG& nPos) const throw(); - HRESULT GetSize(ULONGLONG& nLen) const throw(); - HRESULT HandsOff() throw(); - HRESULT HandsOn() throw(); - HRESULT LockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); - - HRESULT Read( - LPVOID pBuffer, - DWORD nBufSize, - DWORD& nBytesRead) throw(); - HRESULT Seek(LONGLONG nOffset, DWORD dwFrom) throw(); - - HRESULT SetSize(ULONGLONG nNewLen) throw(); - LPCTSTR TempFileName() throw(); - HRESULT UnlockRange(ULONGLONG nPos, ULONGLONG nCount) throw(); - - HRESULT Write( - LPCVOID pBuffer, - DWORD nBufSize, - DWORD* pnBytesWritten) throw(); - operator HANDLE() throw(); -}; - -void test_CAtlTemporaryFile() { - CAtlTemporaryFile file; - char buffer[1024]; - DWORD bytesRead; - file.Read(buffer, 1024, bytesRead); // $ local_source -} - -struct CRegKey { - CRegKey() throw(); - CRegKey(CRegKey& key) throw(); - explicit CRegKey(HKEY hKey) throw(); - CRegKey(CAtlTransactionManager* pTM) throw(); - - ~CRegKey() throw(); - void Attach(HKEY hKey) throw(); - LONG Close() throw(); - - LONG Create( - HKEY hKeyParent, - LPCTSTR lpszKeyName, - LPTSTR lpszClass, - DWORD dwOptions, - REGSAM samDesired, - LPSECURITY_ATTRIBUTES lpSecAttr, - LPDWORD lpdwDisposition) throw(); - - LONG DeleteSubKey(LPCTSTR lpszSubKey) throw(); - LONG DeleteValue(LPCTSTR lpszValue) throw(); - HKEY Detach() throw(); - - LONG EnumKey( - DWORD iIndex, - LPTSTR pszName, - LPDWORD pnNameLength, - FILETIME* pftLastWriteTime) throw(); - - LONG Flush() throw(); - - LONG GetKeySecurity( - SECURITY_INFORMATION si, - PSECURITY_DESCRIPTOR psd, - LPDWORD pnBytes) throw(); - - LONG NotifyChangeKeyValue( - BOOL bWatchSubtree, - DWORD dwNotifyFilter, - HANDLE hEvent, - BOOL bAsync) throw(); - - LONG Open( - HKEY hKeyParent, - LPCTSTR lpszKeyName, - REGSAM samDesired) throw(); - - LONG QueryBinaryValue( - LPCTSTR pszValueName, - void* pValue, - ULONG* pnBytes) throw(); - - LONG QueryDWORDValue( - LPCTSTR pszValueName, - DWORD& dwValue) throw(); - - LONG QueryGUIDValue( - LPCTSTR pszValueName, - GUID& guidValue) throw(); - - LONG QueryMultiStringValue( - LPCTSTR pszValueName, - LPTSTR pszValue, - ULONG* pnChars) throw(); - - LONG QueryQWORDValue( - LPCTSTR pszValueName, - ULONGLONG& qwValue) throw(); - - LONG QueryStringValue( - LPCTSTR pszValueName, - LPTSTR pszValue, - ULONG* pnChars) throw(); - - LONG QueryValue( + LONG QueryBinaryValue( LPCTSTR pszValueName, - DWORD* pdwType, - void* pData, + void* pValue, ULONG* pnBytes) throw(); - LONG QueryValue( - DWORD& dwValue, - LPCTSTR lpszValueName); + LONG QueryDWORDValue( + LPCTSTR pszValueName, + DWORD& dwValue) throw(); - LONG QueryValue( - LPTSTR szValue, - LPCTSTR lpszValueName, - DWORD* pdwCount); + LONG QueryGUIDValue( + LPCTSTR pszValueName, + GUID& guidValue) throw(); - LONG RecurseDeleteKey(LPCTSTR lpszKey) throw(); + LONG QueryMultiStringValue( + LPCTSTR pszValueName, + LPTSTR pszValue, + ULONG* pnChars) throw(); - LONG SetBinaryValue( - LPCTSTR pszValueName, - const void* pValue, - ULONG nBytes) throw(); + LONG QueryQWORDValue( + LPCTSTR pszValueName, + ULONGLONG& qwValue) throw(); - LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue) throw(); + LONG QueryStringValue( + LPCTSTR pszValueName, + LPTSTR pszValue, + ULONG* pnChars) throw(); - LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue) throw(); + LONG QueryValue( + LPCTSTR pszValueName, + DWORD* pdwType, + void* pData, + ULONG* pnBytes) throw(); - LONG SetKeySecurity(SECURITY_INFORMATION si, PSECURITY_DESCRIPTOR psd) throw(); + LONG QueryValue( + DWORD& dwValue, + LPCTSTR lpszValueName); - LONG SetKeyValue( - LPCTSTR lpszKeyName, - LPCTSTR lpszValue, - LPCTSTR lpszValueName) throw(); + LONG QueryValue( + LPTSTR szValue, + LPCTSTR lpszValueName, + DWORD* pdwCount); - LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue) throw(); + LONG RecurseDeleteKey(LPCTSTR lpszKey) throw(); - LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue) throw(); + LONG SetBinaryValue( + LPCTSTR pszValueName, + const void* pValue, + ULONG nBytes) throw(); - LONG SetStringValue( - LPCTSTR pszValueName, - LPCTSTR pszValue, - DWORD dwType) throw(); + LONG SetDWORDValue(LPCTSTR pszValueName, DWORD dwValue) throw(); - LONG SetValue( - LPCTSTR pszValueName, - DWORD dwType, - const void* pValue, - ULONG nBytes) throw(); + LONG SetGUIDValue(LPCTSTR pszValueName, REFGUID guidValue) throw(); - static LONG SetValue( - HKEY hKeyParent, - LPCTSTR lpszKeyName, - LPCTSTR lpszValue, - LPCTSTR lpszValueName); + LONG SetKeySecurity(SECURITY_INFORMATION si, PSECURITY_DESCRIPTOR psd) throw(); - LONG SetValue( - DWORD dwValue, - LPCTSTR lpszValueName); + LONG SetKeyValue( + LPCTSTR lpszKeyName, + LPCTSTR lpszValue, + LPCTSTR lpszValueName) throw(); - LONG SetValue( - LPCTSTR lpszValue, - LPCTSTR lpszValueName, - bool bMulti, - int nValueLen); + LONG SetMultiStringValue(LPCTSTR pszValueName, LPCTSTR pszValue) throw(); - operator HKEY() const throw(); - CRegKey& operator= (CRegKey& key) throw(); + LONG SetQWORDValue(LPCTSTR pszValueName, ULONGLONG qwValue) throw(); - HKEY m_hKey; -}; + LONG SetStringValue( + LPCTSTR pszValueName, + LPCTSTR pszValue, + DWORD dwType) throw(); -void test_CRegKey() { - CRegKey key; - char data[1024]; - ULONG bytesRead; - key.QueryBinaryValue("foo", data, &bytesRead); // $ local_source + LONG SetValue( + LPCTSTR pszValueName, + DWORD dwType, + const void* pValue, + ULONG nBytes) throw(); - DWORD value; - key.QueryDWORDValue("foo", value); // $ local_source - - GUID guid; - key.QueryGUIDValue("foo", guid); // $ local_source - - key.QueryMultiStringValue("foo", data, &bytesRead); // $ local_source - - ULONGLONG qword; - key.QueryQWORDValue("foo", qword); // $ local_source - - key.QueryStringValue("foo", data, &bytesRead); // $ local_source - - key.QueryValue(data, "foo", &bytesRead); // $ local_source - - DWORD type; - key.QueryValue("foo", &type, data, &bytesRead); // $ local_source - - DWORD value2; - key.QueryValue(value2, "foo"); // $ local_source + static LONG SetValue( + HKEY hKeyParent, + LPCTSTR lpszKeyName, + LPCTSTR lpszValue, + LPCTSTR lpszValueName); + + LONG SetValue( + DWORD dwValue, + LPCTSTR lpszValueName); + + LONG SetValue( + LPCTSTR lpszValue, + LPCTSTR lpszValueName, + bool bMulti, + int nValueLen); + + operator HKEY() const throw(); + CRegKey& operator= (CRegKey& key) throw(); + + HKEY m_hKey; + }; + + void test_CRegKey() { + CRegKey key; + char data[1024]; + ULONG bytesRead; + key.QueryBinaryValue("foo", data, &bytesRead); // $ local_source + + DWORD value; + key.QueryDWORDValue("foo", value); // $ local_source + + GUID guid; + key.QueryGUIDValue("foo", guid); // $ local_source + + key.QueryMultiStringValue("foo", data, &bytesRead); // $ local_source + + ULONGLONG qword; + key.QueryQWORDValue("foo", qword); // $ local_source + + key.QueryStringValue("foo", data, &bytesRead); // $ local_source + + key.QueryValue(data, "foo", &bytesRead); // $ local_source + + DWORD type; + key.QueryValue("foo", &type, data, &bytesRead); // $ local_source + + DWORD value2; + key.QueryValue(value2, "foo"); // $ local_source + } } \ No newline at end of file