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/stm32flash-0.5+git20200914+2b0f078/compiler.h
Examining data/stm32flash-0.5+git20200914+2b0f078/dev_table.c
Examining data/stm32flash-0.5+git20200914+2b0f078/i2c.c
Examining data/stm32flash-0.5+git20200914+2b0f078/init.c
Examining data/stm32flash-0.5+git20200914+2b0f078/init.h
Examining data/stm32flash-0.5+git20200914+2b0f078/main.c
Examining data/stm32flash-0.5+git20200914+2b0f078/parsers/binary.c
Examining data/stm32flash-0.5+git20200914+2b0f078/parsers/binary.h
Examining data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c
Examining data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.h
Examining data/stm32flash-0.5+git20200914+2b0f078/parsers/parser.h
Examining data/stm32flash-0.5+git20200914+2b0f078/port.c
Examining data/stm32flash-0.5+git20200914+2b0f078/port.h
Examining data/stm32flash-0.5+git20200914+2b0f078/serial.h
Examining data/stm32flash-0.5+git20200914+2b0f078/serial_common.c
Examining data/stm32flash-0.5+git20200914+2b0f078/serial_platform.c
Examining data/stm32flash-0.5+git20200914+2b0f078/serial_posix.c
Examining data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c
Examining data/stm32flash-0.5+git20200914+2b0f078/stm32.c
Examining data/stm32flash-0.5+git20200914+2b0f078/stm32.h
Examining data/stm32flash-0.5+git20200914+2b0f078/utils.c
Examining data/stm32flash-0.5+git20200914+2b0f078/utils.h

FINAL RESULTS:

data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:52:3:  [4] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf.
		sprintf(devName, "\\\\.\\%s", device);
