Skip to content

Commit 901919f

Browse files
committed
C++: Add tests expanding on the issue with (global) variables.
1 parent 43ff3b1 commit 901919f

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed
Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
edges
2-
| test.cpp:11:20:11:22 | url | test.cpp:15:30:15:32 | url |
3-
| test.cpp:28:10:28:29 | http://example.com | test.cpp:11:20:11:22 | url |
4-
| test.cpp:38:18:38:26 | http:// | test.cpp:41:11:41:16 | buffer |
5-
| test.cpp:41:11:41:16 | buffer | test.cpp:11:20:11:22 | url |
2+
| test.cpp:11:26:11:28 | url | test.cpp:15:30:15:32 | url |
3+
| test.cpp:28:10:28:29 | http://example.com | test.cpp:11:26:11:28 | url |
4+
| test.cpp:35:23:35:42 | http://example.com | test.cpp:39:11:39:15 | url_l |
5+
| test.cpp:36:26:36:45 | http://example.com | test.cpp:40:11:40:17 | access to array |
6+
| test.cpp:39:11:39:15 | url_l | test.cpp:11:26:11:28 | url |
7+
| test.cpp:40:11:40:17 | access to array | test.cpp:11:26:11:28 | url |
8+
| test.cpp:46:18:46:26 | http:// | test.cpp:49:11:49:16 | buffer |
9+
| test.cpp:49:11:49:16 | buffer | test.cpp:11:26:11:28 | url |
610
nodes
7-
| test.cpp:11:20:11:22 | url | semmle.label | url |
11+
| test.cpp:11:26:11:28 | url | semmle.label | url |
812
| test.cpp:15:30:15:32 | url | semmle.label | url |
913
| test.cpp:28:10:28:29 | http://example.com | semmle.label | http://example.com |
10-
| test.cpp:38:18:38:26 | http:// | semmle.label | http:// |
11-
| test.cpp:41:11:41:16 | buffer | semmle.label | buffer |
14+
| test.cpp:35:23:35:42 | http://example.com | semmle.label | http://example.com |
15+
| test.cpp:36:26:36:45 | http://example.com | semmle.label | http://example.com |
16+
| test.cpp:39:11:39:15 | url_l | semmle.label | url_l |
17+
| test.cpp:40:11:40:17 | access to array | semmle.label | access to array |
18+
| test.cpp:46:18:46:26 | http:// | semmle.label | http:// |
19+
| test.cpp:49:11:49:16 | buffer | semmle.label | buffer |
1220
subpaths
1321
#select
1422
| 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. |
15-
| test.cpp:38:18:38:26 | http:// | test.cpp:38:18:38:26 | http:// | test.cpp:15:30:15:32 | url | A URL may be constructed with the HTTP protocol. |
23+
| 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. |
24+
| 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. |
25+
| 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. |

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ struct host
44
// ...
55
};
66

7-
host gethostbyname(char *str);
7+
host gethostbyname(const char *str);
88
char *strcpy(char *s1, const char *s2);
99
char *strcat(char *s1, const char *s2);
1010

11-
void openUrl(char *url)
11+
void openUrl(const char *url)
1212
{
1313
// ...
1414

@@ -21,7 +21,7 @@ void doNothing(char *url)
2121
{
2222
}
2323

24-
char *urls[] = { "http://example.com" };
24+
const char *url_g = "http://example.com"; // BAD [NOT DETECTED]
2525

2626
void test()
2727
{
@@ -30,7 +30,15 @@ void test()
3030
openUrl("http://localhost/example"); // GOOD (localhost)
3131
openUrl("https://localhost/example"); // GOOD (https, localhost)
3232
doNothing("http://example.com"); // GOOD (URL not used)
33-
openUrl(urls[0]); // BAD [NOT DETECTED]
33+
34+
{
35+
const char *url_l = "http://example.com"; // BAD
36+
const char *urls[] = { "http://example.com" }; // BAD
37+
38+
openUrl(url_g);
39+
openUrl(url_l);
40+
openUrl(urls[0]);
41+
}
3442

3543
{
3644
char buffer[1024];

0 commit comments

Comments
 (0)