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/android-platform-build-kati-10.0.0+r32/affinity.cc Examining data/android-platform-build-kati-10.0.0+r32/affinity.h Examining data/android-platform-build-kati-10.0.0+r32/command.cc Examining data/android-platform-build-kati-10.0.0+r32/command.h Examining data/android-platform-build-kati-10.0.0+r32/dep.cc Examining data/android-platform-build-kati-10.0.0+r32/dep.h Examining data/android-platform-build-kati-10.0.0+r32/eval.cc Examining data/android-platform-build-kati-10.0.0+r32/eval.h Examining data/android-platform-build-kati-10.0.0+r32/exec.cc Examining data/android-platform-build-kati-10.0.0+r32/exec.h Examining data/android-platform-build-kati-10.0.0+r32/expr.cc Examining data/android-platform-build-kati-10.0.0+r32/expr.h Examining data/android-platform-build-kati-10.0.0+r32/file.cc Examining data/android-platform-build-kati-10.0.0+r32/file.h Examining data/android-platform-build-kati-10.0.0+r32/file_cache.cc Examining data/android-platform-build-kati-10.0.0+r32/file_cache.h Examining data/android-platform-build-kati-10.0.0+r32/fileutil.h Examining data/android-platform-build-kati-10.0.0+r32/fileutil_bench.cc Examining data/android-platform-build-kati-10.0.0+r32/find.cc Examining data/android-platform-build-kati-10.0.0+r32/find.h Examining data/android-platform-build-kati-10.0.0+r32/find_test.cc Examining data/android-platform-build-kati-10.0.0+r32/flags.cc Examining data/android-platform-build-kati-10.0.0+r32/flags.h Examining data/android-platform-build-kati-10.0.0+r32/func.cc Examining data/android-platform-build-kati-10.0.0+r32/func.h Examining data/android-platform-build-kati-10.0.0+r32/io.cc Examining data/android-platform-build-kati-10.0.0+r32/io.h Examining data/android-platform-build-kati-10.0.0+r32/loc.h Examining data/android-platform-build-kati-10.0.0+r32/log.cc Examining data/android-platform-build-kati-10.0.0+r32/log.h Examining data/android-platform-build-kati-10.0.0+r32/main.cc Examining data/android-platform-build-kati-10.0.0+r32/ninja.cc Examining data/android-platform-build-kati-10.0.0+r32/ninja.h Examining data/android-platform-build-kati-10.0.0+r32/ninja_test.cc Examining data/android-platform-build-kati-10.0.0+r32/parser.cc Examining data/android-platform-build-kati-10.0.0+r32/parser.h Examining data/android-platform-build-kati-10.0.0+r32/regen.cc Examining data/android-platform-build-kati-10.0.0+r32/regen.h Examining data/android-platform-build-kati-10.0.0+r32/regen_dump.cc Examining data/android-platform-build-kati-10.0.0+r32/rule.cc Examining data/android-platform-build-kati-10.0.0+r32/rule.h Examining data/android-platform-build-kati-10.0.0+r32/stats.cc Examining data/android-platform-build-kati-10.0.0+r32/stats.h Examining data/android-platform-build-kati-10.0.0+r32/stmt.cc Examining data/android-platform-build-kati-10.0.0+r32/stmt.h Examining data/android-platform-build-kati-10.0.0+r32/string_piece.cc Examining data/android-platform-build-kati-10.0.0+r32/string_piece.h Examining data/android-platform-build-kati-10.0.0+r32/string_piece_test.cc Examining data/android-platform-build-kati-10.0.0+r32/stringprintf.cc Examining data/android-platform-build-kati-10.0.0+r32/stringprintf.h Examining data/android-platform-build-kati-10.0.0+r32/strutil_bench.cc Examining data/android-platform-build-kati-10.0.0+r32/strutil_test.cc Examining data/android-platform-build-kati-10.0.0+r32/symtab.cc Examining data/android-platform-build-kati-10.0.0+r32/symtab.h Examining data/android-platform-build-kati-10.0.0+r32/testutil.h Examining data/android-platform-build-kati-10.0.0+r32/thread_local.h Examining data/android-platform-build-kati-10.0.0+r32/thread_pool.cc Examining data/android-platform-build-kati-10.0.0+r32/thread_pool.h Examining data/android-platform-build-kati-10.0.0+r32/timeutil.cc Examining data/android-platform-build-kati-10.0.0+r32/timeutil.h Examining data/android-platform-build-kati-10.0.0+r32/var.cc Examining data/android-platform-build-kati-10.0.0+r32/var.h Examining data/android-platform-build-kati-10.0.0+r32/version.h Examining data/android-platform-build-kati-10.0.0+r32/version_unknown.cc Examining data/android-platform-build-kati-10.0.0+r32/strutil.cc Examining data/android-platform-build-kati-10.0.0+r32/strutil.h Examining data/android-platform-build-kati-10.0.0+r32/fileutil.cc FINAL RESULTS: data/android-platform-build-kati-10.0.0+r32/fileutil.cc:160:15: [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. ssize_t l = readlink(PROC_CUR_EXE, mypath, PATH_MAX); data/android-platform-build-kati-10.0.0+r32/find.cc:987:21: [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. ssize_t len = readlink(path.c_str(), buf, PATH_MAX); data/android-platform-build-kati-10.0.0+r32/ninja.cc:705:9: [5] (race) chmod: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchmod( ) instead. if (chmod(GetNinjaShellScriptFilename().c_str(), 0755) != 0) data/android-platform-build-kati-10.0.0+r32/fileutil.cc:131: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[0], const_cast<char**>(argv)); data/android-platform-build-kati-10.0.0+r32/log.cc:53: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, data/android-platform-build-kati-10.0.0+r32/stringprintf.cc:28:15: [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. int ret = vsnprintf(&str[0], str.size(), format, args); data/android-platform-build-kati-10.0.0+r32/strutil_test.cc:181: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(buffer_str, str); data/android-platform-build-kati-10.0.0+r32/testutil.h:24:7: [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, \ data/android-platform-build-kati-10.0.0+r32/fileutil.cc:167:21: [3] (buffer) realpath: This function does not protect against buffer overflows, and some implementations can overflow internally (CWE-120/CWE-785!). Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN. char *real_path = realpath(mypath, NULL); data/android-platform-build-kati-10.0.0+r32/fileutil.cc:175:15: [3] (buffer) realpath: This function does not protect against buffer overflows, and some implementations can overflow internally (CWE-120/CWE-785!). Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN. char *ret = realpath(mypath, real_path); data/android-platform-build-kati-10.0.0+r32/flags.cc:57:31: [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 (const char* makeflags = getenv("MAKEFLAGS")) { data/android-platform-build-kati-10.0.0+r32/func.cc:412:9: [3] (buffer) realpath: This function does not protect against buffer overflows, and some implementations can overflow internally (CWE-120/CWE-785!). Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN. if (realpath(tok.data(), buf)) data/android-platform-build-kati-10.0.0+r32/main.cc:343:9: [3] (buffer) realpath: This function does not protect against buffer overflows, and some implementations can overflow internally (CWE-120/CWE-785!). Ensure that the destination buffer is at least of size MAXPATHLEN, andto protect against implementation problems, the input argument should also be checked to ensure it is no larger than MAXPATHLEN. if (realpath(argv[i], buf)) data/android-platform-build-kati-10.0.0+r32/ninja.cc:642:23: [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. StringPiece val(getenv(e.c_str())); data/android-platform-build-kati-10.0.0+r32/regen.cc:190:11: [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(s.c_str())) { data/android-platform-build-kati-10.0.0+r32/regen.cc:192:62: [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("env %s: dirty (unset => %s)\n", s.c_str(), getenv(s.c_str())); data/android-platform-build-kati-10.0.0+r32/regen.cc:206:23: [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. StringPiece val(getenv(s.c_str())); data/android-platform-build-kati-10.0.0+r32/file.cc:31: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). int fd = open(filename.c_str(), O_RDONLY); data/android-platform-build-kati-10.0.0+r32/fileutil.cc:91:14: [2] (race) vfork: On some old systems, vfork() permits race conditions, and it's very difficult to use correctly (CWE-362). Use fork() instead. if ((pid = vfork())) { data/android-platform-build-kati-10.0.0+r32/fileutil.cc:100: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. char buf[4096]; data/android-platform-build-kati-10.0.0+r32/fileutil.cc:122: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). int fd = open("/dev/null", O_WRONLY); data/android-platform-build-kati-10.0.0+r32/fileutil.cc:142: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 mypath[PATH_MAX + 1]; data/android-platform-build-kati-10.0.0+r32/fileutil.cc:174: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 real_path[PATH_MAX + 1]; data/android-platform-build-kati-10.0.0+r32/fileutil.cc:182: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 mypath[PATH_MAX + 1]; data/android-platform-build-kati-10.0.0+r32/find.cc:985: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 buf[PATH_MAX + 1]; data/android-platform-build-kati-10.0.0+r32/func.cc:279: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[32]; data/android-platform-build-kati-10.0.0+r32/func.cc:280: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(buf, "%d", n); data/android-platform-build-kati-10.0.0+r32/func.cc:411: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[PATH_MAX]; data/android-platform-build-kati-10.0.0+r32/func.cc:707: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). int fd = open(filename.c_str(), O_RDONLY); data/android-platform-build-kati-10.0.0+r32/func.cc:756:13: [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). FILE* f = fopen(filename.c_str(), append ? "ab" : "wb"); data/android-platform-build-kati-10.0.0+r32/main.cc:109: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 cwd[PATH_MAX]; data/android-platform-build-kati-10.0.0+r32/main.cc:143: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[11]; data/android-platform-build-kati-10.0.0+r32/main.cc:341: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[PATH_MAX]; data/android-platform-build-kati-10.0.0+r32/ninja.cc:590:11: [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). fp_ = fopen(GetNinjaFilename().c_str(), "wb"); data/android-platform-build-kati-10.0.0+r32/ninja.cc:666: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). FILE* fp = fopen(GetEnvScriptFilename().c_str(), "wb"); data/android-platform-build-kati-10.0.0+r32/ninja.cc:685: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). fp = fopen(GetNinjaShellScriptFilename().c_str(), "wb"); data/android-platform-build-kati-10.0.0+r32/ninja.cc:710: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). FILE* fp = fopen(GetStampTempFilename().c_str(), "wb"); data/android-platform-build-kati-10.0.0+r32/regen.cc:93:18: [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). FILE* fp = fopen(GetNinjaStampFilename().c_str(), "rb+"); data/android-platform-build-kati-10.0.0+r32/regen.cc:140: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). FILE* fp = fopen(stamp_filename.c_str(), "rb"); data/android-platform-build-kati-10.0.0+r32/regen.cc:376:11: [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). fopen(sr->cmd.c_str(), (sr->op == CommandOp::WRITE) ? "wb" : "ab"); data/android-platform-build-kati-10.0.0+r32/regen_dump.cc:55:14: [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). FILE* fp = fopen(argv[argc - 1], "rb"); data/android-platform-build-kati-10.0.0+r32/string_piece.cc:58: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(buf, ptr_ + pos, ret); data/android-platform-build-kati-10.0.0+r32/strutil.cc:381: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[PATH_MAX]; data/android-platform-build-kati-10.0.0+r32/strutil_test.cc:152: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[10] = {'f', 'o', '\\', '\0', 'x', 'y'}; data/android-platform-build-kati-10.0.0+r32/symtab.cc:119: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 b[2]; data/android-platform-build-kati-10.0.0+r32/testutil.h:35: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. static char buf[64]; data/android-platform-build-kati-10.0.0+r32/testutil.h:36: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(buf, "%zd", v); data/android-platform-build-kati-10.0.0+r32/file.cc:45:28: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ssize_t r = HANDLE_EINTR(read(fd, &buf_[0], len)); data/android-platform-build-kati-10.0.0+r32/fileutil.cc:101:34: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ssize_t r = HANDLE_EINTR(read(pipefd[0], buf, 4096)); data/android-platform-build-kati-10.0.0+r32/fileutil.cc:204:36: [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 (strcspn(pat, "?*[\\") != strlen(pat)) { data/android-platform-build-kati-10.0.0+r32/find.cc:675:37: [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). new NameCond(tok.substr(strlen("--prune=")).as_string()); data/android-platform-build-kati-10.0.0+r32/find.cc:682:42: [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). string mindepth_str = tok.substr(strlen("--mindepth=")).as_string(); data/android-platform-build-kati-10.0.0+r32/find.cc:691:38: [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). StringPiece dir = tok.substr(strlen("--dir=")); data/android-platform-build-kati-10.0.0+r32/func.cc:730:28: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ssize_t r = HANDLE_EINTR(read(fd, &out[0], len)); data/android-platform-build-kati-10.0.0+r32/main.cc:140:35: [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(STDERR_FILENO, s, strlen(s)); data/android-platform-build-kati-10.0.0+r32/string_piece.h:66:48: [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_(str), length_((str == NULL) ? 0 : strlen(str)) {} data/android-platform-build-kati-10.0.0+r32/string_piece.h:91: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). length_ = str ? strlen(str) : 0; data/android-platform-build-kati-10.0.0+r32/strutil_test.cc:180: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). buffer_str -= strlen(str) + 1; ANALYSIS SUMMARY: Hits = 58 Lines analyzed = 12403 in approximately 0.42 seconds (29804 lines/second) Physical Source Lines of Code (SLOC) = 9428 Hits@level = [0] 97 [1] 11 [2] 30 [3] 9 [4] 5 [5] 3 Hits@level+ = [0+] 155 [1+] 58 [2+] 47 [3+] 17 [4+] 8 [5+] 3 Hits/KSLOC@level+ = [0+] 16.4404 [1+] 6.15189 [2+] 4.98515 [3+] 1.80314 [4+] 0.848536 [5+] 0.318201 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.