Skip to content

Commit 652f903

Browse files
committed
C++: Add simple dataflow to the query.
1 parent 7500d75 commit 652f903

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414
import cpp
1515
import semmle.code.cpp.security.SensitiveExprs
1616
import semmle.code.cpp.security.FileWrite
17+
import semmle.code.cpp.dataflow.DataFlow
1718

1819
from FileWrite w, SensitiveExpr source, Expr dest
1920
where
20-
source = w.getASource() and
21+
DataFlow::localFlow(DataFlow::exprNode(source), DataFlow::exprNode(w.getASource())) and
2122
dest = w.getDest()
2223
select w, "This write into file '" + dest.toString() + "' may contain unencrypted data from $@",
2324
source, "this source."
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
| test2.cpp:28:2:28:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:28:36:28:43 | password | this source. |
22
| test2.cpp:29:2:29:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:29:37:29:45 | thepasswd | this source. |
33
| test2.cpp:30:2:30:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:30:38:30:47 | accountkey | this source. |
4+
| test2.cpp:40:3:40:9 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:37:18:37:25 | password | this source. |
45
| test.cpp:45:3:45:7 | call to fputs | This write into file 'file' may contain unencrypted data from $@ | test.cpp:45:9:45:19 | thePassword | this source. |
56
| test.cpp:70:35:70:35 | call to operator<< | This write into file 'mystream' may contain unencrypted data from $@ | test.cpp:70:38:70:48 | thePassword | this source. |
67
| test.cpp:73:37:73:41 | call to write | This write into file 'mystream' may contain unencrypted data from $@ | test.cpp:73:43:73:53 | thePassword | this source. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void tests(FILE *log, myStruct &s)
3737
char *cpy1 = s.password;
3838
char *cpy2 = crypt(s.password);
3939

40-
fprintf(log, "cpy1 = %s\n", cpy1); // BAD [NOT DETECTED]
40+
fprintf(log, "cpy1 = %s\n", cpy1); // BAD
4141
fprintf(log, "cpy2 = %s\n", cpy2); // GOOD
4242
}
4343

0 commit comments

Comments
 (0)