Skip to content

Commit 13ae15b

Browse files
committed
C++: Add tests for more edge cases.
1 parent 8f9ad1f commit 13ae15b

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

cpp/ql/test/query-tests/Security/CWE/CWE-290/semmle/AuthenticationBypass/AuthenticationBypass.expected

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ edges
1717
| test.cpp:38:25:38:42 | (const char *)... | test.cpp:42:14:42:20 | address |
1818
| test.cpp:38:25:38:42 | (const char *)... | test.cpp:42:14:42:20 | address |
1919
| test.cpp:38:25:38:42 | (const char *)... | test.cpp:42:14:42:20 | address indirection |
20+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:52:14:52:20 | address |
21+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:52:14:52:20 | address |
22+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:52:14:52:20 | address indirection |
23+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:56:14:56:20 | address |
24+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:56:14:56:20 | address |
25+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:56:14:56:20 | address indirection |
26+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:60:14:60:20 | address |
27+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:60:14:60:20 | address |
28+
| test.cpp:49:25:49:30 | call to getenv | test.cpp:60:14:60:20 | address indirection |
29+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:52:14:52:20 | address |
30+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:52:14:52:20 | address |
31+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:52:14:52:20 | address indirection |
32+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:56:14:56:20 | address |
33+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:56:14:56:20 | address |
34+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:56:14:56:20 | address indirection |
35+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:60:14:60:20 | address |
36+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:60:14:60:20 | address |
37+
| test.cpp:49:25:49:42 | (const char *)... | test.cpp:60:14:60:20 | address indirection |
2038
subpaths
2139
nodes
2240
| test.cpp:16:25:16:30 | call to getenv | semmle.label | call to getenv |
@@ -34,7 +52,21 @@ nodes
3452
| test.cpp:42:14:42:20 | address | semmle.label | address |
3553
| test.cpp:42:14:42:20 | address | semmle.label | address |
3654
| test.cpp:42:14:42:20 | address indirection | semmle.label | address indirection |
55+
| test.cpp:49:25:49:30 | call to getenv | semmle.label | call to getenv |
56+
| test.cpp:49:25:49:42 | (const char *)... | semmle.label | (const char *)... |
57+
| test.cpp:52:14:52:20 | address | semmle.label | address |
58+
| test.cpp:52:14:52:20 | address | semmle.label | address |
59+
| test.cpp:52:14:52:20 | address indirection | semmle.label | address indirection |
60+
| test.cpp:56:14:56:20 | address | semmle.label | address |
61+
| test.cpp:56:14:56:20 | address | semmle.label | address |
62+
| test.cpp:56:14:56:20 | address indirection | semmle.label | address indirection |
63+
| test.cpp:60:14:60:20 | address | semmle.label | address |
64+
| test.cpp:60:14:60:20 | address | semmle.label | address |
65+
| test.cpp:60:14:60:20 | address indirection | semmle.label | address indirection |
3766
#select
3867
| test.cpp:20:7:20:12 | call to strcmp | test.cpp:16:25:16:30 | call to getenv | test.cpp:20:14:20:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:16:25:16:30 | call to getenv | call to getenv |
3968
| test.cpp:31:7:31:12 | call to strcmp | test.cpp:27:25:27:30 | call to getenv | test.cpp:31:14:31:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:27:25:27:30 | call to getenv | call to getenv |
4069
| test.cpp:42:7:42:12 | call to strcmp | test.cpp:38:25:38:30 | call to getenv | test.cpp:42:14:42:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:38:25:38:30 | call to getenv | call to getenv |
70+
| test.cpp:52:7:52:12 | call to strcmp | test.cpp:49:25:49:30 | call to getenv | test.cpp:52:14:52:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:49:25:49:30 | call to getenv | call to getenv |
71+
| test.cpp:56:7:56:12 | call to strcmp | test.cpp:49:25:49:30 | call to getenv | test.cpp:56:14:56:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:49:25:49:30 | call to getenv | call to getenv |
72+
| test.cpp:60:7:60:12 | call to strcmp | test.cpp:49:25:49:30 | call to getenv | test.cpp:60:14:60:20 | address | Untrusted input $@ might be vulnerable to a spoofing attack. | test.cpp:49:25:49:30 | call to getenv | call to getenv |

cpp/ql/test/query-tests/Security/CWE/CWE-290/semmle/AuthenticationBypass/test.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,27 @@ void processRequest3()
4343
isServer = 1;
4444
}
4545
}
46+
47+
void processRequest4()
48+
{
49+
const char *address = getenv("SERVERIP");
50+
bool cond = false;
51+
52+
if (strcmp(address, "127.0.0.1")) { cond = true; } // BAD
53+
if (strcmp(address, "127_0_0_1")) { cond = true; } // GOOD (not an IP)
54+
if (strcmp(address, "127.0.0")) { cond = true; } // GOOD (not an IP)
55+
if (strcmp(address, "127.0.0.0.1")) { cond = true; } // GOOD (not an IP)
56+
if (strcmp(address, "http://mycompany")) { cond = true; } // BAD
57+
if (strcmp(address, "http_//mycompany")) { cond = true; } // GOOD (not an address)
58+
if (strcmp(address, "htt://mycompany")) { cond = true; } // GOOD (not an address)
59+
if (strcmp(address, "httpp://mycompany")) { cond = true; } // GOOD (not an address)
60+
if (strcmp(address, "mycompany.com")) { cond = true; } // BAD
61+
if (strcmp(address, "mycompany_com")) { cond = true; } // GOOD (not an address)
62+
if (strcmp(address, "mycompany.c")) { cond = true; } // GOOD (not an address)
63+
if (strcmp(address, "mycompany.comm")) { cond = true; } // GOOD (not an address)
64+
65+
if (cond) {
66+
isServer = 1;
67+
}
68+
}
69+

0 commit comments

Comments
 (0)