Skip to content

Commit 1339533

Browse files
committed
C++: More test cases.
1 parent 6aec7f2 commit 1339533

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
| 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. |
2+
| 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. |
3+
| 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:31:2:31:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:31:41:31:53 | password_hash | this source. |
5+
| test2.cpp:33:2:33:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:33:41:33:53 | password_file | this source. |
6+
| test2.cpp:34:2:34:8 | call to fprintf | This write into file 'log' may contain unencrypted data from $@ | test2.cpp:34:41:34:53 | passwd_config | this source. |
17
| 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. |
28
| 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. |
39
| 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. |
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
#define FILE int
3+
4+
int fprintf(FILE *stream, const char *format, ...);
5+
char *strcpy(char *s1, const char *s2);
6+
7+
char *crypt(char *input);
8+
9+
struct myStruct
10+
{
11+
// sensitive
12+
char *password;
13+
char *thepasswd;
14+
char *accountkey;
15+
16+
// encrypted
17+
char password_hash[64];
18+
char *encrypted_passwd;
19+
20+
// not sensitive
21+
char *password_file;
22+
char *passwd_config;
23+
24+
};
25+
26+
void tests(FILE *log, myStruct &s)
27+
{
28+
fprintf(log, "password = %s\n", s.password); // BAD
29+
fprintf(log, "thepasswd = %s\n", s.thepasswd); // BAD
30+
fprintf(log, "accountkey = %s\n", s.accountkey); // BAD
31+
fprintf(log, "password_hash = %s\n", s.password_hash); // GOOD
32+
fprintf(log, "encrypted_passwd = %s\n", s.encrypted_passwd); // GOOD
33+
fprintf(log, "password_file = %s\n", s.password_file); // GOOD
34+
fprintf(log, "passwd_config = %s\n", s.passwd_config); // GOOD
35+
36+
{
37+
char *cpy1 = s.password;
38+
char *cpy2 = crypt(s.password);
39+
40+
fprintf(log, "cpy1 = %s\n", cpy1); // BAD
41+
fprintf(log, "cpy2 = %s\n", cpy2); // GOOD
42+
}
43+
44+
{
45+
char buf[1024];
46+
47+
strcpy(buf, s.password);
48+
fprintf(log, "buf = %s\n", buf); // BAD
49+
50+
strcpy(buf, s.password_hash);
51+
fprintf(log, "buf = %s\n", buf); // GOOD
52+
}
53+
}
54+

0 commit comments

Comments
 (0)