Skip to content

Commit 0bb9a95

Browse files
committed
C++: Extend tests.
1 parent e3493e3 commit 0bb9a95

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ 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:93:28:93:36 | http:// | test.cpp:104:11:104:13 | ptr |
11+
| test.cpp:104:11:104:13 | ptr | test.cpp:11:26:11:28 | url |
12+
| test.cpp:110:21:110:40 | http://example.com | test.cpp:121:11:121:13 | ptr |
13+
| test.cpp:121:11:121:13 | ptr | test.cpp:11:26:11:28 | url |
1014
nodes
1115
| test.cpp:11:26:11:28 | url | semmle.label | url |
1216
| test.cpp:15:30:15:32 | url | semmle.label | url |
@@ -17,9 +21,15 @@ nodes
1721
| test.cpp:40:11:40:17 | access to array | semmle.label | access to array |
1822
| test.cpp:46:18:46:26 | http:// | semmle.label | http:// |
1923
| test.cpp:49:11:49:16 | buffer | semmle.label | buffer |
24+
| test.cpp:93:28:93:36 | http:// | semmle.label | http:// |
25+
| test.cpp:104:11:104:13 | ptr | semmle.label | ptr |
26+
| test.cpp:110:21:110:40 | http://example.com | semmle.label | http://example.com |
27+
| test.cpp:121:11:121:13 | ptr | semmle.label | ptr |
2028
subpaths
2129
#select
2230
| 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. |
2331
| 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. |
2432
| 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. |
2533
| 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. |
34+
| test.cpp:93:28:93:36 | http:// | test.cpp:93:28:93:36 | http:// | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
35+
| test.cpp:110:21:110:40 | http://example.com | test.cpp:110:21:110:40 | http://example.com | 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: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void test3(char *url)
7575
{
7676
char *ptr;
7777

78-
ptr = strstr(url, "https://");
78+
ptr = strstr(url, "https://"); // GOOD (https)
7979
if (!ptr)
8080
{
8181
ptr = strstr(url, "http://"); // GOOD (we are not constructing the URL)
@@ -86,3 +86,38 @@ void test3(char *url)
8686
openUrl(ptr);
8787
}
8888
}
89+
90+
void test4(char *url)
91+
{
92+
const char *https_string = "https://"; // GOOD (https)
93+
const char *http_string = "http://"; // GOOD (we are not constructing the URL) [FALSE POSITIVE]
94+
char *ptr;
95+
96+
ptr = strstr(url, https_string);
97+
if (!ptr)
98+
{
99+
ptr = strstr(url, http_string);
100+
}
101+
102+
if (ptr)
103+
{
104+
openUrl(ptr);
105+
}
106+
}
107+
108+
void test5()
109+
{
110+
char *url_string = "http://example.com"; // BAD
111+
char *ptr;
112+
113+
ptr = strstr(url_string, "https://"); // GOOD (https)
114+
if (!ptr)
115+
{
116+
ptr = strstr(url_string, "http://"); // GOOD (we are not constructing the URL here)
117+
}
118+
119+
if (ptr)
120+
{
121+
openUrl(ptr);
122+
}
123+
}

0 commit comments

Comments
 (0)