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/sshguard-2.3.1/src/parser/attack_scanner.c Examining data/sshguard-2.3.1/src/parser/parser.h Examining data/sshguard-2.3.1/src/parser/attack_parser.c Examining data/sshguard-2.3.1/src/parser/attack.c Examining data/sshguard-2.3.1/src/parser/attack_parser.h Examining data/sshguard-2.3.1/src/parser/parser.c Examining data/sshguard-2.3.1/src/common/simclist.h Examining data/sshguard-2.3.1/src/common/address.h Examining data/sshguard-2.3.1/src/common/attack.h Examining data/sshguard-2.3.1/src/common/simclist.c Examining data/sshguard-2.3.1/src/common/sandbox.h Examining data/sshguard-2.3.1/src/blocker/attack.c Examining data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c Examining data/sshguard-2.3.1/src/blocker/sshguard_blacklist.c Examining data/sshguard-2.3.1/src/blocker/sshguard_options.h Examining data/sshguard-2.3.1/src/blocker/blocklist.c Examining data/sshguard-2.3.1/src/blocker/sshguard_log.h Examining data/sshguard-2.3.1/src/blocker/fnv.h Examining data/sshguard-2.3.1/src/blocker/sshguard_blacklist.h Examining data/sshguard-2.3.1/src/blocker/hash_32a.c Examining data/sshguard-2.3.1/src/blocker/sshguard_whitelist.h Examining data/sshguard-2.3.1/src/blocker/blocker.c Examining data/sshguard-2.3.1/src/blocker/blocklist.h Examining data/sshguard-2.3.1/src/blocker/sshguard_options.c Examining data/sshguard-2.3.1/src/fw/hosts.c Examining data/sshguard-2.3.1/src/fw/fw.h FINAL RESULTS: data/sshguard-2.3.1/src/fw/hosts.c:73: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(tempflname, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) != 0) { data/sshguard-2.3.1/src/blocker/attack.c:16: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(ipe->attack.address.value, attack->address.value); data/sshguard-2.3.1/src/blocker/sshguard_options.c:64:21: [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(optarg, "%u:%s", &opts.blacklist_threshold, data/sshguard-2.3.1/src/fw/hosts.c:148: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(ads.addr, attack->address.value); data/sshguard-2.3.1/src/fw/hosts.c:230: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(tmp, HOSTS_SSHGUARD_SUFFIX); data/sshguard-2.3.1/src/parser/attack_parser.c:950:21: [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. # define YYFPRINTF fprintf data/sshguard-2.3.1/src/parser/attack_parser.c:1708:25: [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(attack->address.value, (yyvsp[0].str)); data/sshguard-2.3.1/src/parser/attack_parser.c:1717:25: [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(attack->address.value, (yyvsp[0].str)); data/sshguard-2.3.1/src/parser/attack_parser.c:1727:25: [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(attack->address.value, (yyvsp[-2].str)); data/sshguard-2.3.1/src/blocker/blocker.c:107:27: [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. int sshg_debugging = (getenv("SSHGUARD_DEBUG") != NULL); data/sshguard-2.3.1/src/blocker/blocker.c:110:5: [3] (random) srand: This function is not sufficiently random for security-related functions such as key and nonce creation (CWE-327). Use a more secure technique for acquiring random values. srand(time(NULL)); data/sshguard-2.3.1/src/blocker/sshguard_options.c:60:21: [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 ((optch = getopt(argc, argv, "b:p:s:a:w:i:N:n:")) != -1) { data/sshguard-2.3.1/src/parser/parser.c:94:20: [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 ((flag = getopt(argc, argv, "adht")) != -1) { data/sshguard-2.3.1/src/blocker/blocker.c:74:15: [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 *p = fopen(opts.my_pidfile, "w"); data/sshguard-2.3.1/src/blocker/blocker.c:158: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[1024]; data/sshguard-2.3.1/src/blocker/blocker.c:177: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 time_msg[128] = "forever"; data/sshguard-2.3.1/src/blocker/blocker.c:262:9: [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(offenderent, tmpent, sizeof(attacker_t)); data/sshguard-2.3.1/src/blocker/sshguard_blacklist.c:57: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 blacklist_line[BL_MAXBUF]; data/sshguard-2.3.1/src/blocker/sshguard_blacklist.c:61:22: [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). blacklist_file = fopen(filename, "a+"); data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:137: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[WHITELIST_SRCLINE_LEN]; data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:144: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). src = fopen(filename, "r"); data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:182: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[ADDRLEN+5]; data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:336: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 addrstring[ADDRLEN]; data/sshguard-2.3.1/src/common/address.h:49: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 value[ADDRLEN]; /* address of offender */ data/sshguard-2.3.1/src/common/simclist.c:484:9: [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(lent->data, data, datalen); data/sshguard-2.3.1/src/common/simclist.c:1070: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). fd = open(filename, O_RDONLY, 0); data/sshguard-2.3.1/src/common/simclist.c:1351: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). fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); data/sshguard-2.3.1/src/common/simclist.c:1364: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). fd = open(filename, O_RDONLY, 0); data/sshguard-2.3.1/src/fw/hosts.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 addr[ADDRLEN]; data/sshguard-2.3.1/src/fw/hosts.c:57: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 tempflname[MAX_TEMPFILE_NAMELEN] = ""; data/sshguard-2.3.1/src/fw/hosts.c:69:9: [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). f = fopen(tempflname, "w+"); data/sshguard-2.3.1/src/fw/hosts.c:94: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[HOSTS_MAXCMDLEN]; data/sshguard-2.3.1/src/fw/hosts.c:106:12: [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). deny = fopen(HOSTSFILE_PATH, "r+"); data/sshguard-2.3.1/src/fw/hosts.c:172: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[HOSTS_MAXCMDLEN]; data/sshguard-2.3.1/src/fw/hosts.c:176:12: [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). deny = fopen(HOSTSFILE_PATH, "r+"); data/sshguard-2.3.1/src/fw/hosts.c:277: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[HOSTS_MAXCMDLEN]; data/sshguard-2.3.1/src/fw/hosts.c:282:12: [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). deny = fopen(HOSTSFILE_PATH, "r+"); data/sshguard-2.3.1/src/fw/hosts.c:351: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[128]; data/sshguard-2.3.1/src/parser/attack_parser.c:1197: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 const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; data/sshguard-2.3.1/src/parser/attack_parser.c:1386: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 yymsgbuf[128]; data/sshguard-2.3.1/src/parser/attack_scanner.c:80643: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 yytext[YYLMAX]; data/sshguard-2.3.1/src/parser/parser.c:24:26: [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 void parse_to_buf(char buf[static 1], char dst[static MAX_LEN]) { data/sshguard-2.3.1/src/parser/parser.c:24:46: [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 void parse_to_buf(char buf[static 1], char dst[static MAX_LEN]) { data/sshguard-2.3.1/src/parser/parser.c:40:28: [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 void test_next_line(char buf[static MAX_LEN]) { data/sshguard-2.3.1/src/parser/parser.c:42: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 expected[MAX_LEN], result[MAX_LEN]; data/sshguard-2.3.1/src/parser/parser.c:89: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[MAX_LEN]; data/sshguard-2.3.1/src/blocker/blocker.c:161:13: [1] (buffer) sscanf: It's unclear if the %s limit in the format string is small enough (CWE-120). Check that the limit is sufficiently small, or use a different input function. if (sscanf(buf, "%d %46s %d %d\n", (int*)&parsed_attack.service, data/sshguard-2.3.1/src/blocker/sshguard_blacklist.c:77: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). while (blacklist_line[strlen(blacklist_line)-1] != '\n') { data/sshguard-2.3.1/src/blocker/sshguard_options.c:63:58: [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). opts.blacklist_filename = (char *)malloc(strlen(optarg) + 1); data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:155: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). len = strlen(line); data/sshguard-2.3.1/src/blocker/sshguard_whitelist.c:185:9: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(buf, str, sizeof(buf)); data/sshguard-2.3.1/src/common/simclist.c:187:57: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if (read(fd, msgbuf, msglen) != msglen) { \ data/sshguard-2.3.1/src/common/simclist.c:1437:51: [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 list_meter_string(const void *el) { return strlen((const char *)el) + 1; } data/sshguard-2.3.1/src/fw/hosts.c:338:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(address.value, addr, ADDRLEN); data/sshguard-2.3.1/src/parser/attack_parser.c:1097: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). # define yystrlen strlen data/sshguard-2.3.1/src/parser/attack_scanner.c:80856:14: [1] (buffer) getc: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ data/sshguard-2.3.1/src/parser/attack_scanner.c:82441:29: [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 yy_scan_bytes(yystr,strlen(yystr) ); data/sshguard-2.3.1/src/parser/parser.c:32:9: [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(dst, "*\n", MAX_LEN); data/sshguard-2.3.1/src/parser/parser.c:52:13: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(expected, buf, sizeof(expected)); ANALYSIS SUMMARY: Hits = 59 Lines analyzed = 90034 in approximately 5.33 seconds (16881 lines/second) Physical Source Lines of Code (SLOC) = 78591 Hits@level = [0] 49 [1] 13 [2] 33 [3] 4 [4] 8 [5] 1 Hits@level+ = [0+] 108 [1+] 59 [2+] 46 [3+] 13 [4+] 9 [5+] 1 Hits/KSLOC@level+ = [0+] 1.3742 [1+] 0.750722 [2+] 0.585309 [3+] 0.165413 [4+] 0.114517 [5+] 0.0127241 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.