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/insserv-1.21.0/systemd.h Examining data/insserv-1.21.0/map.c Examining data/insserv-1.21.0/systemd.c Examining data/insserv-1.21.0/listing.h Examining data/insserv-1.21.0/listing.c Examining data/insserv-1.21.0/insserv.c FINAL RESULTS: data/insserv-1.21.0/insserv.c:1425:13: [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. if ((len = readlink(script, buf, sizeof(buf)-1)) < 0) data/insserv-1.21.0/listing.h:388:47: [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. # define xreadlink(d,x,b,l) (__extension__ ({ readlink(x,b,l); })) data/insserv-1.21.0/insserv.c:1210:5: [4] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). strcat(strcat(strcpy(buf, myname), ": "), fmt); data/insserv-1.21.0/insserv.c:1210:19: [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). strcat(strcat(strcpy(buf, myname), ": "), fmt); data/insserv-1.21.0/insserv.c:1211:5: [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(stderr, buf, ap); data/insserv-1.21.0/insserv.c:1500:16: [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. if ((script = popen(cmd, "r")) == (FILE*)0) data/insserv-1.21.0/insserv.c:2177:8: [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(r->name, token); data/insserv-1.21.0/insserv.c:2418: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(r->name, token); data/insserv-1.21.0/insserv.c:2682:9: [4] (race) access: This usually indicates a security flaw. If an attacker can change anything along the path between the call to access() and the file's actual use (e.g., by moving files), the attacker can exploit the race condition (CWE-362/CWE-367!). Set up the correct permissions (e.g., using setuid()) and try to open the file directly. if (access(p, F_OK) >= 0) data/insserv-1.21.0/insserv.c:2719:12: [4] (shell) system: 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. err = system(p); data/insserv-1.21.0/insserv.c:3001:6: [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(root, pwd); data/insserv-1.21.0/insserv.c:3004:6: [4] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). strcat(root, path); data/insserv-1.21.0/insserv.c:3056:9: [4] (race) access: This usually indicates a security flaw. If an attacker can change anything along the path between the call to access() and the file's actual use (e.g., by moving files), the attacker can exploit the race condition (CWE-362/CWE-367!). Set up the correct permissions (e.g., using setuid()) and try to open the file directly. if (access(SYSTEMD_BINARY_PATH, F_OK) == 0 && (sbus = systemd_open_conn())) { data/insserv-1.21.0/insserv.c:4108:6: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(olink, "../%s", script); data/insserv-1.21.0/insserv.c:4109:6: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(nlink, "S%.2d%s", serv->attr.sorder, script); data/insserv-1.21.0/insserv.c:4158:6: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(olink, "../%s", script); data/insserv-1.21.0/insserv.c:4159:6: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(nlink, "K%.2d%s", serv->attr.korder, script); data/insserv-1.21.0/insserv.c:4290:6: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(olink, "../init.d/%s", script); data/insserv-1.21.0/insserv.c:4296:3: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(nlink, "K%.2d%s", serv->attr.korder, script); data/insserv-1.21.0/insserv.c:4299:3: [4] (buffer) sprintf: Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or vsnprintf. sprintf(nlink, "S%.2d%s", serv->attr.sorder, script); data/insserv-1.21.0/listing.c:139: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(serv->name, name); data/insserv-1.21.0/listing.h:328:77: [4] (format) printf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. extern void error(const char *restrict fmt, ...) attribute((noreturn,format(printf,1,2))); data/insserv-1.21.0/listing.h:329:68: [4] (format) printf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. extern void warn (const char *restrict fmt, ...) attribute((format(printf,1,2))); data/insserv-1.21.0/listing.h:330:79: [4] (format) printf: If format strings can be influenced by an attacker, they can be exploited (CWE-134). Use a constant for the format specification. extern void info (int level, const char *restrict fmt, ...) attribute((format(printf,2,3))); data/insserv-1.21.0/systemd.c:72:2: [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(this->name+1, name); data/insserv-1.21.0/systemd.c:75:2: [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(this->name, name); data/insserv-1.21.0/insserv.c:2838:17: [3] (buffer) getopt_long: 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_long(argc, argv, "c:dfrhqvni:o:p:u:es", long_options, (int *)0)) != -1) { data/insserv-1.21.0/insserv.c:175: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 buf[LINE_MAX]; data/insserv-1.21.0/insserv.c:241: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 empty[1] = ""; data/insserv-1.21.0/insserv.c:308: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 line[32]; data/insserv-1.21.0/insserv.c:313: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). my_file = fopen(FILE_FILTER_PATH, "r"); data/insserv-1.21.0/insserv.c:889: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 current_path[PATH_MAX]; data/insserv-1.21.0/insserv.c:900:19: [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). if (!(boot = fopen(current_path, "w"))) { data/insserv-1.21.0/insserv.c:906:19: [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). if (!(start = fopen(current_path, "w"))) { data/insserv-1.21.0/insserv.c:1062:19: [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). if (!(stop = fopen(current_path, "w"))) { data/insserv-1.21.0/insserv.c:1069: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). if (!(halt = fopen(current_path, "w"))) { data/insserv-1.21.0/insserv.c:1209: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[strlen(myname)+2+strlen(fmt)+1]; data/insserv-1.21.0/insserv.c:1210:12: [2] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). Risk is low because the source is a constant string. strcat(strcat(strcpy(buf, myname), ": "), fmt); data/insserv-1.21.0/insserv.c:1401: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+1]; data/insserv-1.21.0/insserv.c:1439: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[0], script, dirlen); data/insserv-1.21.0/insserv.c:1495: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 cmd[PATH_MAX]; data/insserv-1.21.0/insserv.c:1693: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 linkbuf[PATH_MAX+1]; data/insserv-1.21.0/insserv.c:1731: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(&linkbuf[0], script, dirname_len); data/insserv-1.21.0/insserv.c:1757: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 fullpath[PATH_MAX+1]; data/insserv-1.21.0/insserv.c:1902: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 str[20]; data/insserv-1.21.0/insserv.c:1981:14: [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). order = atoi(ptr); data/insserv-1.21.0/insserv.c:2110: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). if ((conf = fopen(fptr, "r"))) data/insserv-1.21.0/insserv.c:2113: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). if ((conf = fopen(file, "r"))) data/insserv-1.21.0/insserv.c:2276: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 path[PATH_MAX+1]; data/insserv-1.21.0/insserv.c:2296:6: [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/insserv-1.21.0/insserv.c:2586: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], *argv[3], *ptr; data/insserv-1.21.0/insserv.c:2595: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). if ((fd = open(buf, O_NOCTTY|O_RDONLY)) >= 0) data/insserv-1.21.0/insserv.c:2658:17: [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). if ((argc = atoi(argv[2])) >= 0 && argc <= 2) data/insserv-1.21.0/insserv.c:2808: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 * argr[argc]; data/insserv-1.21.0/insserv.c:2878:20: [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 current_dir[PATH_MAX]; data/insserv-1.21.0/insserv.c:3241:6: [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 linkbuf[PATH_MAX+1]; data/insserv-1.21.0/insserv.c:4029: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 nlink[PATH_MAX+1], olink[PATH_MAX+1]; data/insserv-1.21.0/insserv.c:4214: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 nlink[PATH_MAX+1], olink[PATH_MAX+1]; data/insserv-1.21.0/listing.h:393:41: [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). # define xopen(d,x,f) (__extension__ ({ open(x,f); })) data/insserv-1.21.0/insserv.c:331: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). string_length = strlen(line); data/insserv-1.21.0/insserv.c:1209:14: [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 buf[strlen(myname)+2+strlen(fmt)+1]; data/insserv-1.21.0/insserv.c:1209:31: [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 buf[strlen(myname)+2+strlen(fmt)+1]; data/insserv-1.21.0/insserv.c:1696:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(linkbuf, script, sizeof(linkbuf)-1); data/insserv-1.21.0/insserv.c:1888: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). if (!*token || strlen(token) != 1) data/insserv-1.21.0/insserv.c:1929:9: [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(str) == 0) data/insserv-1.21.0/insserv.c:2199: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). if (!strncmp("<interactive>", key, strlen(key))) { data/insserv-1.21.0/insserv.c:2605:16: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). if ((len = read(fd , buf, sizeof(buf)-1)) < 0) data/insserv-1.21.0/insserv.c:2628: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). if (strncmp(argv[0], shell, strlen(shell)) != 0) { data/insserv-1.21.0/insserv.c:2637: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). if (strncmp(argv[1], tmppath, strlen(tmppath)) != 0) { data/insserv-1.21.0/insserv.c:2642:11: [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(tmppath); data/insserv-1.21.0/insserv.c:2896:7: [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). l = strlen(optarg) - 1; data/insserv-1.21.0/insserv.c:2965:23: [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 size_t l = strlen(*argv) - 1; data/insserv-1.21.0/insserv.c:2997:12: [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(pwd)+2+strlen(path); data/insserv-1.21.0/insserv.c:2997:26: [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(pwd)+2+strlen(path); data/insserv-1.21.0/insserv.c:3003:3: [1] (buffer) strcat: Does not check for buffer overflows when concatenating to destination [MS-banned] (CWE-120). Consider using strcat_s, strncat, strlcat, or snprintf (warning: strncat is easily misused). Risk is low because the source is a constant character. strcat(root, "/"); data/insserv-1.21.0/insserv.c:3271: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 (!strncmp(d->d_name, "README", strlen("README"))) { data/insserv-1.21.0/insserv.c:3277: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). if (!strncmp(d->d_name, "Makefile", strlen("Makefile"))) { data/insserv-1.21.0/insserv.c:3317:16: [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 (d->d_name[strlen(d->d_name)-1] == '~') { data/insserv-1.21.0/insserv.c:3776: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). mark[c].order += strlen(mark[c].wrd); data/insserv-1.21.0/insserv.c:3781: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). size_t len = strlen(mark[c].order); data/insserv-1.21.0/listing.h:110: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). #define strsize(string) ((strlen(string)+1)*sizeof(char)) ANALYSIS SUMMARY: Hits = 81 Lines analyzed = 6725 in approximately 0.20 seconds (34277 lines/second) Physical Source Lines of Code (SLOC) = 5127 Hits@level = [0] 56 [1] 22 [2] 32 [3] 1 [4] 24 [5] 2 Hits@level+ = [0+] 137 [1+] 81 [2+] 59 [3+] 27 [4+] 26 [5+] 2 Hits/KSLOC@level+ = [0+] 26.7213 [1+] 15.7987 [2+] 11.5077 [3+] 5.26624 [4+] 5.07119 [5+] 0.390092 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.