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/r-cran-ps-1.4.0/src/interrupt.c Examining data/r-cran-ps-1.4.0/src/posix.c Examining data/r-cran-ps-1.4.0/src/api-posix.c Examining data/r-cran-ps-1.4.0/src/linux.c Examining data/r-cran-ps-1.4.0/src/api-linux.c Examining data/r-cran-ps-1.4.0/src/macos.c Examining data/r-cran-ps-1.4.0/src/windows.c Examining data/r-cran-ps-1.4.0/src/init.c Examining data/r-cran-ps-1.4.0/src/arch/macos/process_info.c Examining data/r-cran-ps-1.4.0/src/arch/macos/process_info.h Examining data/r-cran-ps-1.4.0/src/arch/windows/process_info.c Examining data/r-cran-ps-1.4.0/src/arch/windows/ntextapi.h Examining data/r-cran-ps-1.4.0/src/arch/windows/process_handles.c Examining data/r-cran-ps-1.4.0/src/arch/windows/process_info.h Examining data/r-cran-ps-1.4.0/src/arch/windows/process_handles.h Examining data/r-cran-ps-1.4.0/src/windows.h Examining data/r-cran-ps-1.4.0/src/ps.h Examining data/r-cran-ps-1.4.0/src/api-macos.c Examining data/r-cran-ps-1.4.0/src/api-windows-conn.c Examining data/r-cran-ps-1.4.0/src/ps-internal.h Examining data/r-cran-ps-1.4.0/src/common.c Examining data/r-cran-ps-1.4.0/src/dummy.c Examining data/r-cran-ps-1.4.0/src/px.c Examining data/r-cran-ps-1.4.0/src/extra.c Examining data/r-cran-ps-1.4.0/src/common.h Examining data/r-cran-ps-1.4.0/src/api-windows.c Examining data/r-cran-ps-1.4.0/src/posix.h Examining data/r-cran-ps-1.4.0/src/api-common.c FINAL RESULTS: data/r-cran-ps-1.4.0/src/api-linux.c:134: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. r = readlink(path, *linkname, size - 1); data/r-cran-ps-1.4.0/src/api-windows.c:843:60: [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. processHandle = ps__handle_from_pid_waccess(handle->pid, access); data/r-cran-ps-1.4.0/src/api-windows.c:1346:55: [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. hProcess = ps__handle_from_pid_waccess(handle->pid, access); data/r-cran-ps-1.4.0/src/extra.c:30:3: [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(ps__last_error_string, data/r-cran-ps-1.4.0/src/api-windows-conn.c:118:13: [3] (misc) LoadLibrary: Ensure that the full path to the library is specified, or current directory may be used (CWE-829, CWE-20). Use registry entry or GetWindowsDirectory to find library path, if you aren't already. ntdll = LoadLibrary(TEXT("ntdll.dll")); data/r-cran-ps-1.4.0/src/arch/windows/process_info.c:842:12: [3] (misc) LoadLibrary: Ensure that the full path to the library is specified, or current directory may be used (CWE-829, CWE-20). Use registry entry or GetWindowsDirectory to find library path, if you aren't already. hNtDll = LoadLibrary(TEXT("ntdll.dll")); data/r-cran-ps-1.4.0/src/init.c:78: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("R_PS_DEBUG") != NULL) PS__DEBUG = 1; data/r-cran-ps-1.4.0/src/init.c:79: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("R_PS_TESTING") != NULL) PS__TESTING = 1; data/r-cran-ps-1.4.0/src/px.c:173:22: [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. printf("%s\n", getenv(argv[++idx])); data/r-cran-ps-1.4.0/src/api-linux.c:98: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:179: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:437: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:474: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:559: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:586: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:663: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:748: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:819: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:901: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:936: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 path[512]; data/r-cran-ps-1.4.0/src/api-linux.c:1005: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 path[512]; data/r-cran-ps-1.4.0/src/api-macos.c:209: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[PROC_PIDPATHINFO_MAXSIZE]; data/r-cran-ps-1.4.0/src/api-macos.c:740:7: [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 lip[512], rip[512]; data/r-cran-ps-1.4.0/src/api-macos.c:850: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 opts[400]; data/r-cran-ps-1.4.0/src/api-windows-conn.c:223:2: [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(&addr, tcp6Table->table[i].ucLocalAddr, 16); data/r-cran-ps-1.4.0/src/api-windows-conn.c:236:2: [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(&addr, tcp6Table->table[i].ucRemoteAddr, 16); data/r-cran-ps-1.4.0/src/api-windows-conn.c:342:2: [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(&addr, udp6Table->table[i].ucLocalAddr, 16); data/r-cran-ps-1.4.0/src/api-windows.c:300: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(str, CHAR(STRING_ELT(ret, 0)), len1); data/r-cran-ps-1.4.0/src/api-windows.c:302: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(str + len1 + 1, CHAR(STRING_ELT(ret, 1)), len2 + 1); data/r-cran-ps-1.4.0/src/api-windows.c:875: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 arguments[100]; data/r-cran-ps-1.4.0/src/api-windows.c:949: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 address_str[50]; data/r-cran-ps-1.4.0/src/api-windows.c:1099: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 drive_strings[255]; data/r-cran-ps-1.4.0/src/api-windows.c:1101: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 mp_buf[MAX_PATH]; data/r-cran-ps-1.4.0/src/api-windows.c:1102: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 mp_path[MAX_PATH]; data/r-cran-ps-1.4.0/src/api-windows.c:1107: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 opts[20]; data/r-cran-ps-1.4.0/src/extra.c:18:1: [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 ps__last_error_string[1024]; data/r-cran-ps-1.4.0/src/extra.c:142:12: [2] (buffer) MultiByteToWideChar: Requires maximum length in CHARACTERS, not bytes (CWE-120). ws_len = MultiByteToWideChar( data/r-cran-ps-1.4.0/src/extra.c:155:7: [2] (buffer) MultiByteToWideChar: Requires maximum length in CHARACTERS, not bytes (CWE-120). r = MultiByteToWideChar( data/r-cran-ps-1.4.0/src/extra.c:326: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(RAW(VECTOR_ELT(res, lptr)), tmp1, tmp2); data/r-cran-ps-1.4.0/src/linux.c:39: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). fd = open(path, O_RDONLY); data/r-cran-ps-1.4.0/src/linux.c:72: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 dst[INET6_ADDRSTRLEN]; data/r-cran-ps-1.4.0/src/px.c:40: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[8192]; data/r-cran-ps-1.4.0/src/px.c:54: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). int f = open(filename, O_RDONLY); data/r-cran-ps-1.4.0/src/px.c:76: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[nbytes + 1]; data/r-cran-ps-1.4.0/src/windows.c:169:3: [2] (buffer) wchar_t: 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. wchar_t exe[MAX_PATH]; data/r-cran-ps-1.4.0/src/windows.c:197:3: [2] (buffer) wchar_t: 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. wchar_t device[3] = { d, ':', '\0' }; data/r-cran-ps-1.4.0/src/windows.c:198:3: [2] (buffer) wchar_t: 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. wchar_t target[512]; data/r-cran-ps-1.4.0/src/api-linux.c:259: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). size_t needle_len = strlen(needle); data/r-cran-ps-1.4.0/src/api-linux.c:589:24: [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 needle_len = strlen(needle); data/r-cran-ps-1.4.0/src/api-linux.c:838:39: [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). return ps__memmem(buf, ret, marker, strlen(marker)) != NULL; data/r-cran-ps-1.4.0/src/api-linux.c:1050: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). l = strlen(linkname); data/r-cran-ps-1.4.0/src/api-windows.c:297: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). len1 = strlen(CHAR(STRING_ELT(ret, 0))); data/r-cran-ps-1.4.0/src/api-windows.c:298: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). len2 = strlen(CHAR(STRING_ELT(ret, 1))); data/r-cran-ps-1.4.0/src/api-windows.c:1204: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). if (strlen(opts) > 0) { data/r-cran-ps-1.4.0/src/arch/macos/process_info.c:152: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). len = strlen(arg_ptr); data/r-cran-ps-1.4.0/src/arch/windows/process_info.c:773:10: [1] (buffer) wcslen: 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 = wcslen(data); data/r-cran-ps-1.4.0/src/extra.c:66: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 && strlen(msg) ? msg : "Permission denied"); data/r-cran-ps-1.4.0/src/extra.c:87: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 && strlen(msg) ? msg : "Out of memory"); data/r-cran-ps-1.4.0/src/extra.c:259: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). size_t n = strlen(template); data/r-cran-ps-1.4.0/src/extra.c:298:17: [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 slen = strlen(template); data/r-cran-ps-1.4.0/src/extra.c:324: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). tmp2 = strlen(tmp1); data/r-cran-ps-1.4.0/src/linux.c:54:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, ptr, rem_size); data/r-cran-ps-1.4.0/src/px.c:43:15: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). while ((n = read(f, buf, (long) sizeof buf)) > 0) { data/r-cran-ps-1.4.0/src/px.c:66:16: [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 len = strlen(s); data/r-cran-ps-1.4.0/src/px.c:79:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd1, buffer, nbytes); data/r-cran-ps-1.4.0/src/px.c:118:21: [1] (obsolete) usleep: This C routine is considered obsolete (as opposed to the shell command by the same name). The interaction of this function with SIGALRM and other timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead. if (fnum > 0) usleep((useconds_t) (fnum * 1000.0 * 1000.0)); ANALYSIS SUMMARY: Hits = 66 Lines analyzed = 8894 in approximately 0.18 seconds (48594 lines/second) Physical Source Lines of Code (SLOC) = 6748 Hits@level = [0] 66 [1] 19 [2] 38 [3] 5 [4] 3 [5] 1 Hits@level+ = [0+] 132 [1+] 66 [2+] 47 [3+] 9 [4+] 4 [5+] 1 Hits/KSLOC@level+ = [0+] 19.5614 [1+] 9.78068 [2+] 6.96503 [3+] 1.33373 [4+] 0.592768 [5+] 0.148192 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.