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/jpegoptim-1.4.6/getopt.c Examining data/jpegoptim-1.4.6/getopt.h Examining data/jpegoptim-1.4.6/getopt1.c Examining data/jpegoptim-1.4.6/jpegdest.c Examining data/jpegoptim-1.4.6/jpegoptim.c Examining data/jpegoptim-1.4.6/jpegoptim.h Examining data/jpegoptim-1.4.6/misc.c Examining data/jpegoptim-1.4.6/win32_compat.h FINAL RESULTS: data/jpegoptim-1.4.6/jpegoptim.c:875:10: [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(outfname,(file_stat.st_mode & 0777)) != 0) data/jpegoptim-1.4.6/jpegoptim.c:879:10: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. if (chown(outfname, data/jpegoptim-1.4.6/win32_compat.h:33:9: [5] (race) chown: This accepts filename arguments; if an attacker can move those files, a race condition results. (CWE-362). Use fchown( ) instead. #define chown(outfname,st_uid,st_gid) 0 data/jpegoptim-1.4.6/jpegoptim.c:151:3: [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,PROGRAMNAME " v" VERSIO " " COPYRIGHT "\n"); data/jpegoptim-1.4.6/jpegoptim.c:201:3: [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. printf(PROGRAMNAME " v%s %s\n",VERSIO,HOST_TYPE); data/jpegoptim-1.4.6/jpegoptim.c:202:3: [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. printf(COPYRIGHT "\n\n"); data/jpegoptim-1.4.6/jpegoptim.c:219: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,PROGRAMNAME ": signal: %d\n",a); data/jpegoptim-1.4.6/jpegoptim.c:352:22: [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. if (!quiet_mode) fprintf(stderr,PROGRAMNAME ": file arguments missing\n" data/jpegoptim-1.4.6/jpegoptim.c:545:8: [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(LOG_FH,csv ? ",,,,,error\n" : " [ERROR]\n"); data/jpegoptim-1.4.6/jpegoptim.c:554:6: [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(LOG_FH,csv ? "%s," : "%s ",(stdin_mode?"stdin":argv[i])); fflush(LOG_FH); data/jpegoptim-1.4.6/jpegoptim.c:601:6: [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(LOG_FH,csv ? "%dx%d,%dbit,%c," : "%dx%d %dbit %c ",(int)dinfo.image_width, data/jpegoptim-1.4.6/jpegoptim.c:802:6: [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(LOG_FH,csv ? "%ld,%ld,%0.2f," : "%ld --> %ld bytes (%0.2f%%), ",insize,outsize,ratio); data/jpegoptim-1.4.6/jpegoptim.c:808:26: [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. if (!quiet_mode || csv) fprintf(LOG_FH,csv ? "optimized\n" : "optimized.\n"); data/jpegoptim-1.4.6/jpegoptim.c:890:30: [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. if (!quiet_mode || csv) fprintf(LOG_FH,csv ? "skipped\n" : "skipped.\n"); data/jpegoptim-1.4.6/misc.c:179:3: [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, PROGRAMNAME ": "); data/jpegoptim-1.4.6/misc.c:181:3: [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, format, args); data/jpegoptim-1.4.6/misc.c:195:3: [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, PROGRAMNAME ": "); data/jpegoptim-1.4.6/misc.c:197:3: [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, format, args); data/jpegoptim-1.4.6/win32_compat.h:22:9: [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/jpegoptim-1.4.6/win32_compat.h:22:18: [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/jpegoptim-1.4.6/getopt.c:181:7: [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 *getenv (); data/jpegoptim-1.4.6/getopt.c:299:21: [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. posixly_correct = getenv ("POSIXLY_CORRECT"); data/jpegoptim-1.4.6/getopt.c:676:1: [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. getopt (argc, argv, optstring) data/jpegoptim-1.4.6/getopt.c:706:11: [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. c = getopt (argc, argv, "abc:d:0123456789"); data/jpegoptim-1.4.6/getopt.h:104:12: [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. extern int getopt (int argc, char *const *argv, const char *shortopts); data/jpegoptim-1.4.6/getopt.h:106:12: [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. extern int getopt (); data/jpegoptim-1.4.6/getopt.h:108:12: [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. extern int getopt_long (int argc, char *const *argv, const char *shortopts, data/jpegoptim-1.4.6/getopt.h:120:12: [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. extern int getopt (); data/jpegoptim-1.4.6/getopt.h:121:12: [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. extern int getopt_long (); data/jpegoptim-1.4.6/getopt1.c:58:7: [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 *getenv (); data/jpegoptim-1.4.6/getopt1.c:66:1: [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. getopt_long (argc, argv, options, long_options, opt_index) data/jpegoptim-1.4.6/getopt1.c:122:11: [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. c = getopt_long (argc, argv, "abc:d:0123456789", data/jpegoptim-1.4.6/jpegoptim.c:360:12: [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. if ((c=getopt_long(argc,argv,"d:hm:nstqvfVpPoT:S:b",long_options,&opt_index)) data/jpegoptim-1.4.6/jpegoptim.c:379:11: [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(optarg,dest_path)==NULL) data/jpegoptim-1.4.6/win32_compat.h:25: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. #define realpath(N,R) _fullpath((R),(N),MAXPATHLEN) data/jpegoptim-1.4.6/jpegoptim.c:138: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 buffer[JMSG_LENGTH_MAX+1]; data/jpegoptim-1.4.6/jpegoptim.c:307: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 marker_str[256]; data/jpegoptim-1.4.6/jpegoptim.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 tmpfilename[MAXPATHLEN],tmpdir[MAXPATHLEN]; data/jpegoptim-1.4.6/jpegoptim.c:309: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 newname[MAXPATHLEN], dest_path[MAXPATHLEN]; data/jpegoptim-1.4.6/jpegoptim.c:533: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 ((infile=fopen(argv[i],"rb"))==NULL) { data/jpegoptim-1.4.6/jpegoptim.c:826: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 ((outfile=fopen(newname,"wb"))==NULL) data/jpegoptim-1.4.6/jpegoptim.c:842: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 ((outfile=fopen(tmpfilename,"wb"))==NULL) data/jpegoptim-1.4.6/misc.c:96: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. unsigned char buf[COPY_BUF_SIZE]; data/jpegoptim-1.4.6/misc.c:102:6: [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). in=fopen(srcfile,"rb"); data/jpegoptim-1.4.6/misc.c:107:7: [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). out=fopen(dstfile,"wb"); data/jpegoptim-1.4.6/misc.c:148:17: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. if (size > 0) memcpy(buf,pathname,size); data/jpegoptim-1.4.6/misc.c:169:17: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. if (size > 0) memcpy(buf,s,size); data/jpegoptim-1.4.6/win32_compat.h:26:34: [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 ftruncate(fildes,length) open(fildes, O_TRUNC|O_WRONLY) data/jpegoptim-1.4.6/getopt.c:205: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). extern int strlen (const char *); data/jpegoptim-1.4.6/getopt.c:497: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 (nameend - nextchar == (int) strlen (p->name)) data/jpegoptim-1.4.6/getopt.c:521: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). nextchar += strlen (nextchar); data/jpegoptim-1.4.6/getopt.c:551: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). nextchar += strlen (nextchar); data/jpegoptim-1.4.6/getopt.c:564: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). nextchar += strlen (nextchar); data/jpegoptim-1.4.6/getopt.c:568: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). nextchar += strlen (nextchar); data/jpegoptim-1.4.6/jpegoptim.c:50:31: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). #define STRNCPY(dest,src,n) { strncpy(dest,src,n); dest[n-1]=0; } data/jpegoptim-1.4.6/jpegoptim.c:332:3: [1] (access) umask: Ensure that umask is given most restrictive possible setting (e.g., 066 or 077) (CWE-732). umask(077); data/jpegoptim-1.4.6/jpegoptim.c:383:7: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. strncat(dest_path,DIR_SEPARATOR_S,sizeof(dest_path)-strlen(dest_path)-1); data/jpegoptim-1.4.6/jpegoptim.c:383:59: [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). strncat(dest_path,DIR_SEPARATOR_S,sizeof(dest_path)-strlen(dest_path)-1); data/jpegoptim-1.4.6/jpegoptim.c:449:45: [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 (tmpvar > 0 && tmpvar < 100 && optarg[strlen(optarg)-1] == '%' ) { data/jpegoptim-1.4.6/jpegoptim.c:504: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). if (strlen(argv[i]) >= MAXPATHLEN) { data/jpegoptim-1.4.6/jpegoptim.c:516:4: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. strncat(newname,tmpfilename,sizeof(newname)-strlen(newname)-1); data/jpegoptim-1.4.6/jpegoptim.c:516: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). strncat(newname,tmpfilename,sizeof(newname)-strlen(newname)-1); data/jpegoptim-1.4.6/jpegoptim.c:578:8: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. Risk is low because the source is a constant string. strncat(marker_str,"Exif ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:578:54: [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). strncat(marker_str,"Exif ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:581:8: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. Risk is low because the source is a constant string. strncat(marker_str,"IPTC ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:581:54: [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). strncat(marker_str,"IPTC ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:586:8: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. Risk is low because the source is a constant string. strncat(marker_str,"ICC ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:586:53: [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). strncat(marker_str,"ICC ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:591:8: [1] (buffer) strncat: Easily used incorrectly (e.g., incorrectly computing the correct maximum size to add) [MS-banned] (CWE-120). Consider strcat_s, strlcat, snprintf, or automatically resizing strings. Risk is low because the source is a constant string. strncat(marker_str,"XMP ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/jpegoptim.c:591:53: [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). strncat(marker_str,"XMP ",sizeof(marker_str)-strlen(marker_str)-1); data/jpegoptim-1.4.6/misc.c:167:8: [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=strlen(s); ANALYSIS SUMMARY: Hits = 71 Lines analyzed = 2445 in approximately 0.09 seconds (27168 lines/second) Physical Source Lines of Code (SLOC) = 1595 Hits@level = [0] 67 [1] 23 [2] 13 [3] 15 [4] 17 [5] 3 Hits@level+ = [0+] 138 [1+] 71 [2+] 48 [3+] 35 [4+] 20 [5+] 3 Hits/KSLOC@level+ = [0+] 86.5204 [1+] 44.5141 [2+] 30.094 [3+] 21.9436 [4+] 12.5392 [5+] 1.88088 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.