Skip to content

Commit b42bffc

Browse files
committed
C++: Add CSimpleStringT tests.
1 parent fb75f54 commit b42bffc

File tree

3 files changed

+220
-1
lines changed

3 files changed

+220
-1
lines changed

cpp/ql/test/library-tests/dataflow/taint-tests/atl.cpp

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,4 +898,114 @@ void test_CUrl() {
898898
url2.SetUserName(x);
899899
sink(url2); // $ ir
900900
}
901-
}
901+
}
902+
903+
struct IAtlStringMgr {}; // simplified
904+
905+
using XCHAR = char;
906+
using YCHAR = wchar_t;
907+
908+
template <typename BaseType>
909+
struct CSimpleStringT {
910+
using PCXSTR = const BaseType*; // simplified
911+
using PXSTR = BaseType*; // simplified
912+
913+
CSimpleStringT() throw();
914+
CSimpleStringT(const XCHAR* pchSrc, int nLength, IAtlStringMgr* pStringMgr);
915+
CSimpleStringT(PCXSTR pszSrc, IAtlStringMgr* pStringMgr);
916+
CSimpleStringT(const CSimpleStringT& strSrc);
917+
918+
~CSimpleStringT() throw();
919+
920+
void Append(const CSimpleStringT& strSrc);
921+
void Append(PCXSTR pszSrc, int nLength);
922+
void Append(PCXSTR pszSrc);
923+
924+
void AppendChar(XCHAR ch);
925+
926+
static void CopyChars(XCHAR* pchDest, const XCHAR* pchSrc, int nChars) throw();
927+
static void CopyChars(XCHAR* pchDest, size_t nDestLen, const XCHAR* pchSrc, int nChars) throw();
928+
static void CopyCharsOverlapped(XCHAR* pchDest, const XCHAR* pchSrc, int nChars) throw();
929+
930+
XCHAR GetAt(int iChar) const;
931+
PXSTR GetBuffer(int nMinBufferLength);
932+
PXSTR GetBuffer();
933+
PXSTR GetBufferSetLength(int nLength);
934+
935+
PCXSTR GetString() const throw();
936+
PXSTR LockBuffer();
937+
void SetAt(int iChar, XCHAR ch);
938+
void SetString(PCXSTR pszSrc, int nLength);
939+
void SetString(PCXSTR pszSrc);
940+
operator PCXSTR() const throw();
941+
XCHAR operator[](int iChar) const;
942+
943+
CSimpleStringT& operator+=(PCXSTR pszSrc);
944+
CSimpleStringT& operator+=(const CSimpleStringT& strSrc);
945+
CSimpleStringT& operator+=(char ch);
946+
CSimpleStringT& operator+=(unsigned char ch);
947+
CSimpleStringT& operator+=(wchar_t ch);
948+
949+
CSimpleStringT& operator=(PCXSTR pszSrc);
950+
CSimpleStringT& operator=(const CSimpleStringT& strSrc);
951+
};
952+
953+
void test_CSimpleStringT() {
954+
char* x = indirect_source<char>();
955+
956+
CSimpleStringT<char> s1(x, 10, nullptr);
957+
sink(s1.GetString()); // $ MISSING: ir
958+
959+
CSimpleStringT<char> s2(x, nullptr);
960+
sink(s2.GetString()); // $ MISSING: ir
961+
962+
CSimpleStringT<char> s3(s2);
963+
sink(s3.GetString()); // $ MISSING: ir
964+
965+
CSimpleStringT<char> s4;
966+
s4.Append(indirect_source<char>());
967+
sink(s4.GetString()); // $ MISSING: ir
968+
969+
CSimpleStringT<char> s5;
970+
s5.Append(s4);
971+
sink(s5.GetString()); // $ MISSING: ir
972+
973+
CSimpleStringT<char> s6;
974+
s6.Append(indirect_source<char>(), 42);
975+
sink(s6.GetString()); // $ MISSING: ir
976+
977+
char buffer1[128];
978+
CSimpleStringT<char>::CopyChars(buffer1, x, 10);
979+
sink(buffer1); // $ ast MISSING: ir
980+
981+
char buffer2[128];
982+
CSimpleStringT<char>::CopyChars(buffer2, 128, x, 10);
983+
sink(buffer2); // $ ast MISSING: ir
984+
985+
char buffer3[128];
986+
CSimpleStringT<char>::CopyCharsOverlapped(buffer3, x, 10);
987+
sink(buffer3); // $ ast MISSING: ir
988+
989+
sink(s4.GetAt(0)); // $ MISSING: ir
990+
sink(s4.GetBuffer(10)); // $ MISSING: ir
991+
sink(s4.GetBuffer()); // $ MISSING: ir
992+
sink(s4.GetBufferSetLength(10)); // $ MISSING: ir
993+
994+
sink(s4.LockBuffer());
995+
996+
CSimpleStringT<char> s7;
997+
s7.SetAt(0, source<char>());
998+
sink(s7.GetAt(0)); // $ MISSING: ir
999+
1000+
CSimpleStringT<char> s8;
1001+
s8.SetString(indirect_source<char>());
1002+
sink(s8.GetAt(0)); // $ MISSING: ir
1003+
1004+
CSimpleStringT<char> s9;
1005+
s9.SetString(indirect_source<char>(), 1024);
1006+
sink(s9.GetAt(0)); // $ MISSING: ir
1007+
1008+
sink(static_cast<CSimpleStringT<char>::PCXSTR>(s1)); // $ MISSING: ir
1009+
1010+
sink(s1[0]); // $ MISSING: ir
1011+
}

