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/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c Examining data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/namespace.h Examining data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c FINAL RESULTS: data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:147:6: [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. if (vsnprintf(message, sizeof(message), format, args) < 0) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:174: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(path, PATH_MAX, pathfmt, ap); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:144: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(CLONED_BINARY_ENV)) { data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:278: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. char *prefix = getenv("_LIBCONTAINER_STATEDIR"); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:380: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. char *prefix = getenv("_LIBCONTAINER_STATEDIR"); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:359:13: [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. initpipe = getenv("_LIBCONTAINER_INITPIPE"); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:374: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. logpipe = getenv("_LIBCONTAINER_LOGPIPE"); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:121:7: [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("/proc/self/exe", O_RDONLY|O_CLOEXEC); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:178: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], *copy = NULL; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:183:7: [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 | O_CLOEXEC); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:198: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(copy + *length, buf, n); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:277: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 template[PATH_MAX] = {0}; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:304:7: [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(prefix, O_TMPFILE | O_EXCL | O_RDWR | O_CLOEXEC, 0700); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:354: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 fdpath[PATH_MAX] = {0}; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:362: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). newfd = open(fdpath, O_PATH | O_CLOEXEC); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:379: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 template[PATH_MAX] = {0}; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:391:7: [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). fd = mkstemp(template); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:409: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). ret = open(template, O_PATH | O_CLOEXEC); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:435: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 buffer[4096]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:482:10: [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). binfd = open("/proc/self/exe", O_RDONLY | O_CLOEXEC); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:59: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 stack[4096] __attribute__ ((aligned(16))); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:60: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 stack_ptr[0]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:139: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 message[1024] = {}; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:170: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 path[PATH_MAX]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:179:7: [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_RDWR); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:248: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 *argv[MAX_ARGV]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:250: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 pid_fmt[16]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:511: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 type[PATH_MAX]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:512: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[PATH_MAX]; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:540: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/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:191:7: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). n = read(fd, buf, sizeof(buf)); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:227: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). cur += strlen(cur) + 1; data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/cloned_binary.c:440:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). nread = read(infd, buffer, sizeof(buffer)); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:219:25: [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 (write_file(policy, strlen(policy), "/proc/%d/setgroups", pid) < 0) { data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:426:8: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). len = read(fd, &hdr, NLMSG_HDRLEN); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:442:8: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). len = read(fd, data, size); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:515:21: [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 (!namespace || !strlen(namespace) || !strlen(nslist)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:515: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 (!namespace || !strlen(namespace) || !strlen(nslist)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:546:3: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(ns->path, path, PATH_MAX - 1); data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:723:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &s, sizeof(s)) != sizeof(s)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:756:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &child, sizeof(child)) != sizeof(child)) { data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:805:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &s, sizeof(s)) != sizeof(s)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:888:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &s, sizeof(s)) != sizeof(s)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:941:8: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &s, sizeof(s)) != sizeof(s)) { data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:982:8: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(syncfd, &s, sizeof(s)) != sizeof(s)) data/runc-1.0.0~rc92.249.g636f23dd+dfsg1/libcontainer/nsenter/nsexec.c:1004:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(pipenum, &value, sizeof(value)) != sizeof(value)) ANALYSIS SUMMARY: Hits = 46 Lines analyzed = 1606 in approximately 0.17 seconds (9504 lines/second) Physical Source Lines of Code (SLOC) = 965 Hits@level = [0] 6 [1] 16 [2] 23 [3] 5 [4] 2 [5] 0 Hits@level+ = [0+] 52 [1+] 46 [2+] 30 [3+] 7 [4+] 2 [5+] 0 Hits/KSLOC@level+ = [0+] 53.886 [1+] 47.6684 [2+] 31.0881 [3+] 7.25389 [4+] 2.07254 [5+] 0 Dot directories skipped = 2 (--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.