Skip to content

Commit 9c2d961

Browse files
committed
C++: Fix another expression of stdin / stdout we see in practice.
1 parent d77ba02 commit 9c2d961

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class Recv extends SendRecv instanceof RemoteFlowSourceFunction {
105105
* practice it usually isn't very important which query reports a result as
106106
* long as its reported exactly once.
107107
*
108-
* We do exclude function calls that specify a constant socket, which is
109-
* likely to mean standard input, standard output or a similar channel.
108+
* We do exclude function calls that specify an apparently constant socket,
109+
* which is likely to mean standard input, standard output or a similar channel.
110110
*/
111111
abstract class NetworkSendRecv extends FunctionCall {
112112
SendRecv target;
@@ -125,6 +125,16 @@ abstract class NetworkSendRecv extends FunctionCall {
125125
v.getInitializer().getExpr() instanceof Literal and
126126
g = globalValueNumber(v.getAnAccess())
127127
)
128+
or
129+
// result of a function call with literal inputs (likely constant)
130+
exists(FunctionCall fc |
131+
forex(Expr arg |
132+
arg = fc.getAnArgument() |
133+
arg instanceof Literal
134+
) and
135+
g = globalValueNumber(fc)
136+
)
137+
// (this is far from exhaustive)
128138
)
129139
)
130140
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ edges
3737
| test3.cpp:214:8:214:15 | password | test3.cpp:217:30:217:37 | password |
3838
| test3.cpp:214:8:214:15 | password | test3.cpp:219:15:219:26 | password_ptr |
3939
| test3.cpp:217:18:217:28 | call to rtn_encrypt | test3.cpp:219:15:219:26 | password_ptr |
40-
| test3.cpp:225:34:225:41 | password | test3.cpp:227:22:227:29 | password |
4140
| test3.cpp:225:34:225:41 | password | test3.cpp:228:26:228:33 | password |
4241
| test3.cpp:239:7:239:14 | password | test3.cpp:241:8:241:15 | password |
4342
| test3.cpp:239:7:239:14 | password | test3.cpp:242:8:242:15 | password |
@@ -147,7 +146,6 @@ nodes
147146
| test3.cpp:217:30:217:37 | password | semmle.label | password |
148147
| test3.cpp:219:15:219:26 | password_ptr | semmle.label | password_ptr |
149148
| test3.cpp:225:34:225:41 | password | semmle.label | password |
150-
| test3.cpp:227:22:227:29 | password | semmle.label | password |
151149
| test3.cpp:228:26:228:33 | password | semmle.label | password |
152150
| test3.cpp:239:7:239:14 | password | semmle.label | password |
153151
| test3.cpp:241:8:241:15 | password | semmle.label | password |
@@ -225,7 +223,6 @@ subpaths
225223
| test3.cpp:140:3:140:6 | call to send | test3.cpp:129:39:129:47 | password1 | test3.cpp:140:15:140:17 | ptr | This operation transmits 'ptr', which may contain unencrypted sensitive data from $@ | test3.cpp:129:39:129:47 | password1 | password1 |
226224
| test3.cpp:146:3:146:6 | call to send | test3.cpp:126:9:126:23 | global_password | test3.cpp:146:15:146:18 | data | This operation transmits 'data', which may contain unencrypted sensitive data from $@ | test3.cpp:126:9:126:23 | global_password | global_password |
227225
| test3.cpp:159:3:159:6 | call to send | test3.cpp:152:29:152:36 | password | test3.cpp:159:15:159:20 | buffer | This operation transmits 'buffer', which may contain unencrypted sensitive data from $@ | test3.cpp:152:29:152:36 | password | password |
228-
| test3.cpp:227:2:227:5 | call to send | test3.cpp:225:34:225:41 | password | test3.cpp:227:22:227:29 | password | This operation transmits 'password', which may contain unencrypted sensitive data from $@ | test3.cpp:225:34:225:41 | password | password |
229226
| test3.cpp:228:2:228:5 | call to send | test3.cpp:225:34:225:41 | password | test3.cpp:228:26:228:33 | password | This operation transmits 'password', which may contain unencrypted sensitive data from $@ | test3.cpp:225:34:225:41 | password | password |
230227
| test3.cpp:241:2:241:6 | call to fgets | test3.cpp:239:7:239:14 | password | test3.cpp:241:8:241:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:239:7:239:14 | password | password |
231228
| test3.cpp:242:2:242:6 | call to fgets | test3.cpp:239:7:239:14 | password | test3.cpp:242:8:242:15 | password | This operation receives into 'password', which may put unencrypted sensitive data into $@ | test3.cpp:239:7:239:14 | password | password |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ int get_socket(int from);
224224

225225
void test_more_stdio(const char *password)
226226
{
227-
send(get_socket(1), password, 128, val()); // GOOD: `getsocket(1)` is probably standard output [FALSE POSITIVE]
227+
send(get_socket(1), password, 128, val()); // GOOD: `getsocket(1)` is probably standard output
228228
send(get_socket(val()), password, 128, val()); // BAD
229229
}
230230

0 commit comments

Comments
 (0)