Flawfinder version 2.0.10, (C) 2001-2019 David A. Wheeler. Number of rules (primarily dangerous function names) in C/C++ ruleset: 223 Examining data/twoftpd-1.42/log.h Examining data/twoftpd-1.42/responses.c Examining data/twoftpd-1.42/store.c Examining data/twoftpd-1.42/strtou.c Examining data/twoftpd-1.42/twoftpd-xfer.c Examining data/twoftpd-1.42/twoftpd-anon.c Examining data/twoftpd-1.42/twoftpd.h Examining data/twoftpd-1.42/retr.c Examining data/twoftpd-1.42/twoftpd-drop.c Examining data/twoftpd-1.42/banner.c Examining data/twoftpd-1.42/backend.c Examining data/twoftpd-1.42/backend.h Examining data/twoftpd-1.42/conf.c Examining data/twoftpd-1.42/conf.h Examining data/twoftpd-1.42/copy.c Examining data/twoftpd-1.42/list.c Examining data/twoftpd-1.42/log.c Examining data/twoftpd-1.42/main.c Examining data/twoftpd-1.42/messagefile.c Examining data/twoftpd-1.42/path.c Examining data/twoftpd-1.42/respond.c Examining data/twoftpd-1.42/socket.c Examining data/twoftpd-1.42/stat.c Examining data/twoftpd-1.42/state.c Examining data/twoftpd-1.42/statmod.c Examining data/twoftpd-1.42/twoftpd-anon-conf.c Examining data/twoftpd-1.42/twoftpd-auth.c Examining data/twoftpd-1.42/twoftpd-bind-port.c Examining data/twoftpd-1.42/twoftpd-conf.c Examining data/twoftpd-1.42/twoftpd-switch.c FINAL RESULTS: data/twoftpd-1.42/store.c:149:7: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. if (chmod(fullpath.s+1, mode) != 0) data/twoftpd-1.42/twoftpd-anon-conf.c:77:7: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. if (chmod(maindir, 01755) == -1) data/twoftpd-1.42/twoftpd-anon-conf.c:81:7: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. if (chown(logdir, loguid, loggid) == -1) data/twoftpd-1.42/twoftpd-conf.c:68:7: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. if (chmod(maindir, 01755) == -1) data/twoftpd-1.42/twoftpd-conf.c:72:7: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. if (chown(logdir, logacct->pw_uid, logacct->pw_gid) == -1) data/twoftpd-1.42/state.c:61:9: [4] (race) access: This usually indicates a security flaw. If an attacker can change anything along the path between the call to access() and the file's actual use (e.g., by moving files), the attacker can exploit the race condition (CWE-362/CWE-367!). Set up the correct permissions (e.g., using setuid()) and try to open the file directly. if (access(fullpath.s+1, X_OK) == -1) data/twoftpd-1.42/twoftpd-auth.c:40:5: [4] (shell) execvp: This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available. execvp(argv_xfer[0], argv_xfer); data/twoftpd-1.42/twoftpd-bind-port.c:132:5: [4] (shell) execvp: This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available. execvp(argv[1], argv+1); data/twoftpd-1.42/twoftpd-switch.c:32:3: [4] (buffer) strcpy: Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120). Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused). strcpy(cmd, conf_bin); data/twoftpd-1.42/twoftpd-switch.c:34:3: [4] (buffer) strcpy: Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120). Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused). strcpy(cmd + sizeof conf_bin + 8, name); data/twoftpd-1.42/twoftpd-switch.c:35:3: [4] (shell) execv: This causes a new program to execute and is difficult to use safely (CWE-78). try using a library call that implements the same functionality if available. execv(cmd, argv); data/twoftpd-1.42/backend.c:88:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("TCPLOCALIP")) == 0) FAIL("Missing $TCPLOCALIP."); data/twoftpd-1.42/backend.c:90:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("TCPREMOTEIP")) == 0) FAIL("Missing $TCPREMOTEIP."); data/twoftpd-1.42/backend.c:92:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("UID")) == 0) FAIL("Missing $UID."); data/twoftpd-1.42/backend.c:94:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("GID")) == 0) FAIL("Missing $GID."); data/twoftpd-1.42/backend.c:96:15: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((home = getenv("HOME")) == 0) FAIL("Missing $HOME."); data/twoftpd-1.42/backend.c:97:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("GIDS")) != 0 && !parse_gids(tmp)) data/twoftpd-1.42/backend.c:104:15: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((user = getenv("USER")) == 0) FAIL("Missing $USER."); data/twoftpd-1.42/backend.c:105:16: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((group = getenv("GROUP")) == 0) group = "mygroup"; data/twoftpd-1.42/backend.c:108:7: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if (getenv("CHROOT") != 0) { data/twoftpd-1.42/backend.c:110:9: [3] (misc) chroot: chroot can be very helpful, but is hard to use correctly (CWE-250, CWE-22). Make sure the program immediately chdir("/"), closes file descriptors, and drops root privileges, and that all necessary files (and no more!) are in the new root. if (chroot(".")) FAIL("Could not chroot."); data/twoftpd-1.42/backend.c:112:12: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. else if (getenv("SOFTCHROOT") != 0) { data/twoftpd-1.42/backend.c:131:15: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. lockhome = (getenv("LOCKHOME") != 0); data/twoftpd-1.42/backend.c:132:17: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. nodotfiles = (getenv("NODOTFILES") != 0); data/twoftpd-1.42/backend.c:136:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("SESSION_TIMEOUT")) != 0) data/twoftpd-1.42/backend.c:140:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("CONNECT_TIMEOUT")) != 0) data/twoftpd-1.42/backend.c:143:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("TWOFTPD_BIND_PORT_FD")) != 0) { data/twoftpd-1.42/backend.c:150:19: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. startup_code = (getenv("AUTHENTICATED") != 0) ? 230 : 220; data/twoftpd-1.42/backend.c:151:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("BANNER")) != 0) show_banner(startup_code, tmp); data/twoftpd-1.42/backend.c:152:18: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. message_file = getenv("MESSAGEFILE"); data/twoftpd-1.42/main.c:204:18: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. log_requests = getenv("LOGREQUESTS") != 0; data/twoftpd-1.42/main.c:205:19: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. log_responses = getenv("LOGRESPONSES") != 0; data/twoftpd-1.42/main.c:207:9: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. tmp = getenv("TIMEOUT"); data/twoftpd-1.42/twoftpd-auth.c:55:49: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if (cvm_authenticate_password(cvmodule, user, getenv("TCPLOCALHOST"), data/twoftpd-1.42/twoftpd-auth.c:92:8: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if (!getenv("SERVICE") && putenv("SERVICE=ftp") == -1) { data/twoftpd-1.42/twoftpd-auth.c:97:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("LOGINBANNER")) != 0) show_banner(220, tmp); data/twoftpd-1.42/twoftpd-auth.c:100:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("AUTH_TIMEOUT")) != 0) auth_timeout = strtou(tmp, &tmp); data/twoftpd-1.42/twoftpd-auth.c:104:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("AUTH_ATTEMPTS")) != 0) data/twoftpd-1.42/twoftpd-bind-port.c:97:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("TCPLOCALIP")) == 0 || data/twoftpd-1.42/twoftpd-bind-port.c:104:14: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((tmp = getenv("TWOFTPD_BIND_PORT")) != 0) { data/twoftpd-1.42/twoftpd-switch.c:44:16: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((shell = getenv("SHELL")) != 0) { data/twoftpd-1.42/twoftpd-switch.c:45:16: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((env = getenv("SHELL_WRITEONLY")) != 0 data/twoftpd-1.42/twoftpd-switch.c:48:16: [3] (buffer) getenv: Environment variables are untrustable input if they can be set by an attacker. They can have any content and length, and the same variable can be set more than once (CWE-807, CWE-20). Check environment variables carefully before using them. if ((env = getenv("SHELL_READONLY")) != 0 data/twoftpd-1.42/copy.c:94:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char in_buf[iobuf_bufsize]; data/twoftpd-1.42/copy.c:95:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char out_buf[sizeof in_buf * 2]; data/twoftpd-1.42/list.c:39:10: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. static char buf[11]; data/twoftpd-1.42/list.c:103:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buf[16]; data/twoftpd-1.42/list.c:164:8: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. static char send_buf[8192]; data/twoftpd-1.42/list.c:178:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(send_buf + send_used, s->s, s->len); data/twoftpd-1.42/list.c:288:2: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char tmp[2]; data/twoftpd-1.42/main.c:26:8: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. static char request[BUFSIZE]; data/twoftpd-1.42/main.c:95:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char byte[1]; data/twoftpd-1.42/messagefile.c:31:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buf[1024]; data/twoftpd-1.42/path.c:74:13: [2] (misc) open: Check when opening files - can an attacker redirect it (via symlinks), force the opening of special file type (e.g., device files), move things around to create a race condition, control its ancestors, or change its contents? (CWE-362). if ((fd = open(fullpath.s+1, flags, mode)) == -1) return -1; data/twoftpd-1.42/socket.c:262:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buffer[6*4+25]; data/twoftpd-1.42/stat.c:27:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buffer[40]; data/twoftpd-1.42/stat.c:39:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char buffer[16]; data/twoftpd-1.42/twoftpd-switch.c:30:3: [2] (buffer) char: Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Perform bounds checking, use functions that limit length, or ensure that the size is larger than the maximum possible length. char cmd[sizeof conf_bin + 13]; data/twoftpd-1.42/twoftpd-switch.c:33:3: [2] (buffer) strcpy: Does not check for buffer overflows when copying to destination [MS-banned] (CWE-120). Consider using snprintf, strcpy_s, or strlcpy (warning: strncpy easily misused). Risk is low because the source is a constant string. strcpy(cmd + sizeof conf_bin - 1, "/twoftpd-"); data/twoftpd-1.42/backend.c:101:23: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). ptr = (char*)home + strlen(home)-1; data/twoftpd-1.42/backend.c:122:19: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if ((user_len = strlen(user)) > MAX_NAME_LEN) { data/twoftpd-1.42/backend.c:126:20: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). if ((group_len = strlen(group)) > MAX_NAME_LEN) { data/twoftpd-1.42/copy.c:106:19: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if ((icount = read(in, in_buf, sizeof in_buf)) == -1) data/twoftpd-1.42/list.c:203:55: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). for (bytes_out = 0; count > 0; --count, filename += strlen(filename)+1) { data/twoftpd-1.42/list.c:260:42: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). || !str_catb(&entries, entry->d_name, strlen(entry->d_name)+1)) { data/twoftpd-1.42/path.c:31:29: [1] (buffer) strlen: Does not handle strings that are not \0-terminated; if given one it may perform an over-read (it could cause a crash if unprotected) (CWE-126). unsigned long homelen = strlen(home); data/twoftpd-1.42/socket.c:96:2: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). read(bind_port_fd, &buf, 1) == 1 && data/twoftpd-1.42/twoftpd-anon-conf.c:74:3: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). umask(0); data/twoftpd-1.42/twoftpd-bind-port.c:61:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(sock, &code, 1) != 1) return; data/twoftpd-1.42/twoftpd-conf.c:65:3: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). umask(0); ANALYSIS SUMMARY: Hits = 70 Lines analyzed = 2962 in approximately 0.12 seconds (23756 lines/second) Physical Source Lines of Code (SLOC) = 2182 Hits@level = [0] 0 [1] 11 [2] 16 [3] 32 [4] 6 [5] 5 Hits@level+ = [0+] 70 [1+] 70 [2+] 59 [3+] 43 [4+] 11 [5+] 5 Hits/KSLOC@level+ = [0+] 32.0807 [1+] 32.0807 [2+] 27.0394 [3+] 19.7067 [4+] 5.04125 [5+] 2.29148 Minimum risk level = 1 Not every hit is necessarily a security vulnerability. There may be other security vulnerabilities; review your code! See 'Secure Programming HOWTO' (https://dwheeler.com/secure-programs) for more information.