Skip to content

Commit 326dfa5

Browse files
committed
C++: Add test cases.
1 parent 5ee9612 commit 326dfa5

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-319/UseOfHttp/UseOfHttp.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ edges
77
| test.cpp:40:11:40:17 | access to array | test.cpp:11:26:11:28 | url |
88
| test.cpp:46:18:46:26 | http:// | test.cpp:49:11:49:16 | buffer |
99
| test.cpp:49:11:49:16 | buffer | test.cpp:11:26:11:28 | url |
10+
| test.cpp:81:21:81:29 | http:// | test.cpp:86:11:86:13 | ptr |
11+
| test.cpp:86:11:86:13 | ptr | test.cpp:11:26:11:28 | url |
1012
nodes
1113
| test.cpp:11:26:11:28 | url | semmle.label | url |
1214
| test.cpp:15:30:15:32 | url | semmle.label | url |
@@ -17,9 +19,12 @@ nodes
1719
| test.cpp:40:11:40:17 | access to array | semmle.label | access to array |
1820
| test.cpp:46:18:46:26 | http:// | semmle.label | http:// |
1921
| test.cpp:49:11:49:16 | buffer | semmle.label | buffer |
22+
| test.cpp:81:21:81:29 | http:// | semmle.label | http:// |
23+
| test.cpp:86:11:86:13 | ptr | semmle.label | ptr |
2024
subpaths
2125
#select
2226
| test.cpp:28:10:28:29 | http://example.com | test.cpp:28:10:28:29 | http://example.com | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
2327
| test.cpp:35:23:35:42 | http://example.com | test.cpp:35:23:35:42 | http://example.com | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
2428
| test.cpp:36:26:36:45 | http://example.com | test.cpp:36:26:36:45 | http://example.com | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
2529
| test.cpp:46:18:46:26 | http:// | test.cpp:46:18:46:26 | http:// | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
30+
| test.cpp:81:21:81:29 | http:// | test.cpp:81:21:81:29 | http:// | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |

cpp/ql/test/query-tests/Security/CWE/CWE-319/UseOfHttp/test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,31 @@ void test()
5858
openUrl(buffer);
5959
}
6060
}
61+
62+
typedef unsigned long size_t;
63+
int strncmp(const char *s1, const char *s2, size_t n);
64+
char* strstr(char* s1, const char* s2);
65+
66+
void test2(const char *url)
67+
{
68+
if (strncmp(url, "http://", 7)) // GOOD (or at least dubious; we are not constructing the URL)
69+
{
70+
openUrl(url);
71+
}
72+
}
73+
74+
void test3(char *url)
75+
{
76+
char *ptr;
77+
78+
ptr = strstr(url, "https://");
79+
if (!ptr)
80+
{
81+
ptr = strstr(url, "http://"); // GOOD (we are not constructing the URL) [FALSE POSITIVE]
82+
}
83+
84+
if (ptr)
85+
{
86+
openUrl(ptr);
87+
}
88+
}

0 commit comments

Comments
 (0)