Skip to content

Commit 3ba9e80

Browse files
committed
C++: Support various functions / variants.
1 parent 1707d67 commit 3ba9e80

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

cpp/ql/src/Security/CWE/CWE-311/CleartextTransmission.ql

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ abstract class NetworkSendRecv extends FunctionCall {
3333
* note: functions such as `read` may be reading from a network source or a file. We could attempt to determine which, and sort results into `cpp/cleartext-transmission` and perhaps `cpp/cleartext-storage-file`. In practice it probably isn't very important which query reports a result as long as its reported exactly once.
3434
*/
3535
class NetworkSend extends NetworkSendRecv {
36-
NetworkSend() { this.getTarget().hasGlobalName("send") }
36+
NetworkSend() {
37+
this.getTarget()
38+
.hasGlobalName(["send", "sendto", "sendmsg", "write", "writev", "pwritev", "pwritev2"])
39+
}
3740

3841
override Expr getDataExpr() { result = this.getArgument(1) }
3942
}
@@ -42,7 +45,12 @@ class NetworkSend extends NetworkSendRecv {
4245
* A function call that receives data over a network.
4346
*/
4447
class NetworkRecv extends NetworkSendRecv {
45-
NetworkRecv() { this.getTarget().hasGlobalName("recv") }
48+
NetworkRecv() {
49+
this.getTarget()
50+
.hasGlobalName([
51+
"recv", "recvfrom", "recvmsg", "read", "pread", "readv", "preadv", "preadv2"
52+
])
53+
}
4654

4755
override Expr getDataExpr() { result = this.getArgument(1) }
4856
}

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/CleartextTransmission.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
| test3.cpp:49:3:49:6 | call to recv | test3.cpp:49:15:49:22 | password |
55
| test3.cpp:70:3:70:6 | call to send | test3.cpp:68:21:68:29 | password1 |
66
| test3.cpp:77:3:77:6 | call to recv | test3.cpp:75:15:75:22 | password |
7+
| test3.cpp:95:3:95:6 | call to read | test3.cpp:95:12:95:19 | password |
8+
| test3.cpp:102:3:102:6 | call to read | test3.cpp:102:12:102:19 | password |

cpp/ql/test/query-tests/Security/CWE/CWE-311/semmle/tests/test3.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ void test_read()
9292
char password[256];
9393
int fd = val();
9494

95-
read(fd, password, 256); // BAD: `password` is received plaintext [NOT DETECTED]
95+
read(fd, password, 256); // BAD: `password` is received plaintext
9696
}
9797

9898
{
9999
char password[256];
100100
int fd = STDIN_FILENO;
101101

102-
read(fd, password, 256); // GOOD: `password` is received from stdin, not a network socket
102+
read(fd, password, 256); // GOOD: `password` is received from stdin, not a network socket [FALSE POSITIVE]
103103
}
104104
}
105105

0 commit comments

Comments
 (0)