Skip to content

Commit cd5a534

Browse files
committed
C++: Add basic test.
1 parent 2463024 commit cd5a534

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| test3.cpp:39:3:39:6 | call to recv | test3.cpp:39:15:39:22 | password |
2+
| test3.cpp:47:3:47:6 | call to recv | test3.cpp:47:15:47:22 | password |
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Security/CWE/CWE-311/CleartextTransmission.ql
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
2+
typedef unsigned long size_t;
3+
4+
size_t strlen(const char *s);
5+
6+
void send(int a, const void *buf, size_t bufLen, int d);
7+
void recv(int a, void *buf, size_t bufLen, int d);
8+
9+
void LogonUserA(int a, int b, const char *password, int d, int e, int f);
10+
11+
int val();
12+
13+
void test_send(const char *password1, const char *password2, const char *password_hash, const char *message)
14+
{
15+
{
16+
LogonUserA(val(), val(), password1, val(), val(), val()); // proof `password` is plaintext
17+
18+
send(val(), password1, strlen(password1), val()); // BAD: `password` is sent plaintext (certainly) [NOT DETECTED]
19+
}
20+
21+
{
22+
send(val(), password2, strlen(password2), val()); // BAD: `password` is sent plaintext (probably) [NOT DETECTED]
23+
}
24+
25+
{
26+
send(val(), password_hash, strlen(password_hash), val()); // GOOD: `password` is sent encrypted
27+
}
28+
29+
{
30+
send(val(), message, strlen(message), val()); // GOOD: `message` is not a password
31+
}
32+
}
33+
34+
void test_receive()
35+
{
36+
{
37+
char password[256];
38+
39+
recv(val(), password, 256, val()); // BAD: `password` is received plaintext (certainly)
40+
41+
LogonUserA(val(), val(), password, val(), val(), val()); // (proof `password` is plaintext)
42+
}
43+
44+
{
45+
char password[256];
46+
47+
recv(val(), password, 256, val()); // BAD: `password` is received plaintext (probably)
48+
}
49+
50+
{
51+
char password_hash[256];
52+
53+
recv(val(), password_hash, 256, val()); // GOOD: `password` is received encrypted
54+
}
55+
56+
{
57+
char message[256];
58+
59+
recv(val(), message, 256, val()); // GOOD: `message` is not a password
60+
}
61+
}

0 commit comments

Comments
 (0)