cpp/ql/test/library-tests/dataflow/taint-tests/localTaint.expected

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,82 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
946946
| atl.cpp:897:10:897:13 | call to CUrl | atl.cpp:900:3:900:3 | url2 | |
947947
| atl.cpp:898:5:898:8 | ref arg url2 | atl.cpp:899:10:899:13 | url2 | |
948948
| atl.cpp:898:5:898:8 | ref arg url2 | atl.cpp:900:3:900:3 | url2 | |
949+
| atl.cpp:954:13:954:33 | call to indirect_source | atl.cpp:956:27:956:27 | x | |
950+
| atl.cpp:954:13:954:33 | call to indirect_source | atl.cpp:959:27:959:27 | x | |
951+
| atl.cpp:954:13:954:33 | call to indirect_source | atl.cpp:978:44:978:44 | x | |
952+
| atl.cpp:954:13:954:33 | call to indirect_source | atl.cpp:982:49:982:49 | x | |
953+
| atl.cpp:954:13:954:33 | call to indirect_source | atl.cpp:986:54:986:54 | x | |
954+
| atl.cpp:956:27:956:41 | call to CSimpleStringT | atl.cpp:957:8:957:9 | s1 | |
955+
| atl.cpp:956:27:956:41 | call to CSimpleStringT | atl.cpp:1008:50:1008:51 | s1 | |
956+
| atl.cpp:956:27:956:41 | call to CSimpleStringT | atl.cpp:1010:8:1010:9 | s1 | |
957+
| atl.cpp:956:27:956:41 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s1 | |
958+
| atl.cpp:959:27:959:37 | call to CSimpleStringT | atl.cpp:960:8:960:9 | s2 | |
959+
| atl.cpp:959:27:959:37 | call to CSimpleStringT | atl.cpp:962:27:962:28 | s2 | |
960+
| atl.cpp:959:27:959:37 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s2 | |
961+
| atl.cpp:962:27:962:28 | s2 | atl.cpp:962:27:962:29 | call to CSimpleStringT | |
962+
| atl.cpp:962:27:962:29 | call to CSimpleStringT | atl.cpp:963:8:963:9 | s3 | |
963+
| atl.cpp:962:27:962:29 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s3 | |
964+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:966:3:966:4 | s4 | |
965+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:967:8:967:9 | s4 | |
966+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:970:13:970:14 | s4 | |
967+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:989:8:989:9 | s4 | |
968+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:990:8:990:9 | s4 | |
969+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:991:8:991:9 | s4 | |
970+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:992:8:992:9 | s4 | |
971+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:994:8:994:9 | s4 | |
972+
| atl.cpp:965:24:965:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s4 | |
973+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:967:8:967:9 | s4 | |
974+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:970:13:970:14 | s4 | |
975+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:989:8:989:9 | s4 | |
976+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:990:8:990:9 | s4 | |
977+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:991:8:991:9 | s4 | |
978+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:992:8:992:9 | s4 | |
979+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:994:8:994:9 | s4 | |
980+
| atl.cpp:966:3:966:4 | ref arg s4 | atl.cpp:1011:1:1011:1 | s4 | |
981+
| atl.cpp:969:24:969:25 | call to CSimpleStringT | atl.cpp:970:3:970:4 | s5 | |
982+
| atl.cpp:969:24:969:25 | call to CSimpleStringT | atl.cpp:971:8:971:9 | s5 | |
983+
| atl.cpp:969:24:969:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s5 | |
984+
| atl.cpp:970:3:970:4 | ref arg s5 | atl.cpp:971:8:971:9 | s5 | |
985+
| atl.cpp:970:3:970:4 | ref arg s5 | atl.cpp:1011:1:1011:1 | s5 | |
986+
| atl.cpp:973:24:973:25 | call to CSimpleStringT | atl.cpp:974:3:974:4 | s6 | |
987+
| atl.cpp:973:24:973:25 | call to CSimpleStringT | atl.cpp:975:8:975:9 | s6 | |
988+
| atl.cpp:973:24:973:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s6 | |
989+
| atl.cpp:974:3:974:4 | ref arg s6 | atl.cpp:975:8:975:9 | s6 | |
990+
| atl.cpp:974:3:974:4 | ref arg s6 | atl.cpp:1011:1:1011:1 | s6 | |
991+
| atl.cpp:977:8:977:14 | buffer1 | atl.cpp:978:35:978:41 | buffer1 | |
992+
| atl.cpp:977:8:977:14 | buffer1 | atl.cpp:979:8:979:14 | buffer1 | |
993+
| atl.cpp:978:35:978:41 | ref arg buffer1 | atl.cpp:979:8:979:14 | buffer1 | |
994+
| atl.cpp:981:8:981:14 | buffer2 | atl.cpp:982:35:982:41 | buffer2 | |
995+
| atl.cpp:981:8:981:14 | buffer2 | atl.cpp:983:8:983:14 | buffer2 | |
996+
| atl.cpp:982:35:982:41 | ref arg buffer2 | atl.cpp:983:8:983:14 | buffer2 | |
997+
| atl.cpp:985:8:985:14 | buffer3 | atl.cpp:986:45:986:51 | buffer3 | |
998+
| atl.cpp:985:8:985:14 | buffer3 | atl.cpp:987:8:987:14 | buffer3 | |
999+
| atl.cpp:986:45:986:51 | ref arg buffer3 | atl.cpp:987:8:987:14 | buffer3 | |
1000+
| atl.cpp:990:8:990:9 | ref arg s4 | atl.cpp:991:8:991:9 | s4 | |
1001+
| atl.cpp:990:8:990:9 | ref arg s4 | atl.cpp:992:8:992:9 | s4 | |
1002+
| atl.cpp:990:8:990:9 | ref arg s4 | atl.cpp:994:8:994:9 | s4 | |
1003+
| atl.cpp:990:8:990:9 | ref arg s4 | atl.cpp:1011:1:1011:1 | s4 | |
1004+
| atl.cpp:991:8:991:9 | ref arg s4 | atl.cpp:992:8:992:9 | s4 | |
1005+
| atl.cpp:991:8:991:9 | ref arg s4 | atl.cpp:994:8:994:9 | s4 | |
1006+
| atl.cpp:991:8:991:9 | ref arg s4 | atl.cpp:1011:1:1011:1 | s4 | |
1007+
| atl.cpp:992:8:992:9 | ref arg s4 | atl.cpp:994:8:994:9 | s4 | |
1008+
| atl.cpp:992:8:992:9 | ref arg s4 | atl.cpp:1011:1:1011:1 | s4 | |
1009+
| atl.cpp:994:8:994:9 | ref arg s4 | atl.cpp:1011:1:1011:1 | s4 | |
1010+
| atl.cpp:996:24:996:25 | call to CSimpleStringT | atl.cpp:997:3:997:4 | s7 | |
1011+
| atl.cpp:996:24:996:25 | call to CSimpleStringT | atl.cpp:998:8:998:9 | s7 | |
1012+
| atl.cpp:996:24:996:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s7 | |
1013+
| atl.cpp:997:3:997:4 | ref arg s7 | atl.cpp:998:8:998:9 | s7 | |
1014+
| atl.cpp:997:3:997:4 | ref arg s7 | atl.cpp:1011:1:1011:1 | s7 | |
1015+
| atl.cpp:1000:24:1000:25 | call to CSimpleStringT | atl.cpp:1001:3:1001:4 | s8 | |
1016+
| atl.cpp:1000:24:1000:25 | call to CSimpleStringT | atl.cpp:1002:8:1002:9 | s8 | |
1017+
| atl.cpp:1000:24:1000:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s8 | |
1018+
| atl.cpp:1001:3:1001:4 | ref arg s8 | atl.cpp:1002:8:1002:9 | s8 | |
1019+
| atl.cpp:1001:3:1001:4 | ref arg s8 | atl.cpp:1011:1:1011:1 | s8 | |
1020+
| atl.cpp:1004:24:1004:25 | call to CSimpleStringT | atl.cpp:1005:3:1005:4 | s9 | |
1021+
| atl.cpp:1004:24:1004:25 | call to CSimpleStringT | atl.cpp:1006:8:1006:9 | s9 | |
1022+
| atl.cpp:1004:24:1004:25 | call to CSimpleStringT | atl.cpp:1011:1:1011:1 | s9 | |
1023+
| atl.cpp:1005:3:1005:4 | ref arg s9 | atl.cpp:1006:8:1006:9 | s9 | |
1024+
| atl.cpp:1005:3:1005:4 | ref arg s9 | atl.cpp:1011:1:1011:1 | s9 | |
9491025
| bsd.cpp:17:11:17:16 | call to source | bsd.cpp:20:18:20:18 | s | |
9501026
| bsd.cpp:18:12:18:15 | addr | bsd.cpp:20:22:20:25 | addr | |
9511027
| bsd.cpp:18:12:18:15 | addr | bsd.cpp:23:8:23:11 | addr | |

