Skip to content

Commit e5e8a1b

Browse files
committed
C++: Exclude integral types from SensitiveExprs.
1 parent dd95c53 commit e5e8a1b

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

cpp/ql/src/semmle/code/cpp/security/SensitiveExprs.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ private predicate suspicious(string s) {
2727
* A variable that might contain a password or other sensitive information.
2828
*/
2929
class SensitiveVariable extends Variable {
30-
SensitiveVariable() { suspicious(getName().toLowerCase()) }
30+
SensitiveVariable() {
31+
suspicious(getName().toLowerCase()) and
32+
not this.getUnspecifiedType() instanceof IntegralType
33+
}
3134
}
3235

3336
/**
3437
* A function that might return a password or other sensitive information.
3538
*/
3639
class SensitiveFunction extends Function {
37-
SensitiveFunction() { suspicious(getName().toLowerCase()) }
40+
SensitiveFunction() {
41+
suspicious(getName().toLowerCase()) and
42+
not this.getUnspecifiedType() instanceof IntegralType
43+
}
3844
}
3945

4046
/**

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
| test2.cpp:35:2:35:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:35:36:35:43 | password | this source. |
22
| test2.cpp:36:2:36:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:36:37:36:45 | thepasswd | this source. |
33
| test2.cpp:41:2:41:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:41:41:41:53 | passwd_config | this source. |
4-
| test2.cpp:42:2:42:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:42:41:42:53 | num_passwords | this source. |
5-
| test2.cpp:43:2:43:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:43:39:43:49 | have_passwd | this source. |
64
| test2.cpp:45:2:45:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:45:39:45:49 | call to getPassword | this source. |
7-
| test2.cpp:47:2:47:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:47:47:47:65 | call to getPasswordMaxChars | this source. |
85
| test2.cpp:53:3:53:9 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:50:18:50:25 | password | this source. |
96
| 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. |
107
| 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. |

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ void tests(FILE *log, myStruct &s)
3939
fprintf(log, "encrypted_passwd = %s\n", s.encrypted_passwd); // GOOD
4040
fprintf(log, "password_file = %s\n", s.password_file); // GOOD
4141
fprintf(log, "passwd_config = %s\n", s.passwd_config); // DUBIOUS [REPORTED]
42-
fprintf(log, "num_passwords = %i\n", s.num_passwords); // GOOD [FALSE POSITIVE]
43-
fprintf(log, "have_passwd = %i\n", s.have_passwd); // GOOD [FALSE POSITIVE]
42+
fprintf(log, "num_passwords = %i\n", s.num_passwords); // GOOD
43+
fprintf(log, "have_passwd = %i\n", s.have_passwd); // GOOD
4444

4545
fprintf(log, "getPassword() = %i\n", getPassword()); // BAD
4646
fprintf(log, "getPasswordHash() = %i\n", getPasswordHash()); // GOOD
47-
fprintf(log, "getPasswordMaxChars() = %i\n", getPasswordMaxChars()); // GOOD [FALSE POSITIVE]
47+
fprintf(log, "getPasswordMaxChars() = %i\n", getPasswordMaxChars()); // GOOD
4848

4949
{
5050
char *cpy1 = s.password;

0 commit comments

Comments
 (0)