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/mitlm-0.4.1/src/MaxLikelihoodSmoothing.h Examining data/mitlm-0.4.1/src/util/FastIO.h Examining data/mitlm-0.4.1/src/util/RefCounter.h Examining data/mitlm-0.4.1/src/util/CommandOptions.h Examining data/mitlm-0.4.1/src/util/CommandOptions.cpp Examining data/mitlm-0.4.1/src/util/ZFile.h Examining data/mitlm-0.4.1/src/util/RefCounter.cpp Examining data/mitlm-0.4.1/src/util/SharedPtr.h Examining data/mitlm-0.4.1/src/util/BitOps.h Examining data/mitlm-0.4.1/src/util/FastHash.h Examining data/mitlm-0.4.1/src/util/Logger.cpp Examining data/mitlm-0.4.1/src/util/Logger.h Examining data/mitlm-0.4.1/src/evaluate-ngram.cpp Examining data/mitlm-0.4.1/src/Smoothing.h Examining data/mitlm-0.4.1/src/Vocab.cpp Examining data/mitlm-0.4.1/src/Vocab.h Examining data/mitlm-0.4.1/src/Mask.h Examining data/mitlm-0.4.1/src/PerplexityOptimizer.cpp Examining data/mitlm-0.4.1/src/interpolate-ngram.cpp Examining data/mitlm-0.4.1/src/KneserNeySmoothing.h Examining data/mitlm-0.4.1/src/Lattice.cpp Examining data/mitlm-0.4.1/src/Smoothing.cpp Examining data/mitlm-0.4.1/src/NgramVector.cpp Examining data/mitlm-0.4.1/src/estimate-ngram.cpp Examining data/mitlm-0.4.1/src/PerplexityOptimizer.h Examining data/mitlm-0.4.1/src/NgramVector.h Examining data/mitlm-0.4.1/src/Lattice.h Examining data/mitlm-0.4.1/src/MaxLikelihoodSmoothing.cpp Examining data/mitlm-0.4.1/src/vector/Vector.h Examining data/mitlm-0.4.1/src/vector/DenseVector.h Examining data/mitlm-0.4.1/src/vector/Range.h Examining data/mitlm-0.4.1/src/vector/Operations.h Examining data/mitlm-0.4.1/src/vector/VectorClosures.h Examining data/mitlm-0.4.1/src/vector/Traits.h Examining data/mitlm-0.4.1/src/vector/VectorBuilder.h Examining data/mitlm-0.4.1/src/vector/VectorOps.h Examining data/mitlm-0.4.1/src/vector/Scalar.h Examining data/mitlm-0.4.1/src/WordErrorRateOptimizer.h Examining data/mitlm-0.4.1/src/InterpolatedNgramLM.h Examining data/mitlm-0.4.1/src/KneserNeySmoothing.cpp Examining data/mitlm-0.4.1/src/InterpolatedNgramLM.cpp Examining data/mitlm-0.4.1/src/NgramLM.h Examining data/mitlm-0.4.1/src/NgramModel.h Examining data/mitlm-0.4.1/src/optimize/Optimization.h Examining data/mitlm-0.4.1/src/optimize/LBFGS.h Examining data/mitlm-0.4.1/src/optimize/Powell.h Examining data/mitlm-0.4.1/src/optimize/LBFGSB.h Examining data/mitlm-0.4.1/src/optimize/fortran_wrapper.c Examining data/mitlm-0.4.1/src/WordErrorRateOptimizer.cpp Examining data/mitlm-0.4.1/src/Types.h Examining data/mitlm-0.4.1/src/NgramLM.cpp Examining data/mitlm-0.4.1/src/NgramModel.cpp FINAL RESULTS: data/mitlm-0.4.1/src/Lattice.cpp:119:17: [4] (buffer) sscanf: The scanf() family's %s operation, without a limit specification, permits buffer overflows (CWE-120, CWE-20). Specify a limit to %s, or use a different input function. if (sscanf(line, "T %u %u %s %s %f", data/mitlm-0.4.1/src/NgramLM.cpp:199:13: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. sprintf(feature, feats[f].c_str(), GetBasename(corpusFile).c_str()); data/mitlm-0.4.1/src/NgramModel.cpp:1000:24: [4] (buffer) sscanf: The scanf() family's %s operation, without a limit specification, permits buffer overflows (CWE-120, CWE-20). Specify a limit to %s, or use a different input function. int numItems = sscanf(line, "%s\t%d\t%d\n", wordStr, &state, &topic); data/mitlm-0.4.1/src/NgramModel.cpp:1066:24: [4] (buffer) sscanf: The scanf() family's %s operation, without a limit specification, permits buffer overflows (CWE-120, CWE-20). Specify a limit to %s, or use a different input function. int numItems = sscanf(line, "%s\t%d\t%d\n", wordStr, &state, &topic); data/mitlm-0.4.1/src/estimate-ngram.cpp:81:5: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. sprintf(footerDesc, footerDesc_tmpl, PACKAGE_STRING); data/mitlm-0.4.1/src/evaluate-ngram.cpp:80:5: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. sprintf(footerDesc, footerDesc_tmpl, PACKAGE_STRING); data/mitlm-0.4.1/src/interpolate-ngram.cpp:83:5: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. sprintf(footerDesc, footerDesc_tmpl, PACKAGE_STRING); data/mitlm-0.4.1/src/interpolate-ngram.cpp:251:17: [4] (format) sprintf: Potential format string problem (CWE-134). Make format string constant. sprintf(feature, features[f].c_str(), data/mitlm-0.4.1/src/util/Logger.cpp:61:13: [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. vfprintf(_out_file, fmt, args); data/mitlm-0.4.1/src/util/Logger.cpp:79:13: [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. vfprintf(_err_file, fmt, args); data/mitlm-0.4.1/src/util/Logger.cpp:98:13: [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. vfprintf(_err_file, fmt, args); data/mitlm-0.4.1/src/util/ZFile.h:165:14: [4] (shell) popen: 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. { return popen(command.c_str(), mode); } data/mitlm-0.4.1/src/Lattice.cpp:103: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 wordStr[MAXLINE], line[MAXLINE]; data/mitlm-0.4.1/src/NgramLM.cpp:198:13: [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 feature[1024]; data/mitlm-0.4.1/src/NgramModel.cpp:100: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:181: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:202:47: [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). countVectors[order][index] += atoi(token); data/mitlm-0.4.1/src/NgramModel.cpp:262: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:460: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:521: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:832: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:911: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:993: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:994: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 wordStr[1024]; data/mitlm-0.4.1/src/NgramModel.cpp:1060: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 line[MAXLINE]; data/mitlm-0.4.1/src/NgramModel.cpp:1061: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 wordStr[1024]; data/mitlm-0.4.1/src/Smoothing.cpp:49:39: [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). return new KneserNeySmoothing(atoi(&smoothing[5]), false); data/mitlm-0.4.1/src/Smoothing.cpp:57:39: [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). return new KneserNeySmoothing(atoi(&smoothing[2]), true); data/mitlm-0.4.1/src/Vocab.cpp:178: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 line[4096]; data/mitlm-0.4.1/src/WordErrorRateOptimizer.cpp:59: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 line[MAXLINE]; data/mitlm-0.4.1/src/estimate-ngram.cpp:117:20: [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). size_t order = atoi(opts["order"]); data/mitlm-0.4.1/src/estimate-ngram.cpp:119:33: [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). mitlm::Logger::SetVerbosity(atoi(opts["verbose"])); data/mitlm-0.4.1/src/evaluate-ngram.cpp:103:20: [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). size_t order = atoi(opts["order"]); data/mitlm-0.4.1/src/evaluate-ngram.cpp:105:33: [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). mitlm::Logger::SetVerbosity(atoi(opts["verbose"])); data/mitlm-0.4.1/src/interpolate-ngram.cpp:120:20: [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). size_t order = atoi(opts["order"]); data/mitlm-0.4.1/src/interpolate-ngram.cpp:122:33: [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). mitlm::Logger::SetVerbosity(atoi(opts["verbose"])); data/mitlm-0.4.1/src/interpolate-ngram.cpp:250:17: [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 feature[1024]; data/mitlm-0.4.1/src/optimize/LBFGSB.h: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 task[60]; data/mitlm-0.4.1/src/optimize/LBFGSB.h:68: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 csave[60]; data/mitlm-0.4.1/src/optimize/LBFGSB.h:90:17: [2] (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). Risk is low because the source is a constant string. strcpy(task, "STOP: TOTAL NO. ITERATIONS EXCEEDS LIMIT"); data/mitlm-0.4.1/src/util/FastIO.h:194: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[256]; data/mitlm-0.4.1/src/util/ZFile.h:200:21: [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 = fopen(_filename.c_str(), mode); data/mitlm-0.4.1/src/NgramModel.cpp:298:30: [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 lineLen = strlen(line); data/mitlm-0.4.1/src/Smoothing.cpp:47: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). for (size_t i = 5; i < strlen(smoothing); ++i) data/mitlm-0.4.1/src/Smoothing.cpp:55: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). for (size_t i = 2; i < strlen(smoothing); ++i) data/mitlm-0.4.1/src/Vocab.h:80:65: [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). VocabIndex Find(const char *word) const { return Find(word, strlen(word)); } data/mitlm-0.4.1/src/Vocab.h:82:57: [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). VocabIndex Add(const char *word) { return Add(word, strlen(word)); } data/mitlm-0.4.1/src/estimate-ngram.cpp:80:33: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/estimate-ngram.cpp:80:57: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/evaluate-ngram.cpp:79:33: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/evaluate-ngram.cpp:79:57: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/interpolate-ngram.cpp:82:33: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/interpolate-ngram.cpp:82:57: [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). char *footerDesc = new char[strlen(footerDesc_tmpl)+strlen(PACKAGE_STRING)+1+59]; data/mitlm-0.4.1/src/optimize/LBFGSB.h:75:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). Risk is low because the source is a constant string. strncpy(task, "START", 5); data/mitlm-0.4.1/src/util/CommandOptions.cpp:132:33: [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). const char *end = str + strlen(str); data/mitlm-0.4.1/src/util/FastIO.h:69: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). size_t len = strlen(buf) - 1; data/mitlm-0.4.1/src/util/FastIO.h:81:19: [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). *outLen = strlen(buf) - 1; data/mitlm-0.4.1/src/util/FastIO.h:142: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 len = strlen(header); data/mitlm-0.4.1/src/util/FastIO.h:195: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 len = strlen(header); data/mitlm-0.4.1/src/util/ZFile.h:158: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). size_t strLen = strlen(str); data/mitlm-0.4.1/src/util/ZFile.h:159:28: [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 suffixLen = strlen(suffix); ANALYSIS SUMMARY: Hits = 61 Lines analyzed = 9558 in approximately 0.28 seconds (33978 lines/second) Physical Source Lines of Code (SLOC) = 6228 Hits@level = [0] 39 [1] 19 [2] 30 [3] 0 [4] 12 [5] 0 Hits@level+ = [0+] 100 [1+] 61 [2+] 42 [3+] 12 [4+] 12 [5+] 0 Hits/KSLOC@level+ = [0+] 16.0565 [1+] 9.79448 [2+] 6.74374 [3+] 1.92678 [4+] 1.92678 [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.