Skip to content

Commit 6388ac5

Browse files
committed
C++: Add tests.
1 parent d2b18d9 commit 6388ac5

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
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 |
6+
nodes
7+
| test.cpp:11:20:11:22 | url | semmle.label | url |
8+
| test.cpp:15:30:15:32 | url | semmle.label | url |
9+
| 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 |
12+
subpaths
13+
#select
14+
| 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. |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE/CWE-319/UseOfHttp.ql
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
struct host
3+
{
4+
// ...
5+
};
6+
7+
host gethostbyname(char *str);
8+
char *strcpy(char *s1, const char *s2);
9+
char *strcat(char *s1, const char *s2);
10+
11+
void openUrl(char *url)
12+
{
13+
// ...
14+
15+
host myHost = gethostbyname(url);
16+
17+
// ...
18+
}
19+
20+
void doNothing(char *url)
21+
{
22+
}
23+
24+
char *urls[] = { "http://example.com" };
25+
26+
void test()
27+
{
28+
openUrl("http://example.com"); // BAD
29+
openUrl("https://example.com"); // GOOD (https)
30+
openUrl("http://localhost/example"); // GOOD (localhost)
31+
openUrl("https://localhost/example"); // GOOD (https, localhost)
32+
doNothing("http://example.com"); // GOOD (URL not used)
33+
openUrl(urls[0]); // BAD [NOT DETECTED]
34+
35+
{
36+
char buffer[1024];
37+
38+
strcpy(buffer, "http://"); // BAD
39+
strcat(buffer, "example.com");
40+
41+
openUrl(buffer);
42+
}
43+
44+
{
45+
char buffer[1024];
46+
47+
strcpy(buffer, "https://"); // GOOD (https)
48+
strcat(buffer, "example.com");
49+
50+
openUrl(buffer);
51+
}
52+
}

0 commit comments

Comments
 (0)