cpp/ql/test/library-tests/dataflow/taint-tests/test_mad-signatures.expected

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ signatureMatches
8383
| atl.cpp:846:15:846:27 | SetSchemeName | (LPCTSTR) | _U_STRINGorID | _U_STRINGorID | 0 |
8484
| atl.cpp:847:15:847:24 | SetUrlPath | (LPCTSTR) | _U_STRINGorID | _U_STRINGorID | 0 |
8585
| atl.cpp:848:15:848:25 | SetUserName | (LPCTSTR) | _U_STRINGorID | _U_STRINGorID | 0 |
86+
| atl.cpp:921:8:921:13 | Append | (LPCOLESTR,int) | CComBSTR | Append | 1 |
87+
| atl.cpp:938:8:938:16 | SetString | (LPCOLESTR,int) | CComBSTR | Append | 1 |
8688
| constructor_delegation.cpp:10:2:10:8 | MyValue | (LPCOLESTR,int) | CComBSTR | Append | 1 |
8789
| constructor_delegation.cpp:19:2:19:15 | MyDerivedValue | (LPCOLESTR,int) | CComBSTR | Append | 1 |
8890
| standalone_iterators.cpp:103:27:103:36 | operator+= | (LPCOLESTR,int) | CComBSTR | Append | 1 |
@@ -670,6 +672,37 @@ getParameterTypeName
670672
| atl.cpp:846:15:846:27 | SetSchemeName | 0 | LPCTSTR |
671673
| atl.cpp:847:15:847:24 | SetUrlPath | 0 | LPCTSTR |
672674
| atl.cpp:848:15:848:25 | SetUserName | 0 | LPCTSTR |
675+
| atl.cpp:903:8:903:8 | operator= | 0 | IAtlStringMgr && |
676+
| atl.cpp:903:8:903:8 | operator= | 0 | const IAtlStringMgr & |
677+
| atl.cpp:914:3:914:16 | CSimpleStringT | 0 | const XCHAR * |
678+
| atl.cpp:914:3:914:16 | CSimpleStringT | 1 | int |
679+
| atl.cpp:914:3:914:16 | CSimpleStringT | 2 | IAtlStringMgr * |
680+
| atl.cpp:915:3:915:16 | CSimpleStringT | 0 | PCXSTR |
681+
| atl.cpp:915:3:915:16 | CSimpleStringT | 1 | IAtlStringMgr * |
682+
| atl.cpp:916:3:916:16 | CSimpleStringT | 0 | const CSimpleStringT & |
683+
| atl.cpp:920:8:920:13 | Append | 0 | const CSimpleStringT & |
684+
| atl.cpp:921:8:921:13 | Append | 0 | PCXSTR |
685+
| atl.cpp:921:8:921:13 | Append | 1 | int |
686+
| atl.cpp:922:8:922:13 | Append | 0 | PCXSTR |
687+
| atl.cpp:926:15:926:23 | CopyChars | 0 | XCHAR * |
688+
| atl.cpp:926:15:926:23 | CopyChars | 1 | const XCHAR * |
689+
| atl.cpp:926:15:926:23 | CopyChars | 2 | int |
690+
| atl.cpp:927:15:927:23 | CopyChars | 0 | XCHAR * |
691+
| atl.cpp:927:15:927:23 | CopyChars | 1 | size_t |
692+
| atl.cpp:927:15:927:23 | CopyChars | 2 | const XCHAR * |
693+
| atl.cpp:927:15:927:23 | CopyChars | 3 | int |
694+
| atl.cpp:928:15:928:33 | CopyCharsOverlapped | 0 | XCHAR * |
695+
| atl.cpp:928:15:928:33 | CopyCharsOverlapped | 1 | const XCHAR * |
696+
| atl.cpp:928:15:928:33 | CopyCharsOverlapped | 2 | int |
697+
| atl.cpp:930:9:930:13 | GetAt | 0 | int |
698+
| atl.cpp:931:9:931:17 | GetBuffer | 0 | int |
699+
| atl.cpp:933:9:933:26 | GetBufferSetLength | 0 | int |
700+
| atl.cpp:937:8:937:12 | SetAt | 0 | int |
701+
| atl.cpp:937:8:937:12 | SetAt | 1 | XCHAR |
702+
| atl.cpp:938:8:938:16 | SetString | 0 | PCXSTR |
703+
| atl.cpp:938:8:938:16 | SetString | 1 | int |
704+
| atl.cpp:939:8:939:16 | SetString | 0 | PCXSTR |
705+
| atl.cpp:941:9:941:18 | operator[] | 0 | int |
673706
| bsd.cpp:6:8:6:8 | operator= | 0 | const sockaddr & |
674707
| bsd.cpp:6:8:6:8 | operator= | 0 | sockaddr && |
675708
| bsd.cpp:12:5:12:10 | accept | 0 | int |

0 commit comments

Comments
 (0)