File tree Expand file tree Collapse file tree 3 files changed +68
-0
lines changed
cpp/ql/test/query-tests/Security/CWE/CWE-319/UseOfHttp Expand file tree Collapse file tree 3 files changed +68
-0
lines changed Original file line number Diff line number Diff line change 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. |
Original file line number Diff line number Diff line change 1+ Security/CWE/CWE-319/UseOfHttp.ql
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments