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/genext2fs-1.5.0/cache.h Examining data/genext2fs-1.5.0/genext2fs.c Examining data/genext2fs-1.5.0/list.h FINAL RESULTS: data/genext2fs-1.5.0/genext2fs.c:2866:10: [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 (readlink(dent->d_name, lnk, st.st_size) > 0) data/genext2fs-1.5.0/genext2fs.c:388:8: [4] (format) vsprintf: Potential format string problem (CWE-134). Make format string constant. ret = vsprintf(str, fmt, ap); data/genext2fs-1.5.0/genext2fs.c:394:19: [4] (format) snprintf: 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. # define SNPRINTF snprintf data/genext2fs-1.5.0/genext2fs.c:789:2: [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, s, p); data/genext2fs-1.5.0/genext2fs.c:2566: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(lnk, archive_entry_symlink(entry)); data/genext2fs-1.5.0/genext2fs.c:3758:13: [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, "x:d:D:a:B:b:i:N:L:m:o:g:e:zfqUPhVv", longopts, NULL)) != EOF) { data/genext2fs-1.5.0/genext2fs.c:3762:13: [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((c = getopt(argc, argv, "x:d:D:a:B:b:i:N:L:m:o:g:e:zfqUPhVv")) != EOF) { data/genext2fs-1.5.0/genext2fs.c:3898:30: [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 *source_date_epoch = getenv("SOURCE_DATE_EPOCH"); data/genext2fs-1.5.0/genext2fs.c:173: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 filename[100]; data/genext2fs-1.5.0/genext2fs.c:174: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 filemode[8]; data/genext2fs-1.5.0/genext2fs.c:175: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 uid[8]; data/genext2fs-1.5.0/genext2fs.c:176: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 gid[8]; data/genext2fs-1.5.0/genext2fs.c:177: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 filesize[12]; data/genext2fs-1.5.0/genext2fs.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 mtime[12]; data/genext2fs-1.5.0/genext2fs.c:179: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 checksum[8]; data/genext2fs-1.5.0/genext2fs.c:181: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 linkedname[100]; data/genext2fs-1.5.0/genext2fs.c:182: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 ustar[8]; data/genext2fs-1.5.0/genext2fs.c:183: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 owner[32]; data/genext2fs-1.5.0/genext2fs.c:184: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 group[32]; data/genext2fs-1.5.0/genext2fs.c:185: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 major[8]; data/genext2fs-1.5.0/genext2fs.c:186: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 minor[8]; data/genext2fs-1.5.0/genext2fs.c:187: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 prefix[155]; data/genext2fs-1.5.0/genext2fs.c:838: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). if ((fp = fopen(path, mode)) == NULL) data/genext2fs-1.5.0/genext2fs.c:1255:2: [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(&dw->d, dw->last_d, sizeof(directory)); data/genext2fs-1.5.0/genext2fs.c:1270: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(dw->last_d, &dw->d, sizeof(directory)); data/genext2fs-1.5.0/genext2fs.c:1280:2: [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(&dw->d, next_d, sizeof(directory)); data/genext2fs-1.5.0/genext2fs.c:1294: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(dw->last_d, &dw->d, sizeof(directory)); data/genext2fs-1.5.0/genext2fs.c:1337:2: [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(dw->last_d, &dw->d, sizeof(directory)); data/genext2fs-1.5.0/genext2fs.c:1865:4: [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(block, b + pos, BLOCKSIZE); data/genext2fs-1.5.0/genext2fs.c:2084:4: [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(node->i_block, b, 4 * (EXT2_TIND_BLOCK + 1)); data/genext2fs-1.5.0/genext2fs.c:2260: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[TAR_BLOCKSIZE]; data/genext2fs-1.5.0/genext2fs.c:2261: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 pathbuf[TAR_FULLFILENAME], *path, *path2 = NULL, *dir, *name; data/genext2fs-1.5.0/genext2fs.c:2873: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). fh = fopen(dent->d_name, "rb"); data/genext2fs-1.5.0/genext2fs.c:2969:11: [2] (tmpfile) tmpfile: Function tmpfile() has a security flaw on some systems (e.g., older System V systems) (CWE-377). fs->f = tmpfile(); data/genext2fs-1.5.0/genext2fs.c:2979: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). fs->f = fopen(fname, "r+b"); data/genext2fs-1.5.0/genext2fs.c:2981: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). fs->f = fopen(fname, "w+b"); data/genext2fs-1.5.0/genext2fs.c:2986: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). fs->f = fopen(fname, "w+b"); data/genext2fs-1.5.0/genext2fs.c:3370:25: [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. make_perms(uint32 mode, char perms[11]) data/genext2fs-1.5.0/genext2fs.c:3372:2: [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(perms, "----------"); data/genext2fs-1.5.0/genext2fs.c:3433: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 perms[11]; data/genext2fs-1.5.0/genext2fs.c:3613: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). if((pdir = open(".", O_RDONLY)) < 0) data/genext2fs-1.5.0/genext2fs.c:3688:24: [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 atoi(name); data/genext2fs-1.5.0/genext2fs.c:3715: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 * gopt[MAX_GOPT]; data/genext2fs-1.5.0/genext2fs.c:3806:16: [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). emptyval = atoi(optarg); data/genext2fs-1.5.0/genext2fs.c:3935: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 fname[MAX_FILENAME]; data/genext2fs-1.5.0/genext2fs.c:1319:2: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(((char *) dw->last_d) + sizeof(directory), name, nlen); data/genext2fs-1.5.0/genext2fs.c:1343:2: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(((char *) dw->last_d) + sizeof(directory), name, nlen); data/genext2fs-1.5.0/genext2fs.c:1369:2: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(((char *) dw->last_d) + sizeof(directory), name, nlen); data/genext2fs-1.5.0/genext2fs.c:1892: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). nlen = strlen(name); data/genext2fs-1.5.0/genext2fs.c:1951:13: [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). int nlen = strlen(name); data/genext2fs-1.5.0/genext2fs.c:2324:4: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(pathbuf, tarhead->prefix, sizeof tarhead->prefix); data/genext2fs-1.5.0/genext2fs.c:2325:4: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(pathbuf+strnlen(pathbuf, sizeof pathbuf), tarhead->filename, sizeof tarhead->filename); data/genext2fs-1.5.0/genext2fs.c:2334: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). if (strlen(tarhead->linkedname) >= 4 * (EXT2_TIND_BLOCK+1)) data/genext2fs-1.5.0/genext2fs.c:2413: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). mklink_fs(fs, nod, name, strlen(longlink), (uint8*)longlink, uid, gid, ctime, mtime); data/genext2fs-1.5.0/genext2fs.c:2415: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). mklink_fs(fs, nod, name, strlen(tarhead->linkedname), (uint8*)tarhead->linkedname, uid, gid, ctime, mtime); data/genext2fs-1.5.0/genext2fs.c:2565: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). lnk = calloc(1, rndup(strlen(archive_entry_symlink(entry)), BLOCKSIZE)); data/genext2fs-1.5.0/genext2fs.c:2569: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). mklink_fs(fs, nod, name, strlen(archive_entry_symlink(entry)), (uint8*)lnk, uid, gid, ctime, mtime); data/genext2fs-1.5.0/genext2fs.c:2729: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(name) + 10; data/genext2fs-1.5.0/genext2fs.c:3910:3: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy((char *)fs->sb->s_volume_name, volumelabel, ANALYSIS SUMMARY: Hits = 59 Lines analyzed = 4162 in approximately 0.14 seconds (30239 lines/second) Physical Source Lines of Code (SLOC) = 3461 Hits@level = [0] 51 [1] 14 [2] 37 [3] 3 [4] 4 [5] 1 Hits@level+ = [0+] 110 [1+] 59 [2+] 45 [3+] 8 [4+] 5 [5+] 1 Hits/KSLOC@level+ = [0+] 31.7827 [1+] 17.0471 [2+] 13.002 [3+] 2.31147 [4+] 1.44467 [5+] 0.288934 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.