Skip to content

Commit c16302b

Browse files
committed
C++: Fix the FP.
1 parent 326dfa5 commit c16302b

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

cpp/ql/src/Security/CWE/CWE-319/UseOfHttp.ql

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ class HttpStringToUrlOpenConfig extends TaintTracking::Configuration {
5757

5858
override predicate isSource(DataFlow::Node src) {
5959
// Sources are strings containing an HTTP URL not in a private domain.
60-
src.asExpr() instanceof HttpStringLiteral
60+
src.asExpr() instanceof HttpStringLiteral and
61+
// block taint starting at `strstr`, which is likely testing an existing URL, rather than constructing an HTTP URL.
62+
not exists(FunctionCall fc |
63+
fc.getTarget().getName() = ["strstr", "strcasestr"] and
64+
fc.getAnArgument() = src.asExpr()
65+
)
6166
}
6267

6368
override predicate isSink(DataFlow::Node sink) {

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ 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 |
1210
nodes
1311
| test.cpp:11:26:11:28 | url | semmle.label | url |
1412
| test.cpp:15:30:15:32 | url | semmle.label | url |
@@ -19,12 +17,9 @@ nodes
1917
| test.cpp:40:11:40:17 | access to array | semmle.label | access to array |
2018
| test.cpp:46:18:46:26 | http:// | semmle.label | http:// |
2119
| 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 |
2420
subpaths
2521
#select
2622
| 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. |
2723
| 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. |
2824
| 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. |
2925
| 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void test3(char *url)
7878
ptr = strstr(url, "https://");
7979
if (!ptr)
8080
{
81-
ptr = strstr(url, "http://"); // GOOD (we are not constructing the URL) [FALSE POSITIVE]
81+
ptr = strstr(url, "http://"); // GOOD (we are not constructing the URL)
8282
}
8383

8484
if (ptr)

0 commit comments

Comments
 (0)