data/stm32flash-0.5+git20200914+2b0f078/main.c:670:14:  [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, "a:b:m:r:w:e:vn:g:jkfcChuos:S:F:i:R")) != -1) {
data/stm32flash-0.5+git20200914+2b0f078/i2c.c:92:7:  [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(ops->device, O_RDWR);
data/stm32flash-0.5+git20200914+2b0f078/i2c.c:183: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.
	static char str[11];
data/stm32flash-0.5+git20200914+2b0f078/init.c:53:7:  [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_WRONLY);
data/stm32flash-0.5+git20200914+2b0f078/init.c:73:7:  [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);
data/stm32flash-0.5+git20200914+2b0f078/init.c:97: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 num[16]; /* sized to carry MAX_INT */
data/stm32flash-0.5+git20200914+2b0f078/init.c:98: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 file[48]; /* sized to carry longest filename */
data/stm32flash-0.5+git20200914+2b0f078/init.c:106:2:  [2] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf. Risk is low because the source has a constant maximum length.
	sprintf(file, "/sys/class/gpio/gpio%d/value", n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:110:3:  [2] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf. Risk is low because the source has a constant maximum length.
		sprintf(num, "%d", n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:122:2:  [2] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf. Risk is low because the source has a constant maximum length.
	sprintf(file, "/sys/class/gpio/gpio%d/direction", n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:147: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 num[16]; /* sized to carry MAX_INT */
data/stm32flash-0.5+git20200914+2b0f078/init.c:148: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 file[48]; /* sized to carry longest filename */
data/stm32flash-0.5+git20200914+2b0f078/init.c:150:2:  [2] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf. Risk is low because the source has a constant maximum length.
	sprintf(num, "%d", n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:152:3:  [2] (buffer) sprintf:
  Does not check for buffer overflows (CWE-120). Use sprintf_s, snprintf, or
  vsnprintf. Risk is low because the source has a constant maximum length.
		sprintf(file, "/sys/class/gpio/gpio%d/direction", n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:196:11:  [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).
			gpio = atoi(s);
data/stm32flash-0.5+git20200914+2b0f078/main.c:271:39:  [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 (force_binary || (perr = parser->open(p_st, filename, 0)) != PARSER_ERR_OK) {
data/stm32flash-0.5+git20200914+2b0f078/main.c:285:20:  [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).
				perr = parser->open(p_st, filename, 0);
data/stm32flash-0.5+git20200914+2b0f078/main.c:411:18:  [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).
		perr = parser->open(p_st, filename, 1);
data/stm32flash-0.5+git20200914+2b0f078/parsers/binary.c:45:13:  [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).
			st->fd = open(
data/stm32flash-0.5+git20200914+2b0f078/parsers/binary.c:65:13:  [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).
			st->fd = open(filename,
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:55:8:  [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);
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:66:4:  [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[9];
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:211: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(data, &st->data[st->offset], get);
data/stm32flash-0.5+git20200914+2b0f078/parsers/parser.h:36:17:  [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).
	parser_err_t (*open )(void *storage, const char *filename, const char write);	/* open the file for read|write */
data/stm32flash-0.5+git20200914+2b0f078/port.c:43:18:  [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).
		ret = (*port)->open(*port, ops);
data/stm32flash-0.5+git20200914+2b0f078/port.h:63:15:  [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).
	port_err_t (*open)(struct port_interface *port, struct port_options *ops);
data/stm32flash-0.5+git20200914+2b0f078/serial_posix.c:45: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 setup_str[11];
data/stm32flash-0.5+git20200914+2b0f078/serial_posix.c:52: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).
	h->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:38: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 setup_str[11];
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:973: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(mem, &stack_le, sizeof(uint32_t));
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:974: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(mem + 4, &code_address_le, sizeof(uint32_t));
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:975: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(mem + 8, code, code_size);
data/stm32flash-0.5+git20200914+2b0f078/i2c.c:76:40:  [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(ops->device, "/dev/i2c-", strlen("/dev/i2c-")))
data/stm32flash-0.5+git20200914+2b0f078/i2c.c:152:8:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	ret = read(h->fd, buf, nbyte);
data/stm32flash-0.5+git20200914+2b0f078/init.c:58: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).
	ret = write(fd, value, strlen(value));
data/stm32flash-0.5+git20200914+2b0f078/init.c:80:9:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		ret = read(fd, buf + n, len - n);
data/stm32flash-0.5+git20200914+2b0f078/init.c:261:4:  [1] (obsolete) usleep:
  This C routine is considered obsolete (as opposed to the shell command by
  the same name). The interaction of this function with SIGALRM and other
  timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is
  unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead.
			usleep(sleep_time);
data/stm32flash-0.5+git20200914+2b0f078/init.c:285: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).
		return gpio_sequence(port, seq, strlen(seq));
data/stm32flash-0.5+git20200914+2b0f078/init.c:301: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).
	return gpio_sequence(port, s + 1, strlen(s + 1));
data/stm32flash-0.5+git20200914+2b0f078/main.c:543:16:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
			if (parser->read(p_st, buffer, &len) != PARSER_ERR_OK)
data/stm32flash-0.5+git20200914+2b0f078/main.c:688: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(optarg) != 3
data/stm32flash-0.5+git20200914+2b0f078/parsers/binary.c:101:7:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		r = read(st->fd, d, left);
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:61:9:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		while(read(fd, &mark, 1) != 0) {
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:72:8:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
			if (read(fd, &buffer, 8) != 8) return PARSER_ERR_INVALID_FILE;
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:115:9:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
				if (read(fd, &buffer, 2) != 2 || sscanf(buffer, "%2x", &c) != 1) {
data/stm32flash-0.5+git20200914+2b0f078/parsers/hex.c:141:5:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
				read(fd, &buffer, 2 ) != 2 ||
data/stm32flash-0.5+git20200914+2b0f078/parsers/parser.h:39:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	parser_err_t (*read )(void *storage, void *data, unsigned int *len);		/* read a block of data */
data/stm32flash-0.5+git20200914+2b0f078/port.h:66:15:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	port_err_t (*read)(struct port_interface *port, void *buf, size_t nbyte);
data/stm32flash-0.5+git20200914+2b0f078/serial_posix.c:282:7:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		r = read(h->fd, pos, nbyte);
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:50:6:  [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(device) > 4 && device[0] != '\\') {
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:51: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).
		devName = calloc(1, strlen(device) + 5);
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:200:47:  [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).
	    && !(!strncmp(ops->device, "\\\\.\\COM", strlen("\\\\.\\COM"))
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:201:27:  [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).
		 && isdigit(ops->device[strlen("\\\\.\\COM")])))
data/stm32flash-0.5+git20200914+2b0f078/serial_w32.c:315:3:  [1] (obsolete) usleep:
  This C routine is considered obsolete (as opposed to the shell command by
  the same name). The interaction of this function with SIGALRM and other
  timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is
  unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead.
		usleep(500000);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:200:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		p_err = port->read(port, &byte, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:276:4:  [1] (obsolete) usleep:
  This C routine is considered obsolete (as opposed to the shell command by
  the same name). The interaction of this function with SIGALRM and other
  timer functions such as sleep(), alarm(), setitimer(), and nanosleep() is
  unspecified (CWE-676). Use nanosleep(2) or setitimer(2) instead.
			usleep(500000);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:280:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		p_err = port->read(port, &ack, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:314:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		p_err = port->read(port, data, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:318:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		p_err = port->read(port, data + 1, len + 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:324:16:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	p_err = port->read(port, data, len + 2);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:333:17:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
		p_err = port->read(port, data, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:345:16:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	p_err = port->read(port, data, len + 2);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:374:16:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	p_err = port->read(port, &byte, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:397:16:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	p_err = port->read(port, &byte, 1);
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:432:12:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	if (port->read(port, buf, len) != PORT_ERR_OK)
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:597:12:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	if (port->read(port, data, len) != PORT_ERR_OK)
data/stm32flash-0.5+git20200914+2b0f078/stm32.c:1080:12:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
	if (port->read(port, buf, 5) != PORT_ERR_OK)

ANALYSIS SUMMARY:

Hits = 68
Lines analyzed = 4658 in approximately 0.15 seconds (31613 lines/second)
Physical Source Lines of Code (SLOC) = 3424
Hits@level = [0] 165 [1]  35 [2]  31 [3]   1 [4]   1 [5]   0
Hits@level+ = [0+] 233 [1+]  68 [2+]  33 [3+]   2 [4+]   1 [5+]   0
Hits/KSLOC@level+ = [0+] 68.0491 [1+] 19.8598 [2+] 9.63785 [3+] 0.584112 [4+] 0.292056 [5+]   0
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.