|
| 1 | + |
| 2 | +#define FILE int |
| 3 | + |
| 4 | +typedef unsigned long size_t; |
| 5 | + |
| 6 | +FILE *fopen(const char *filename, const char *mode); |
| 7 | +int snprintf(char *s, size_t n, const char *format, ...); |
| 8 | +int fprintf(FILE *stream, const char *format, ...); |
| 9 | +char *strcpy(char *s1, const char *s2); |
| 10 | + |
| 11 | +char *crypt(char *input); |
| 12 | + |
| 13 | +struct myStruct |
| 14 | +{ |
| 15 | + // sensitive |
| 16 | + char *password; |
| 17 | + char *thepasswd; |
| 18 | + char *accountkey; |
| 19 | + wchar_t *widepassword; |
| 20 | + |
| 21 | + // encrypted |
| 22 | + char password_hash[64]; |
| 23 | + char *encrypted_passwd; |
| 24 | + |
| 25 | + // not sensitive |
| 26 | + char *password_file; |
| 27 | + char *password_path; |
| 28 | + int num_passwords; |
| 29 | + int *password_tries; |
| 30 | + bool have_passwd; |
| 31 | + |
| 32 | + // dubious |
| 33 | + char *passwd_config; |
| 34 | + char *passwd_config2; |
| 35 | +}; |
| 36 | + |
| 37 | +char *getPassword(); |
| 38 | +char *getPasswordHash(); |
| 39 | +int getPasswordMaxChars(); |
| 40 | + |
| 41 | +void tests(FILE *log, myStruct &s) |
| 42 | +{ |
| 43 | + fprintf(log, "password = %s\n", s.password); // BAD |
| 44 | + fprintf(log, "thepasswd = %s\n", s.thepasswd); // BAD |
| 45 | + fprintf(log, "accountkey = %s\n", s.accountkey); // DUBIOUS [NOT REPORTED] |
| 46 | + fprintf(log, "password_hash = %s\n", s.password_hash); // GOOD |
| 47 | + fprintf(log, "encrypted_passwd = %s\n", s.encrypted_passwd); // GOOD |
| 48 | + fprintf(log, "password_file = %s\n", s.password_file); // GOOD |
| 49 | + fprintf(log, "password_path = %s\n", s.password_path); // GOOD |
| 50 | + fprintf(log, "passwd_config = %s\n", s.passwd_config); // DUBIOUS [REPORTED] |
| 51 | + fprintf(log, "num_passwords = %i\n", s.num_passwords); // GOOD |
| 52 | + fprintf(log, "password_tries = %i\n", *(s.password_tries)); // GOOD |
| 53 | + fprintf(log, "have_passwd = %i\n", s.have_passwd); // GOOD |
| 54 | + fprintf(log, "widepassword = %ls\n", s.widepassword); // BAD |
| 55 | + fprintf(log, "widepassword = %S\n", s.widepassword); // BAD |
| 56 | + |
| 57 | + fprintf(log, "getPassword() = %s\n", getPassword()); // BAD |
| 58 | + fprintf(log, "getPasswordHash() = %s\n", getPasswordHash()); // GOOD |
| 59 | + fprintf(log, "getPasswordMaxChars() = %i\n", getPasswordMaxChars()); // GOOD |
| 60 | + |
| 61 | + { |
| 62 | + char *cpy1 = s.password; |
| 63 | + char *cpy2 = crypt(s.password); |
| 64 | + |
| 65 | + fprintf(log, "cpy1 = %s\n", cpy1); // BAD |
| 66 | + fprintf(log, "cpy2 = %s\n", cpy2); // GOOD |
| 67 | + } |
| 68 | + |
| 69 | + { |
| 70 | + char buf[1024]; |
| 71 | + |
| 72 | + strcpy(buf, s.password); |
| 73 | + fprintf(log, "buf = %s\n", buf); // BAD [NOT DETECTED] |
| 74 | + |
| 75 | + strcpy(buf, s.password_hash); |
| 76 | + fprintf(log, "buf = %s\n", buf); // GOOD |
| 77 | + } |
| 78 | + |
| 79 | + fprintf(log, "password = %p\n", s.password); // GOOD |
| 80 | + |
| 81 | + { |
| 82 | + if (fopen(s.passwd_config2, "rt") == 0) |
| 83 | + { |
| 84 | + fprintf(log, "could not open file '%s'.\n", s.passwd_config2); // GOOD |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + { |
| 89 | + char buffer[1024]; |
| 90 | + |
| 91 | + snprintf(buffer, 1024, "password = %s", s.password); |
| 92 | + fprintf(log, "log: %s", buffer); // BAD [NOT DETECTED] |
| 93 | + } |
| 94 | +} |
0 commit comments