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/xjobs-20120412/log.c Examining data/xjobs-20120412/xjobs.c Examining data/xjobs-20120412/log.h Examining data/xjobs-20120412/tokens.h FINAL RESULTS: data/xjobs-20120412/xjobs.c:491:20: [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. while (-1 != (l = readlink(cmd,lt,PATH_MAX))) { data/xjobs-20120412/log.c:28:9: [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(stderr,msg,val); data/xjobs-20120412/log.c:42:8: [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. len = vsnprintf(buf,sizeof(buf),msg,val); data/xjobs-20120412/log.c:55:9: [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(stderr,msg,val); data/xjobs-20120412/log.c:66:10: [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(stderr,msg,val); data/xjobs-20120412/xjobs.c:434:3: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(msg,"failed to execute %s: %s\n",j->args[0],strerror(errno)); data/xjobs-20120412/xjobs.c:532:31: [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 ((exe[0] == '/') && (0 == access(exe,X_OK))) { data/xjobs-20120412/xjobs.c:534: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(c->exe,exe); data/xjobs-20120412/xjobs.c:542:12: [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 (0 == access(exe,X_OK)) { data/xjobs-20120412/xjobs.c:544:4: [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(c->exe,exe); data/xjobs-20120412/xjobs.c:588:12: [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 (0 == access(cmd,X_OK)) { data/xjobs-20120412/xjobs.c:591:4: [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(c->exe,exe); data/xjobs-20120412/xjobs.c:785:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. s += sprintf(msg,"### job #%d (%s), pid %6ld, ",j->job,j->cmd,(long)j->pid); data/xjobs-20120412/xjobs.c:789:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. s += sprintf(s,"terminated by signal %d (%s), ",WTERMSIG(ret),strsignal(WTERMSIG(ret))); data/xjobs-20120412/xjobs.c:793:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. s += sprintf(s,"real: %s, user: %s, sys: %s\n",timestr(dt,real),timevstr(rusage->ru_utime,user),timevstr(rusage->ru_stime,sys)); data/xjobs-20120412/xjobs.c:795:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. s += sprintf(s,"real: %s\n",timestr(dt,0)); data/xjobs-20120412/xjobs.c:1031: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. Path = getenv("PATH"); data/xjobs-20120412/xjobs.c:1032:14: [3] (buffer) getopt: Some older implementations do not protect against internal buffer overflows (CWE-120, CWE-20). Check implementation on installation, or limit the size of all string inputs. while ((i = getopt(argc,argv,"01dehj:l:nNpq:rs:tv:V")) != -1) { data/xjobs-20120412/log.c:36: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 buf[4096]; data/xjobs-20120412/xjobs.c:146: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). Input = open(Script,O_RDONLY); data/xjobs-20120412/xjobs.c:260:9: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. return memcpy(Malloc(n),s,n); data/xjobs-20120412/xjobs.c:292: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 y[16]; data/xjobs-20120412/xjobs.c:311: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 pwd[PATH_MAX]; data/xjobs-20120412/xjobs.c:332:8: [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). in = open(j->in,O_RDONLY,0666); data/xjobs-20120412/xjobs.c:350:9: [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). err = open(j->err,mode,0666); data/xjobs-20120412/xjobs.c:369:9: [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). out = open(j->out,mode,0666); data/xjobs-20120412/xjobs.c:381: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). err = mkstemp(fname); data/xjobs-20120412/xjobs.c:413:11: [2] (race) vfork: On some old systems, vfork() permits race conditions, and it's very difficult to use correctly (CWE-362). Use fork() instead. j->pid = vfork(); data/xjobs-20120412/xjobs.c:425: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 msg[256]; data/xjobs-20120412/xjobs.c:487: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 lt[PATH_MAX+1]; data/xjobs-20120412/xjobs.c:506:10: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. (void) memcpy(base,lt,l+1); data/xjobs-20120412/xjobs.c:517: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 *file, exe[PATH_MAX]; data/xjobs-20120412/xjobs.c:551:4: [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[PATH_MAX+1]; data/xjobs-20120412/xjobs.c:552:11: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. (void) memcpy(cmd,exe,exel); data/xjobs-20120412/xjobs.c:560: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[PATH_MAX]; data/xjobs-20120412/xjobs.c:569:10: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. (void) memcpy(cmd, token, off+1); data/xjobs-20120412/xjobs.c:578:10: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. (void) memcpy(cmd+off, exe, exel+1); data/xjobs-20120412/xjobs.c:732:9: [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 str[64]; data/xjobs-20120412/xjobs.c:747:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"%d days, ",days); data/xjobs-20120412/xjobs.c:749:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"%d:",hours); data/xjobs-20120412/xjobs.c:750:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"%02d:",mins); data/xjobs-20120412/xjobs.c:752:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"%d:",mins); data/xjobs-20120412/xjobs.c:758:7: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"%.4g",sec); data/xjobs-20120412/xjobs.c:760:3: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. sprintf(s," hours"); data/xjobs-20120412/xjobs.c:762:3: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. sprintf(s," mins."); data/xjobs-20120412/xjobs.c:764:3: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. sprintf(s," secs."); data/xjobs-20120412/xjobs.c:779: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 real[64],user[64],sys[64]; data/xjobs-20120412/xjobs.c:787:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(msg,"### "); data/xjobs-20120412/xjobs.c:791:8: [2] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. Risk is low because the source has a constant maximum length. s += sprintf(s,"exitcode %d, ",WEXITSTATUS(ret)); data/xjobs-20120412/xjobs.c:863: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[bsize]; data/xjobs-20120412/xjobs.c:950:9: [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[8*1024]; data/xjobs-20120412/xjobs.c:971:9: [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[PATH_MAX+1] = ""; data/xjobs-20120412/xjobs.c:993:9: [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[PATH_MAX+1] = ""; data/xjobs-20120412/xjobs.c:1105: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). Stdout = open("/dev/null",O_WRONLY); data/xjobs-20120412/xjobs.c:1113: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). Stdout = open("/dev/null",O_WRONLY); data/xjobs-20120412/xjobs.c:1121:10: [2] (misc) fopen: 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). Tty = fopen("/dev/tty","r+"); data/xjobs-20120412/xjobs.c:1139: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). Input = open(optarg,O_RDONLY); data/xjobs-20120412/xjobs.c:1154: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(optarg,O_WRONLY); data/xjobs-20120412/xjobs.c:1233: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). Stdin = open(argv[++optind],O_RDONLY); data/xjobs-20120412/xjobs.c:1241: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). Stdout = open(argv[optind],O_WRONLY|O_CREAT|O_EXCL,0666); data/xjobs-20120412/xjobs.c:1249: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). Stdout = open(argv[optind],O_WRONLY|O_APPEND); data/xjobs-20120412/xjobs.c:1257:22: [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). Stderr = Stdout = open(argv[optind],O_WRONLY|O_CREAT|O_EXCL,0666); data/xjobs-20120412/xjobs.c:1265: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). Stdout = open(argv[optind],O_WRONLY|O_APPEND); data/xjobs-20120412/xjobs.c:1284: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). Stdin = open("/dev/null",O_RDONLY); data/xjobs-20120412/xjobs.c:179:6: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). n = read(Input,buf,max); data/xjobs-20120412/xjobs.c:272:8: [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). l += strlen(*a); data/xjobs-20120412/xjobs.c:435:22: [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). (void) write(2,msg,strlen(msg)); data/xjobs-20120412/xjobs.c:540: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). exel = strlen(exe); data/xjobs-20120412/xjobs.c:565:14: [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 ((off = strlen(token)) >= PATH_MAX) { data/xjobs-20120412/xjobs.c:782:15: [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). msg = alloca(strlen(j->cmd) + 128); data/xjobs-20120412/xjobs.c:861:31: [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). size_t bsize = st.st_size + strlen(j->cmd) + 200; data/xjobs-20120412/xjobs.c:953:13: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). int num = read(STDIN_FILENO,buf,sizeof(buf)); ANALYSIS SUMMARY: Hits = 72 Lines analyzed = 1613 in approximately 0.05 seconds (31075 lines/second) Physical Source Lines of Code (SLOC) = 1469 Hits@level = [0] 13 [1] 8 [2] 46 [3] 2 [4] 15 [5] 1 Hits@level+ = [0+] 85 [1+] 72 [2+] 64 [3+] 18 [4+] 16 [5+] 1 Hits/KSLOC@level+ = [0+] 57.8625 [1+] 49.0129 [2+] 43.5671 [3+] 12.2532 [4+] 10.8918 [5+] 0.680735 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.