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/libcap2-2.44/contrib/bug400591/bug.c Examining data/libcap2-2.44/libcap/libcap.h Examining data/libcap2-2.44/libcap/cap_alloc.c Examining data/libcap2-2.44/libcap/include/uapi/linux/securebits.h Examining data/libcap2-2.44/libcap/include/uapi/linux/prctl.h Examining data/libcap2-2.44/libcap/include/uapi/linux/capability.h Examining data/libcap2-2.44/libcap/include/sys/securebits.h Examining data/libcap2-2.44/libcap/include/sys/capability.h Examining data/libcap2-2.44/libcap/cap_extint.c Examining data/libcap2-2.44/libcap/cap_flag.c Examining data/libcap2-2.44/libcap/cap_test.c Examining data/libcap2-2.44/libcap/cap_proc.c Examining data/libcap2-2.44/libcap/cap_file.c Examining data/libcap2-2.44/libcap/_makenames.c Examining data/libcap2-2.44/libcap/cap_text.c Examining data/libcap2-2.44/pam_cap/test_pam_cap.c Examining data/libcap2-2.44/pam_cap/pam_cap.c Examining data/libcap2-2.44/pam_cap/test.c Examining data/libcap2-2.44/progs/capsh.c Examining data/libcap2-2.44/progs/old/sucap.c Examining data/libcap2-2.44/progs/old/setpcaps.c Examining data/libcap2-2.44/progs/old/execcap.c Examining data/libcap2-2.44/progs/getcap.c Examining data/libcap2-2.44/progs/getpcaps.c Examining data/libcap2-2.44/progs/setcap.c Examining data/libcap2-2.44/psx/include/sys/psx_syscall.h Examining data/libcap2-2.44/psx/psx.c Examining data/libcap2-2.44/template.c Examining data/libcap2-2.44/tests/libcap_launch_test.c Examining data/libcap2-2.44/tests/noop.c Examining data/libcap2-2.44/tests/psx_test.c Examining data/libcap2-2.44/tests/libcap_psx_test.c FINAL RESULTS: data/libcap2-2.44/libcap/cap_alloc.c:92:5: [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((char *) raw_data, old); data/libcap2-2.44/libcap/cap_text.c:388:9: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p = sprintf(buf, "=%s%s%s", data/libcap2-2.44/libcap/cap_text.c:406:15: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p += sprintf(p, "%s,", this_cap_name); data/libcap2-2.44/libcap/cap_text.c:422:11: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p += sprintf(p, "%c%s%s%s", op, data/libcap2-2.44/libcap/cap_text.c:429:11: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p += sprintf(p, "-%s%s%s", data/libcap2-2.44/libcap/cap_text.c:458:8: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p += sprintf(p, "%s,", this_cap_name); data/libcap2-2.44/libcap/cap_text.c:463:7: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. p += sprintf(p, "+%s%s%s", data/libcap2-2.44/libcap/cap_text.c:536:7: [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(p, _cap_names[c]); data/libcap2-2.44/libcap/libcap.h:169:5: [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. fprintf(stderr, f, ## x); \ data/libcap2-2.44/progs/capsh.c:406:3: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(ptr, "%s %s+i", text, argv[i]+6); data/libcap2-2.44/progs/capsh.c:408: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(ptr, text); data/libcap2-2.44/progs/old/execcap.c:60: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[2], argv+2); data/libcap2-2.44/progs/old/sucap.c:175:2: [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[3], argv+3); data/libcap2-2.44/libcap/cap_alloc.c:189:16: [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 (launcher->chroot) { data/libcap2-2.44/libcap/cap_alloc.c:190:25: [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. cap_free(launcher->chroot); data/libcap2-2.44/libcap/cap_proc.c:805:61: [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. void cap_launcher_set_chroot(cap_launch_t attr, const char *chroot) data/libcap2-2.44/libcap/cap_proc.c:807:35: [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. attr->chroot = _libcap_strdup(chroot); data/libcap2-2.44/libcap/cap_proc.c:825:12: [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. ret = chroot(root); data/libcap2-2.44/libcap/cap_proc.c:863:15: [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 (attr->chroot != NULL && _cap_chroot(sc, attr->chroot)) { data/libcap2-2.44/libcap/cap_proc.c:863:55: [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 (attr->chroot != NULL && _cap_chroot(sc, attr->chroot)) { data/libcap2-2.44/libcap/include/sys/capability.h:195:68: [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. extern void cap_launcher_set_chroot(cap_launch_t attr, const char *chroot); data/libcap2-2.44/libcap/libcap.h:289:11: [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. char *chroot; data/libcap2-2.44/progs/capsh.c:566:15: [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. status = chroot(argv[i]+9); data/libcap2-2.44/progs/getcap.c:85:17: [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 ((c = getopt(argc, argv, "rvhn")) > 0) { data/libcap2-2.44/tests/libcap_launch_test.c:17:17: [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. const char *chroot; data/libcap2-2.44/tests/libcap_launch_test.c:94: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 (v->chroot) { data/libcap2-2.44/tests/libcap_launch_test.c:95:39: [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. cap_launcher_set_chroot(attr, v->chroot); data/libcap2-2.44/libcap/cap_alloc.c:119: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(result, cap_d, sizeof(*cap_d)); data/libcap2-2.44/libcap/cap_extint.c:56: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(&result->magic, external_magic, CAP_EXT_MAGIC_SIZE); data/libcap2-2.44/libcap/cap_text.c:18: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 const *_cap_names[__CAP_BITS] = LIBCAP_CAP_NAMES; data/libcap2-2.44/libcap/cap_text.c:355: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[CAP_TEXT_SIZE+CAP_TEXT_BUFFER_ZONE]; data/libcap2-2.44/libcap/cap_text.c:505: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[CAP_TEXT_SIZE+CAP_TEXT_BUFFER_ZONE]; data/libcap2-2.44/libcap/cap_text.c:538: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. sprintf(p, "%u", c); data/libcap2-2.44/pam_cap/pam_cap.c:82: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 buffer[CAP_FILE_BUFFER_SIZE], *line; data/libcap2-2.44/pam_cap/pam_cap.c:92:16: [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). cap_file = fopen(source, "r"); data/libcap2-2.44/progs/capsh.c:38:12: [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 string[8*sizeof(unsigned long) + 1]; data/libcap2-2.44/progs/getpcaps.c:53:8: [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). pid = atoi(argv[0]); data/libcap2-2.44/progs/old/setpcaps.c:66: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 buffer[MAXCAP+1]; data/libcap2-2.44/progs/old/setpcaps.c:110:8: [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). pid = atoi(*++argv); data/libcap2-2.44/progs/old/sucap.c:45: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[1]; data/libcap2-2.44/progs/setcap.c:81: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 buffer[MAXCAP+1]; data/libcap2-2.44/progs/setcap.c:115:23: [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). rootid = (uid_t) atoi(*++argv); data/libcap2-2.44/tests/libcap_launch_test.c:22:11: [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. const char *args[MORE_THAN_ENOUGH]; data/libcap2-2.44/tests/psx_test.c:77: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 * const stop_argv[3] = { argv[0], strdup("stop"), NULL }; data/libcap2-2.44/libcap/_makenames.c:54: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). int n = strlen(list[i].name); data/libcap2-2.44/libcap/cap_alloc.c:85:40: [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). raw_data = malloc( sizeof(__u32) + strlen(old) + 1 ); data/libcap2-2.44/libcap/cap_alloc.c:167:18: [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 length = strlen(data_p) + sizeof(__u32); data/libcap2-2.44/libcap/cap_proc.c:931:10: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). int n = read(ps[0], &my_errno, sizeof(my_errno)); data/libcap2-2.44/libcap/cap_text.c:401: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). if ((strlen(this_cap_name) + (p - buf)) > CAP_TEXT_SIZE) { data/libcap2-2.44/libcap/cap_text.c:453: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). if ((strlen(this_cap_name) + (p - buf)) > CAP_TEXT_SIZE) { data/libcap2-2.44/libcap/cap_text.c:540: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). p += strlen(p); data/libcap2-2.44/pam_cap/pam_cap.c:204:32: [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). ssize_t conf_caps_length = strlen(conf_caps); data/libcap2-2.44/progs/capsh.c:111: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). (unsigned) strlen(b), b); data/libcap2-2.44/progs/capsh.c:400: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). ptr = malloc(10 + strlen(argv[i]+6) + strlen(text)); data/libcap2-2.44/progs/capsh.c:400:44: [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 = malloc(10 + strlen(argv[i]+6) + strlen(text)); data/libcap2-2.44/progs/old/setpcaps.c:40:10: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). int j = read(STDIN_FILENO, buffer, i); data/libcap2-2.44/progs/old/sucap.c:46:12: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). while (read(fd, buf, sizeof(buf)) == -1 && errno == EINTR) { data/libcap2-2.44/progs/setcap.c:54:10: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). int j = read(STDIN_FILENO, buffer, i); data/libcap2-2.44/tests/libcap_psx_test.c:16:5: [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. usleep(1234); data/libcap2-2.44/tests/libcap_psx_test.c:46:2: [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. usleep(1000); data/libcap2-2.44/tests/psx_test.c:81:2: [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. usleep(2000); data/libcap2-2.44/tests/psx_test.c:114:7: [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. usleep(2000); ANALYSIS SUMMARY: Hits = 62 Lines analyzed = 7294 in approximately 0.31 seconds (23797 lines/second) Physical Source Lines of Code (SLOC) = 4968 Hits@level = [0] 167 [1] 18 [2] 17 [3] 14 [4] 13 [5] 0 Hits@level+ = [0+] 229 [1+] 62 [2+] 44 [3+] 27 [4+] 13 [5+] 0 Hits/KSLOC@level+ = [0+] 46.095 [1+] 12.4799 [2+] 8.85668 [3+] 5.43478 [4+] 2.61675 [5+] 0 Symlinks skipped = 1 (--allowlink overrides but see doc for security issue) 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.