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/csh-20110502/dol.c Examining data/csh-20110502/parse.c Examining data/csh-20110502/error.c Examining data/csh-20110502/exec.c Examining data/csh-20110502/const.c Examining data/csh-20110502/extern.h Examining data/csh-20110502/hist.c Examining data/csh-20110502/char.c Examining data/csh-20110502/func.c Examining data/csh-20110502/file.c Examining data/csh-20110502/char.h Examining data/csh-20110502/set.c Examining data/csh-20110502/proc.h Examining data/csh-20110502/misc.c Examining data/csh-20110502/init.c Examining data/csh-20110502/alloc.c Examining data/csh-20110502/time.c Examining data/csh-20110502/dir.h Examining data/csh-20110502/dir.c Examining data/csh-20110502/sem.c Examining data/csh-20110502/str.c Examining data/csh-20110502/csh.h Examining data/csh-20110502/pathnames.h Examining data/csh-20110502/csh.c Examining data/csh-20110502/glob.c Examining data/csh-20110502/proc.c Examining data/csh-20110502/exp.c Examining data/csh-20110502/lex.c FINAL RESULTS: data/csh-20110502/dir.c:677:9: [5] (race) readlink: This accepts filename arguments; if an attacker can move those files or change the link content, a race condition results. Also, it does not terminate with ASCII NUL. (CWE-362, CWE-20). Reconsider approach. (cc = readlink(short2str(cp), tlink, data/csh-20110502/dir.c:762:9: [5] (race) readlink: This accepts filename arguments; if an attacker can move those files or change the link content, a race condition results. Also, it does not terminate with ASCII NUL. (CWE-362, CWE-20). Reconsider approach. (cc = readlink(short2str(cp), tlink, data/csh-20110502/dir.c:83:13: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(csherr, emsg, vis_str(hp)); data/csh-20110502/dir.c:88:13: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(csherr, emsg, "/"); data/csh-20110502/dir.c:218:9: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(cshout, s != dp->di_name ? "~%s%c" : "%s%c", data/csh-20110502/error.c:289:2: [4] (format) vsnprintf: If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate (CWE-134). Use a constant for the format specification. vsnprintf(berr, sizeof(berr), errorlist[id], va); data/csh-20110502/error.c:343:13: [4] (format) vfprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) vfprintf(csherr, errorlist[id], va); data/csh-20110502/exec.c:580:8: [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. access(strname, X_OK) == 0) || data/csh-20110502/exp.c:488:11: [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. i = !access(short2str(ep), R_OK); data/csh-20110502/exp.c:492:11: [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. i = !access(short2str(ep), W_OK); data/csh-20110502/exp.c:496:11: [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. i = !access(short2str(ep), X_OK); data/csh-20110502/func.c:223:12: [4] (shell) execl: 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. (void) execl(_PATH_LOGIN, "login", short2str(v[1]), (char *)NULL); data/csh-20110502/proc.c:704:11: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(cshout, format, ""); data/csh-20110502/proc.c:717:14: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(cshout, format, "Running "); data/csh-20110502/proc.c:734:11: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(cshout, format, data/csh-20110502/proc.c:747:15: [4] (format) fprintf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. (void) fprintf(cshout, format, "Done"); data/csh-20110502/csh.c:172: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. AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL; data/csh-20110502/csh.c:172:43: [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. AsciiOnly = getenv("LANG") == NULL && getenv("LC_CTYPE") == NULL; data/csh-20110502/csh.c:210: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 ((tcp = getenv("HOME")) != NULL && strlen(tcp) < MAXPATHLEN) data/csh-20110502/csh.c:225: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 ((tcp = getenv("LOGNAME")) != NULL || data/csh-20110502/csh.c:226: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. (tcp = getenv("USER")) != NULL) data/csh-20110502/csh.c:228: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 ((tcp = getenv("TERM")) != NULL) data/csh-20110502/csh.c:234: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 ((tcp = getenv("PATH")) == NULL) data/csh-20110502/dir.c:111: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. if ((cwd = getenv("PWD")) != NULL) { data/csh-20110502/dol.c:508: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. dolp = (vp || getenv(short2str(name))) ? STR1 : STR0; data/csh-20110502/dol.c:512: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. np = str2short(getenv(short2str(name))); data/csh-20110502/func.c:977: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. AsciiOnly = getenv("LANG") == NULL && data/csh-20110502/func.c:978:4: [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. getenv("LC_CTYPE") == NULL; data/csh-20110502/char.c:237: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. unsigned char _cmap_lower[256] = { data/csh-20110502/char.c:272: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. unsigned char _cmap_upper[256] = { data/csh-20110502/csh.c:358:11: [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). nofile = open(tempv[0], O_RDONLY); data/csh-20110502/csh.c:640:17: [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 ((unit = open(f, O_RDONLY)) == -1) data/csh-20110502/csh.c:707:5: [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(&saveB, &B, sizeof(B)); data/csh-20110502/csh.c:791:12: [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(short2str(hfile), O_WRONLY | O_CREAT | O_TRUNC, data/csh-20110502/csh.c:1107:5: [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 sbuf[BUFSIZ]; data/csh-20110502/csh.c:1244:5: [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 uenc[5]; /* 4 + NUL */ data/csh-20110502/csh.h:195:20: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. #define getexit(a) memcpy((a), reslab, sizeof reslab) data/csh-20110502/csh.h:196:20: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. #define resexit(a) memcpy(reslab, (a), sizeof reslab) data/csh-20110502/dir.c:70:5: [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 path[MAXPATHLEN]; data/csh-20110502/dir.c:409:5: [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 ebuf[MAXPATHLEN]; data/csh-20110502/dir.c:615:5: [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 tlink[MAXPATHLEN]; data/csh-20110502/dol.c:830:9: [2] (tmpfile) mkstemp: Potential for temporary file vulnerability in some circumstances. Some older Unix-like systems create temp files with permission to write by all by default, so be sure to set the umask to override this. Also, some older Unix systems might fail to use O_EXCL when opening the file, so make sure that O_EXCL is used by the library (CWE-377). if (mkstemp(tmp) < 0) data/csh-20110502/error.c:283: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 berr[BUFSIZ]; data/csh-20110502/exec.c:81: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 xhash[HSHSIZ / 8]; data/csh-20110502/exec.c:281:12: [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(f, O_RDONLY)) != -1) { data/csh-20110502/file.c:576:5: [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 tinputline[BUFSIZ]; data/csh-20110502/glob.c:684:5: [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 tibuf[BUFSIZ]; data/csh-20110502/glob.c:942:5: [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[2048]; data/csh-20110502/lex.c:1403:5: [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 tbuf[BUFSIZ + 1]; data/csh-20110502/lex.c:1462:7: [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(fbuf[buf] + off, ttyline, c * sizeof(Char)); data/csh-20110502/proc.c:107:16: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended). if (pid == atoi(short2str(value(STRchild)))) data/csh-20110502/proc.c:142:9: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended). >= atoi(short2str(value(STRtime)))) data/csh-20110502/proc.c:951:12: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended). signum = atoi(short2str(v[1])); data/csh-20110502/proc.c:975:15: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended). signum = atoi(short2str(v[0] + 1)); data/csh-20110502/proc.c:1165:16: [2] (integer) atoi: Unless checked, the resulting number can exceed the expected range (CWE-190). If source untrusted, check both minimum and maximum, even if the input had no minus sign (large numbers can roll over into negative number; consider saving to an unsigned value if that is intended). int idx = atoi(short2str(cp + 1)); data/csh-20110502/sem.c:256:9: [2] (race) vfork: On some old systems, vfork() permits race conditions, and it's very difficult to use correctly (CWE-362). Use fork() instead. pid = vfork(); data/csh-20110502/sem.c:522:6: [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[MAXPATHLEN]; data/csh-20110502/sem.c:533:16: [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(tmp, O_RDONLY)) < 0) data/csh-20110502/sem.c:545: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). (void) open(_PATH_DEVNULL, O_RDONLY); data/csh-20110502/sem.c:554: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[MAXPATHLEN]; data/csh-20110502/sem.c:566:12: [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). (fd = open(tmp, O_WRONLY | O_APPEND)) >= 0); data/csh-20110502/sem.c:568:12: [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). (fd = open(tmp, O_WRONLY)) >= 0) data/csh-20110502/sem.c:577:16: [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(tmp, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) data/csh-20110502/csh.c:210:43: [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 ((tcp = getenv("HOME")) != NULL && strlen(tcp) < MAXPATHLEN) data/csh-20110502/csh.c:1214:12: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). return read(DESC(oreo), buf, siz); data/csh-20110502/csh.h:497: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). #define Strlen(a) strlen(a) data/csh-20110502/dol.c:428:18: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). for (np = wbuf; read(OLDSTD, &tnp, 1) == 1; np++) { data/csh-20110502/exec.c:282:10: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(fd, (char *) &c, 1) == 1) { data/csh-20110502/file.c:580:24: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). while ((num_read = read(SHIN, tinputline, BUFSIZ)) > 0) { data/csh-20110502/func.c:1053:6: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). i = umask(0); data/csh-20110502/func.c:1054:9: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). (void) umask(i); data/csh-20110502/func.c:1063:12: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). (void) umask(i); data/csh-20110502/glob.c:768:14: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). icnt = read(pvec[0], tibuf, BUFSIZ); data/csh-20110502/lex.c:1415:7: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). c = read(SHIN, tbuf, BUFSIZ); data/csh-20110502/lex.c:1467:7: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). c = read(SHIN, tbuf, roomleft); data/csh-20110502/proc.c:962:10: [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). len = strlen(sys_sigabbrev[signum]) + 1; data/csh-20110502/proc.c:995:9: [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). (strlen(name) > 3 && !strncasecmp("SIG", name, 3) && ANALYSIS SUMMARY: Hits = 77 Lines analyzed = 16165 in approximately 0.45 seconds (35851 lines/second) Physical Source Lines of Code (SLOC) = 11984 Hits@level = [0] 97 [1] 14 [2] 35 [3] 12 [4] 14 [5] 2 Hits@level+ = [0+] 174 [1+] 77 [2+] 63 [3+] 28 [4+] 16 [5+] 2 Hits/KSLOC@level+ = [0+] 14.5194 [1+] 6.42523 [2+] 5.25701 [3+] 2.33645 [4+] 1.33511 [5+] 0.166889 Dot directories skipped = 1 (--followdotdir overrides) 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.