Skip to content

Commit 6f64129

Browse files
committed
C++: Add ComPtr tests.
1 parent b7c1e1e commit 6f64129

File tree

3 files changed

+254
-0
lines changed

3 files changed

+254
-0
lines changed

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

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,4 +1241,134 @@ namespace ATL {
12411241
sink(static_cast<CStrBufT<char>::PCXSTR>(b)); // $ ir
12421242
sink(static_cast<CStrBufT<char>::PXSTR>(b)); // $ ir
12431243
}
1244+
}
1245+
1246+
namespace Microsoft {
1247+
namespace WRL {
1248+
template <typename T>
1249+
class ComPtr;
1250+
1251+
struct GUID;
1252+
1253+
typedef GUID IID;
1254+
1255+
typedef IID *REFIID;
1256+
1257+
class IUnknown;
1258+
1259+
class WeakRef;
1260+
1261+
template <typename T>
1262+
class ComPtr
1263+
{
1264+
public:
1265+
using InterfaceType = T;
1266+
1267+
ComPtr();
1268+
ComPtr(const ComPtr &);
1269+
ComPtr(&&other);
1270+
1271+
template <typename U>
1272+
ComPtr(U *);
1273+
1274+
~ComPtr();
1275+
1276+
template <typename U>
1277+
HRESULT As(ComPtr<U> *p) const;
1278+
1279+
HRESULT AsWeak(WeakRef *);
1280+
1281+
void Attach(InterfaceType *);
1282+
1283+
HRESULT CopyTo(InterfaceType **);
1284+
1285+
HRESULT CopyTo(REFIID, void **) const;
1286+
1287+
template <typename U>
1288+
HRESULT CopyTo(U **) const;
1289+
1290+
T *Detach();
1291+
1292+
T *Get() const;
1293+
1294+
T *const *GetAddressOf() const;
1295+
T **GetAddressOf();
1296+
1297+
T **ReleaseAndGetAddressOf();
1298+
1299+
unsigned long Reset();
1300+
1301+
void Swap(ComPtr &&r);
1302+
1303+
void Swap(ComPtr &r);
1304+
};
1305+
1306+
}
1307+
}
1308+
1309+
namespace std {
1310+
template<class T> T&& move(T& t) noexcept; // simplified signature
1311+
}
1312+
1313+
void test_constructor()
1314+
{
1315+
Microsoft::WRL::ComPtr<int> p0;
1316+
sink(*p0.Get()); // clean
1317+
1318+
int x = source<int>();
1319+
Microsoft::WRL::ComPtr<int> p1(new int(x));
1320+
sink(*p1.Get()); // $ MISSING: ast,ir
1321+
sink(*p1.Detach()); // $ MISSING: ast,ir
1322+
1323+
Microsoft::WRL::ComPtr<int> p2(p1);
1324+
sink(*p2.Get()); // $ MISSING: ast,ir
1325+
1326+
Microsoft::WRL::ComPtr<int> p3(std::move(p1));
1327+
sink(*p3.Get()); // $ MISSING: ast,ir
1328+
}
1329+
1330+
void test_As()
1331+
{
1332+
int x = source<int>();
1333+
Microsoft::WRL::ComPtr<int> p1(new int(x));
1334+
Microsoft::WRL::ComPtr<int> p2;
1335+
p1.As(&p2);
1336+
sink(*p2.Get()); // $ MISSING: ast,ir
1337+
}
1338+
1339+
void test_CopyTo()
1340+
{
1341+
int x = source<int>();
1342+
Microsoft::WRL::ComPtr<int> p1(new int(x));
1343+
int *raw = nullptr;
1344+
p1.CopyTo(&raw);
1345+
sink(*raw); // $ MISSING: ast,ir
1346+
1347+
Microsoft::WRL::ComPtr<int> p2;
1348+
p1.CopyTo(nullptr, (void**)&raw);
1349+
sink(*raw); // $ MISSING: ast,ir
1350+
}
1351+
1352+
void test_Swap()
1353+
{
1354+
int x = source<int>();
1355+
Microsoft::WRL::ComPtr<int> p1(new int(x));
1356+
Microsoft::WRL::ComPtr<int> p2;
1357+
p1.Swap(p2);
1358+
sink(*p2.Get()); // $ MISSING: ast,ir
1359+
sink(*p1.Get()); // clean
1360+
}
1361+
1362+
void test_GetAddressOf()
1363+
{
1364+
int x = source<int>();
1365+
Microsoft::WRL::ComPtr<int> p1(new int(x));
1366+
sink(**p1.GetAddressOf()); // $ MISSING: ast,ir
1367+
1368+
const Microsoft::WRL::ComPtr<int> p2(new int(x));
1369+
sink(**p2.GetAddressOf()); // $ MISSING: ast,ir
1370+
1371+
Microsoft::WRL::ComPtr<int> p3(new int(x));
1372+
int **pp = p3.ReleaseAndGetAddressOf();
1373+
sink(**pp); // $ MISSING: ast,ir
12441374
}

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

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,6 +1278,118 @@ WARNING: module 'TaintTracking' has been deprecated and may be removed in future
12781278
| atl.cpp:1240:22:1240:30 | call to CStrBufT | atl.cpp:1241:46:1241:46 | b | |
12791279
| atl.cpp:1240:22:1240:30 | call to CStrBufT | atl.cpp:1242:45:1242:45 | b | |
12801280
| atl.cpp:1241:46:1241:46 | ref arg b | atl.cpp:1242:45:1242:45 | b | |
1281+
| atl.cpp:1315:31:1315:32 | call to ComPtr | atl.cpp:1316:9:1316:10 | p0 | |
1282+
| atl.cpp:1315:31:1315:32 | call to ComPtr | atl.cpp:1328:1:1328:1 | p0 | |
1283+
| atl.cpp:1316:9:1316:10 | ref arg p0 | atl.cpp:1328:1:1328:1 | p0 | |
1284+
| atl.cpp:1316:12:1316:14 | call to Get | atl.cpp:1316:8:1316:16 | * ... | TAINT |
1285+
| atl.cpp:1318:11:1318:21 | call to source | atl.cpp:1319:42:1319:42 | x | |
1286+
| atl.cpp:1319:34:1319:43 | new | atl.cpp:1319:34:1319:44 | call to ComPtr | TAINT |
1287+
| atl.cpp:1319:34:1319:44 | call to ComPtr | atl.cpp:1320:9:1320:10 | p1 | |
1288+
| atl.cpp:1319:34:1319:44 | call to ComPtr | atl.cpp:1321:9:1321:10 | p1 | |
1289+
| atl.cpp:1319:34:1319:44 | call to ComPtr | atl.cpp:1323:34:1323:35 | p1 | |
1290+
| atl.cpp:1319:34:1319:44 | call to ComPtr | atl.cpp:1326:44:1326:45 | p1 | |
1291+
| atl.cpp:1319:34:1319:44 | call to ComPtr | atl.cpp:1328:1:1328:1 | p1 | |
1292+
| atl.cpp:1319:42:1319:42 | x | atl.cpp:1319:34:1319:43 | new | |
1293+
| atl.cpp:1320:9:1320:10 | ref arg p1 | atl.cpp:1321:9:1321:10 | p1 | |
1294+
| atl.cpp:1320:9:1320:10 | ref arg p1 | atl.cpp:1323:34:1323:35 | p1 | |
1295+
| atl.cpp:1320:9:1320:10 | ref arg p1 | atl.cpp:1326:44:1326:45 | p1 | |
1296+
| atl.cpp:1320:9:1320:10 | ref arg p1 | atl.cpp:1328:1:1328:1 | p1 | |
1297+
| atl.cpp:1320:12:1320:14 | call to Get | atl.cpp:1320:8:1320:16 | * ... | TAINT |
1298+
| atl.cpp:1321:9:1321:10 | ref arg p1 | atl.cpp:1323:34:1323:35 | p1 | |
1299+
| atl.cpp:1321:9:1321:10 | ref arg p1 | atl.cpp:1326:44:1326:45 | p1 | |
1300+
| atl.cpp:1321:9:1321:10 | ref arg p1 | atl.cpp:1328:1:1328:1 | p1 | |
1301+
| atl.cpp:1321:12:1321:17 | call to Detach | atl.cpp:1321:8:1321:19 | * ... | TAINT |
1302+
| atl.cpp:1323:34:1323:35 | p1 | atl.cpp:1323:34:1323:36 | call to ComPtr | |
1303+
| atl.cpp:1323:34:1323:36 | call to ComPtr | atl.cpp:1324:9:1324:10 | p2 | |
1304+
| atl.cpp:1323:34:1323:36 | call to ComPtr | atl.cpp:1328:1:1328:1 | p2 | |
1305+
| atl.cpp:1324:9:1324:10 | ref arg p2 | atl.cpp:1328:1:1328:1 | p2 | |
1306+
| atl.cpp:1324:12:1324:14 | call to Get | atl.cpp:1324:8:1324:16 | * ... | TAINT |
1307+
| atl.cpp:1326:34:1326:42 | call to move | atl.cpp:1326:34:1326:47 | call to ComPtr | TAINT |
1308+
| atl.cpp:1326:34:1326:47 | call to ComPtr | atl.cpp:1327:9:1327:10 | p3 | |
1309+
| atl.cpp:1326:34:1326:47 | call to ComPtr | atl.cpp:1328:1:1328:1 | p3 | |
1310+
| atl.cpp:1326:44:1326:45 | p1 | atl.cpp:1326:34:1326:42 | call to move | TAINT |
1311+
| atl.cpp:1326:44:1326:45 | p1 | atl.cpp:1326:34:1326:47 | call to ComPtr | |
1312+
| atl.cpp:1327:9:1327:10 | ref arg p3 | atl.cpp:1328:1:1328:1 | p3 | |
1313+
| atl.cpp:1327:12:1327:14 | call to Get | atl.cpp:1327:8:1327:16 | * ... | TAINT |
1314+
| atl.cpp:1332:11:1332:21 | call to source | atl.cpp:1333:42:1333:42 | x | |
1315+
| atl.cpp:1333:34:1333:43 | new | atl.cpp:1333:34:1333:44 | call to ComPtr | TAINT |
1316+
| atl.cpp:1333:34:1333:44 | call to ComPtr | atl.cpp:1335:3:1335:4 | p1 | |
1317+
| atl.cpp:1333:34:1333:44 | call to ComPtr | atl.cpp:1337:1:1337:1 | p1 | |
1318+
| atl.cpp:1333:42:1333:42 | x | atl.cpp:1333:34:1333:43 | new | |
1319+
| atl.cpp:1334:31:1334:32 | call to ComPtr | atl.cpp:1335:10:1335:11 | p2 | |
1320+
| atl.cpp:1334:31:1334:32 | call to ComPtr | atl.cpp:1336:9:1336:10 | p2 | |
1321+
| atl.cpp:1334:31:1334:32 | call to ComPtr | atl.cpp:1337:1:1337:1 | p2 | |
1322+
| atl.cpp:1335:9:1335:11 | ref arg & ... | atl.cpp:1335:10:1335:11 | p2 [inner post update] | |
1323+
| atl.cpp:1335:9:1335:11 | ref arg & ... | atl.cpp:1336:9:1336:10 | p2 | |
1324+
| atl.cpp:1335:9:1335:11 | ref arg & ... | atl.cpp:1337:1:1337:1 | p2 | |
1325+
| atl.cpp:1335:10:1335:11 | p2 | atl.cpp:1335:9:1335:11 | & ... | |
1326+
| atl.cpp:1336:9:1336:10 | ref arg p2 | atl.cpp:1337:1:1337:1 | p2 | |
1327+
| atl.cpp:1336:12:1336:14 | call to Get | atl.cpp:1336:8:1336:16 | * ... | TAINT |
1328+
| atl.cpp:1341:11:1341:21 | call to source | atl.cpp:1342:42:1342:42 | x | |
1329+
| atl.cpp:1342:34:1342:43 | new | atl.cpp:1342:34:1342:44 | call to ComPtr | TAINT |
1330+
| atl.cpp:1342:34:1342:44 | call to ComPtr | atl.cpp:1344:3:1344:4 | p1 | |
1331+
| atl.cpp:1342:34:1342:44 | call to ComPtr | atl.cpp:1348:3:1348:4 | p1 | |
1332+
| atl.cpp:1342:34:1342:44 | call to ComPtr | atl.cpp:1350:1:1350:1 | p1 | |
1333+
| atl.cpp:1342:42:1342:42 | x | atl.cpp:1342:34:1342:43 | new | |
1334+
| atl.cpp:1343:14:1343:20 | 0 | atl.cpp:1344:14:1344:16 | raw | |
1335+
| atl.cpp:1343:14:1343:20 | 0 | atl.cpp:1345:9:1345:11 | raw | |
1336+
| atl.cpp:1343:14:1343:20 | 0 | atl.cpp:1348:31:1348:33 | raw | |
1337+
| atl.cpp:1343:14:1343:20 | 0 | atl.cpp:1349:9:1349:11 | raw | |
1338+
| atl.cpp:1344:3:1344:4 | ref arg p1 | atl.cpp:1348:3:1348:4 | p1 | |
1339+
| atl.cpp:1344:3:1344:4 | ref arg p1 | atl.cpp:1350:1:1350:1 | p1 | |
1340+
| atl.cpp:1344:13:1344:16 | ref arg & ... | atl.cpp:1344:14:1344:16 | raw [inner post update] | |
1341+
| atl.cpp:1344:13:1344:16 | ref arg & ... | atl.cpp:1345:9:1345:11 | raw | |
1342+
| atl.cpp:1344:13:1344:16 | ref arg & ... | atl.cpp:1348:31:1348:33 | raw | |
1343+
| atl.cpp:1344:13:1344:16 | ref arg & ... | atl.cpp:1349:9:1349:11 | raw | |
1344+
| atl.cpp:1344:14:1344:16 | raw | atl.cpp:1344:13:1344:16 | & ... | |
1345+
| atl.cpp:1345:9:1345:11 | raw | atl.cpp:1345:8:1345:11 | * ... | TAINT |
1346+
| atl.cpp:1347:31:1347:32 | call to ComPtr | atl.cpp:1350:1:1350:1 | p2 | |
1347+
| atl.cpp:1348:30:1348:33 | ref arg & ... | atl.cpp:1348:31:1348:33 | raw [inner post update] | |
1348+
| atl.cpp:1348:30:1348:33 | ref arg & ... | atl.cpp:1349:9:1349:11 | raw | |
1349+
| atl.cpp:1348:31:1348:33 | raw | atl.cpp:1348:30:1348:33 | & ... | |
1350+
| atl.cpp:1349:9:1349:11 | raw | atl.cpp:1349:8:1349:11 | * ... | TAINT |
1351+
| atl.cpp:1354:11:1354:21 | call to source | atl.cpp:1355:42:1355:42 | x | |
1352+
| atl.cpp:1355:34:1355:43 | new | atl.cpp:1355:34:1355:44 | call to ComPtr | TAINT |
1353+
| atl.cpp:1355:34:1355:44 | call to ComPtr | atl.cpp:1357:3:1357:4 | p1 | |
1354+
| atl.cpp:1355:34:1355:44 | call to ComPtr | atl.cpp:1359:9:1359:10 | p1 | |
1355+
| atl.cpp:1355:34:1355:44 | call to ComPtr | atl.cpp:1360:1:1360:1 | p1 | |
1356+
| atl.cpp:1355:42:1355:42 | x | atl.cpp:1355:34:1355:43 | new | |
1357+
| atl.cpp:1356:31:1356:32 | call to ComPtr | atl.cpp:1357:11:1357:12 | p2 | |
1358+
| atl.cpp:1356:31:1356:32 | call to ComPtr | atl.cpp:1358:9:1358:10 | p2 | |
1359+
| atl.cpp:1356:31:1356:32 | call to ComPtr | atl.cpp:1360:1:1360:1 | p2 | |
1360+
| atl.cpp:1357:3:1357:4 | ref arg p1 | atl.cpp:1359:9:1359:10 | p1 | |
1361+
| atl.cpp:1357:3:1357:4 | ref arg p1 | atl.cpp:1360:1:1360:1 | p1 | |
1362+
| atl.cpp:1357:11:1357:12 | ref arg p2 | atl.cpp:1358:9:1358:10 | p2 | |
1363+
| atl.cpp:1357:11:1357:12 | ref arg p2 | atl.cpp:1360:1:1360:1 | p2 | |
1364+
| atl.cpp:1358:9:1358:10 | ref arg p2 | atl.cpp:1360:1:1360:1 | p2 | |
1365+
| atl.cpp:1358:12:1358:14 | call to Get | atl.cpp:1358:8:1358:16 | * ... | TAINT |
1366+
| atl.cpp:1359:9:1359:10 | ref arg p1 | atl.cpp:1360:1:1360:1 | p1 | |
1367+
| atl.cpp:1359:12:1359:14 | call to Get | atl.cpp:1359:8:1359:16 | * ... | TAINT |
1368+
| atl.cpp:1364:11:1364:21 | call to source | atl.cpp:1365:42:1365:42 | x | |
1369+
| atl.cpp:1364:11:1364:21 | call to source | atl.cpp:1368:48:1368:48 | x | |
1370+
| atl.cpp:1364:11:1364:21 | call to source | atl.cpp:1371:42:1371:42 | x | |
1371+
| atl.cpp:1365:34:1365:43 | new | atl.cpp:1365:34:1365:44 | call to ComPtr | TAINT |
1372+
| atl.cpp:1365:34:1365:44 | call to ComPtr | atl.cpp:1366:10:1366:11 | p1 | |
1373+
| atl.cpp:1365:34:1365:44 | call to ComPtr | atl.cpp:1374:1:1374:1 | p1 | |
1374+
| atl.cpp:1365:42:1365:42 | x | atl.cpp:1365:34:1365:43 | new | |
1375+
| atl.cpp:1366:9:1366:26 | * ... | atl.cpp:1366:8:1366:26 | * ... | TAINT |
1376+
| atl.cpp:1366:10:1366:11 | ref arg p1 | atl.cpp:1374:1:1374:1 | p1 | |
1377+
| atl.cpp:1366:13:1366:24 | call to GetAddressOf | atl.cpp:1366:9:1366:26 | * ... | TAINT |
1378+
| atl.cpp:1368:40:1368:49 | new | atl.cpp:1368:40:1368:50 | call to ComPtr | TAINT |
1379+
| atl.cpp:1368:40:1368:50 | call to ComPtr | atl.cpp:1369:10:1369:11 | p2 | |
1380+
| atl.cpp:1368:40:1368:50 | call to ComPtr | atl.cpp:1374:1:1374:1 | p2 | |
1381+
| atl.cpp:1368:48:1368:48 | x | atl.cpp:1368:40:1368:49 | new | |
1382+
| atl.cpp:1369:9:1369:26 | * ... | atl.cpp:1369:8:1369:26 | * ... | TAINT |
1383+
| atl.cpp:1369:10:1369:11 | ref arg p2 | atl.cpp:1374:1:1374:1 | p2 | |
1384+
| atl.cpp:1369:13:1369:24 | call to GetAddressOf | atl.cpp:1369:9:1369:26 | * ... | TAINT |
1385+
| atl.cpp:1371:34:1371:43 | new | atl.cpp:1371:34:1371:44 | call to ComPtr | TAINT |
1386+
| atl.cpp:1371:34:1371:44 | call to ComPtr | atl.cpp:1372:14:1372:15 | p3 | |
1387+
| atl.cpp:1371:34:1371:44 | call to ComPtr | atl.cpp:1374:1:1374:1 | p3 | |
1388+
| atl.cpp:1371:42:1371:42 | x | atl.cpp:1371:34:1371:43 | new | |
1389+
| atl.cpp:1372:14:1372:15 | ref arg p3 | atl.cpp:1374:1:1374:1 | p3 | |
1390+
| atl.cpp:1372:17:1372:38 | call to ReleaseAndGetAddressOf | atl.cpp:1373:10:1373:11 | pp | |
1391+
| atl.cpp:1373:9:1373:11 | * ... | atl.cpp:1373:8:1373:11 | * ... | TAINT |
1392+
| atl.cpp:1373:10:1373:11 | pp | atl.cpp:1373:9:1373:11 | * ... | TAINT |
12811393
| bsd.cpp:17:11:17:16 | call to source | bsd.cpp:20:18:20:18 | s | |
12821394
| bsd.cpp:18:12:18:15 | addr | bsd.cpp:20:22:20:25 | addr | |
12831395
| 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5567,6 +5567,8 @@ signatureMatches
55675567
| atl.cpp:1231:5:1231:12 | CStrBufT | (const char *,const char *,unsigned long) | | __ngettext | 2 |
55685568
| atl.cpp:1231:5:1231:12 | CStrBufT | (unsigned char *,int,unsigned long) | | UTF8_putc | 1 |
55695569
| atl.cpp:1231:5:1231:12 | CStrBufT | (unsigned char *,int,unsigned long) | | UTF8_putc | 2 |
5570+
| atl.cpp:1285:13:1285:18 | CopyTo | (Curl_easy *,void **) | | Curl_resolver_init | 1 |
5571+
| atl.cpp:1285:13:1285:18 | CopyTo | (size_t,void **) | | __libc_alloc_buffer_allocate | 1 |
55705572
| bsd.cpp:12:5:12:10 | accept | (CURLM *,curl_socket_t,int *) | | curl_multi_socket | 2 |
55715573
| bsd.cpp:12:5:12:10 | accept | (Curl_easy *,ssize_t *,int *) | | Curl_GetFTPResponse | 2 |
55725574
| bsd.cpp:12:5:12:10 | accept | (EVP_CIPHER_CTX *,unsigned char *,int *) | | EVP_CipherFinal | 2 |
@@ -46404,6 +46406,16 @@ getParameterTypeName
4640446406
| atl.cpp:1231:5:1231:12 | CStrBufT | 1 | int |
4640546407
| atl.cpp:1231:5:1231:12 | CStrBufT | 2 | DWORD |
4640646408
| atl.cpp:1231:5:1231:12 | CStrBufT | 2 | unsigned long |
46409+
| atl.cpp:1268:5:1268:10 | ComPtr | 0 | const ComPtr & |
46410+
| atl.cpp:1272:5:1272:10 | ComPtr | 0 | func:0 * |
46411+
| atl.cpp:1277:13:1277:14 | As | 0 | ComPtr * |
46412+
| atl.cpp:1283:13:1283:18 | CopyTo | 0 | Interfaceclass:0ype ** |
46413+
| atl.cpp:1283:13:1283:18 | CopyTo | 0 | class:0 ** |
46414+
| atl.cpp:1285:13:1285:18 | CopyTo | 0 | GUID * |
46415+
| atl.cpp:1285:13:1285:18 | CopyTo | 0 | REFIID |
46416+
| atl.cpp:1285:13:1285:18 | CopyTo | 1 | void ** |
46417+
| atl.cpp:1303:10:1303:13 | Swap | 0 | ComPtr & |
46418+
| atl.cpp:1310:25:1310:28 | move | 0 | func:0 & |
4640746419
| bsd.cpp:6:8:6:8 | operator= | 0 | const sockaddr & |
4640846420
| bsd.cpp:6:8:6:8 | operator= | 0 | sockaddr && |
4640946421
| bsd.cpp:12:5:12:10 | accept | 0 | int |

0 commit comments

Comments
 (0)