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/stlink-1.6.1+ds/doc/app-example/main.c
Examining data/stlink-1.6.1+ds/include/stlink.h
Examining data/stlink-1.6.1+ds/include/stlink/backend.h
Examining data/stlink-1.6.1+ds/include/stlink/chipid.h
Examining data/stlink-1.6.1+ds/include/stlink/commands.h
Examining data/stlink-1.6.1+ds/include/stlink/flash_loader.h
Examining data/stlink-1.6.1+ds/include/stlink/reg.h
Examining data/stlink-1.6.1+ds/include/stlink/tools/flash.h
Examining data/stlink-1.6.1+ds/include/stm32.h
Examining data/stlink-1.6.1+ds/src/chipid.c
Examining data/stlink-1.6.1+ds/src/common.c
Examining data/stlink-1.6.1+ds/src/flash_loader.c
Examining data/stlink-1.6.1+ds/src/getopt/getopt.c
Examining data/stlink-1.6.1+ds/src/getopt/getopt.h
Examining data/stlink-1.6.1+ds/src/libusb_settings.h
Examining data/stlink-1.6.1+ds/src/logging.c
Examining data/stlink-1.6.1+ds/src/logging.h
Examining data/stlink-1.6.1+ds/src/md5.c
Examining data/stlink-1.6.1+ds/src/md5.h
Examining data/stlink-1.6.1+ds/src/mingw/mingw.c
Examining data/stlink-1.6.1+ds/src/mingw/mingw.h
Examining data/stlink-1.6.1+ds/src/mmap.c
Examining data/stlink-1.6.1+ds/src/mmap.h
Examining data/stlink-1.6.1+ds/src/sg.c
Examining data/stlink-1.6.1+ds/src/sg.h
Examining data/stlink-1.6.1+ds/src/st-util/gdb-remote.c
Examining data/stlink-1.6.1+ds/src/st-util/gdb-remote.h
Examining data/stlink-1.6.1+ds/src/st-util/gdb-server.c
Examining data/stlink-1.6.1+ds/src/st-util/gdb-server.h
Examining data/stlink-1.6.1+ds/src/st-util/semihosting.c
Examining data/stlink-1.6.1+ds/src/st-util/semihosting.h
Examining data/stlink-1.6.1+ds/src/stlink-gui/gui.c
Examining data/stlink-1.6.1+ds/src/stlink-gui/gui.h
Examining data/stlink-1.6.1+ds/src/tools/flash.c
Examining data/stlink-1.6.1+ds/src/tools/flash_opts.c
Examining data/stlink-1.6.1+ds/src/tools/info.c
Examining data/stlink-1.6.1+ds/src/usb.c
Examining data/stlink-1.6.1+ds/src/usb.h
Examining data/stlink-1.6.1+ds/src/win32/unistd.h
Examining data/stlink-1.6.1+ds/tests/flash.c
Examining data/stlink-1.6.1+ds/tests/sg.c
Examining data/stlink-1.6.1+ds/tests/usb.c

FINAL RESULTS:

data/stlink-1.6.1+ds/src/logging.c:52: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, format, args);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:144:17:  [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(help_str, argv[0]);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:516:9:  [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(map, memory_map_template_F4);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:518:9:  [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(map, memory_map_template_F4_DE);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:520: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.
        snprintf(map, sz, memory_map_template_F7,
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:523:9:  [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(map, memory_map_template_F4_HD);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:525: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.
        snprintf(map, sz, memory_map_template_F2,
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:533: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.
        snprintf(map, sz, memory_map_template_L4,
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:536: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.
        snprintf(map, sz, memory_map_template_L496,
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:539: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.
        snprintf(map, sz, memory_map_template,
data/stlink-1.6.1+ds/src/tools/info.c:34:9:  [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(fmt, sl->serial[n]);
data/stlink-1.6.1+ds/src/win32/unistd.h:32: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.
#define access _access
data/stlink-1.6.1+ds/tests/flash.c:45: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(cmd_line, test->cmd_line);
data/stlink-1.6.1+ds/src/getopt/getopt.c:28:5:  [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.
int getopt(int argc, char* const argv[], const char* optstring) {
data/stlink-1.6.1+ds/src/getopt/getopt.c:134:5:  [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.
int getopt_long(int argc, char* const argv[], const char* optstring,
data/stlink-1.6.1+ds/src/getopt/getopt.c:150: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.
    return getopt(argc, argv, optstring);
data/stlink-1.6.1+ds/src/getopt/getopt.h:29:5:  [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.
int getopt(int argc, char* const argv[], const char* optstring);
data/stlink-1.6.1+ds/src/getopt/getopt.h:31:5:  [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.
int getopt_long(int argc, char* const argv[],
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:139: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, "hv::p:mn", long_options, &option_index)) != -1) {
data/stlink-1.6.1+ds/src/usb.c:982:20:  [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 *device = getenv("STLINK_DEVICE");
data/stlink-1.6.1+ds/src/win32/unistd.h:23:9:  [3] (random) srandom:
  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.
#define srandom srand
data/stlink-1.6.1+ds/src/win32/unistd.h:23:17:  [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.
#define srandom srand
data/stlink-1.6.1+ds/src/win32/unistd.h:24:9:  [3] (random) random:
  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.
#define random rand
data/stlink-1.6.1+ds/include/stlink.h:194:14:  [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 c_buf[C_BUF_LEN];
data/stlink-1.6.1+ds/include/stlink.h:196:14:  [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 q_buf[Q_BUF_LEN];
data/stlink-1.6.1+ds/include/stlink.h:206: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 serial[STLINK_SERIAL_MAX_SIZE];
data/stlink-1.6.1+ds/src/common.c:1543: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).
    const int fd = open(path, O_RDONLY | O_BINARY);
data/stlink-1.6.1+ds/src/common.c:1683: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(sl->q_buf, data + off, size);
data/stlink-1.6.1+ds/src/common.c:1693: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(sl->q_buf, data + len, length - len);
data/stlink-1.6.1+ds/src/common.c:1749: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(sl->q_buf, mf.base + off, size);
data/stlink-1.6.1+ds/src/common.c:1759: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(sl->q_buf, mf.base + len, mf.len - len);
data/stlink-1.6.1+ds/src/common.c:1919:14:  [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).
    int fd = open(path, O_RDWR | O_TRUNC | O_CREAT | O_BINARY, 00700);
data/stlink-1.6.1+ds/src/common.c:1951: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(sl->q_buf, buf, chunk);
data/stlink-1.6.1+ds/src/common.c:1955: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(sl->q_buf, buf+chunk, rem);
data/stlink-1.6.1+ds/src/common.c:2770: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).
        FILE* file = fopen(path, "r");
data/stlink-1.6.1+ds/src/common.c:2779: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 line[1 + 5*2 + 255*2 + 2];
data/stlink-1.6.1+ds/src/flash_loader.c:304:5:  [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(sl->q_buf, loader_code, loader_size);
data/stlink-1.6.1+ds/src/md5.c:241:13:  [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( &Context->buffer[used], Buffer, BufferSize );
data/stlink-1.6.1+ds/src/md5.c:245: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( &Context->buffer[used], Buffer, free );
data/stlink-1.6.1+ds/src/md5.c:257:5:  [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( Context->buffer, Buffer, BufferSize );
data/stlink-1.6.1+ds/src/sg.c:113:14:  [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 csw[13];
data/stlink-1.6.1+ds/src/sg.c:149: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 dbugblah[100];
data/stlink-1.6.1+ds/src/sg.c:151:14:  [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.
    dbugp += sprintf(dbugp, "Sending CDB [");
data/stlink-1.6.1+ds/src/sg.c:153:18:  [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.
        dbugp += sprintf(dbugp, " %#02x", (unsigned int) cdb[i]);
data/stlink-1.6.1+ds/src/sg.c:155:5:  [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(dbugp, "]\n");
data/stlink-1.6.1+ds/src/sg.c:204:5:  [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(&(c_buf[i]), cdb, cdb_length);
data/stlink-1.6.1+ds/src/sg.c:245:14:  [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 sense[REQUEST_SENSE_LENGTH];
data/stlink-1.6.1+ds/src/sg.h:53:14:  [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 cdb_cmd_blk[CDB_SL];
data/stlink-1.6.1+ds/src/sg.h:61:14:  [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 sense_buf[SENSE_BUF_LEN];
data/stlink-1.6.1+ds/src/st-util/gdb-remote.c:66: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 recv_cksum[3] = {0};
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:45: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 serialnumber[28] = {0};
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:149:41:  [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).
                    st->logging_level = atoi(optarg);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:181:21:  [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[3] = {0};
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:182:21:  [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(buffer, optarg + j, 2);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:814:13:  [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(fb->data + start, data, end - start);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1525:21:  [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(&reply[i * 8], "%08x", (uint32_t)htonl(regp.r[i]));
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1574:21:  [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(reply, "%08x", myreg);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1625:21:  [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[9] = {0};
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1680: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.
                        char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1695: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.
                        char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1708: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.
                        char hextmp[3] = { hexdata[i*2], hexdata[i*2+1], 0 };
data/stlink-1.6.1+ds/src/st-util/semihosting.c:45:5:  [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, &sl->q_buf[offset], sizeof(*data));
data/stlink-1.6.1+ds/src/st-util/semihosting.c:63:5:  [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, &sl->q_buf[offset], sizeof(*data));
data/stlink-1.6.1+ds/src/st-util/semihosting.c:87:5:  [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, &sl->q_buf[offset], len);
data/stlink-1.6.1+ds/src/st-util/semihosting.c:118:5:  [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(&sl->q_buf[offset], data, len);
data/stlink-1.6.1+ds/src/st-util/semihosting.c:227:26:  [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 = (uint32_t)open(name, open_mode_flags[mode], 0644);
data/stlink-1.6.1+ds/src/stlink-gui/gui.c:225: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 (gui->flash_mem.memory + off, gui->sl->q_buf, n_read);
data/stlink-1.6.1+ds/src/stlink-gui/gui.c:277:13:  [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 (gui->file_mem.memory, mem, size);
data/stlink-1.6.1+ds/src/stlink-gui/gui.c:316:13:  [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 (gui->file_mem.memory + off, buffer, n_read);
data/stlink-1.6.1+ds/src/stlink-gui/gui.c:645: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).
    FILE * f=fopen(filename, "w");
data/stlink-1.6.1+ds/src/tools/flash_opts.c:124:17:  [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[3] = {0};
data/stlink-1.6.1+ds/src/tools/flash_opts.c:125: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.
                memcpy(buffer, serial + j, 2);
data/stlink-1.6.1+ds/src/usb.c:99:18:  [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 sg_buf[13];
data/stlink-1.6.1+ds/src/usb.c:940:66:  [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.
stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq) {
data/stlink-1.6.1+ds/src/usb.c:989:18:  [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).
        devBus = atoi(device);
data/stlink-1.6.1+ds/src/usb.c:991:19:  [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).
        devAddr = atoi(c);
data/stlink-1.6.1+ds/src/usb.c:1229: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 serial[STLINK_SERIAL_MAX_SIZE] = {0,};
data/stlink-1.6.1+ds/src/usb.h:71:70:  [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.
    stlink_t *stlink_open_usb(enum ugly_loglevel verbose, int reset, char serial[STLINK_SERIAL_MAX_SIZE], int freq);
data/stlink-1.6.1+ds/tests/flash.c:42: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 cmd_line[strlen(test->cmd_line) + 1];
data/stlink-1.6.1+ds/src/common.c:908:9:  [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(10000);
data/stlink-1.6.1+ds/src/common.c:1485:9:  [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(3000000);
data/stlink-1.6.1+ds/src/common.c:2788:24:  [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 l = strlen(line);
data/stlink-1.6.1+ds/src/flash_loader.c:374:9:  [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(1000);
data/stlink-1.6.1+ds/src/getopt/getopt.c:149: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).
  if (strlen(argv[optind]) < 3 || strncmp(argv[optind], "--", 2) != 0)
data/stlink-1.6.1+ds/src/mingw/mingw.c:276:5:  [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.
int usleep(unsigned int waitTime)
data/stlink-1.6.1+ds/src/mingw/mingw.h:52:9:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
#define read(x, y, z)     win32_read_socket(x, y, z)
data/stlink-1.6.1+ds/src/mmap.c:24:13:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
    count = read(fd, buf, len);
data/stlink-1.6.1+ds/src/st-util/gdb-remote.c:24: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).
    unsigned int data_length = (unsigned int) strlen(data);
data/stlink-1.6.1+ds/src/st-util/gdb-remote.c:49:13:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
        if (read(fd, &ack, 1) != 1) {
data/stlink-1.6.1+ds/src/st-util/gdb-remote.c:86:13:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
        if (read(fd, &c, 1) != 1) {
data/stlink-1.6.1+ds/src/st-util/gdb-remote.c:166:13:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
        if (read(fd, &c, 1) != 1)
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:177:30:  [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 j = (int)strlen(optarg);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:247:7:  [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 (1 * 1000); // don't go bezurk if serve returns with error
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1128:42:  [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).
                    separator = packet + strlen(packet);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1135:17:  [1] (buffer) strncpy:
  Easily used incorrectly; doesn't always \0-terminate or check for invalid
  pointers [MS-banned] (CWE-120).
                strncpy(queryName, &packet[1], queryNameLength);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1174:63:  [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).
                        unsigned data_length = (unsigned int) strlen(data);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1183:29:  [1] (buffer) strncpy:
  Easily used incorrectly; doesn't always \0-terminate or check for invalid
  pointers [MS-banned] (CWE-120).
                            strncpy(&reply[1], data, length);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1191:46:  [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).
                        separator = packet + strlen(packet);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1196: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).
                    size_t hex_len = strlen(params);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1488:21:  [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(100000);
data/stlink-1.6.1+ds/src/st-util/gdb-server.c:1626:21:  [1] (buffer) strncpy:
  Easily used incorrectly; doesn't always \0-terminate or check for invalid
  pointers [MS-banned] (CWE-120).
                    strncpy(str, &packet[1 + i * 8], 8);
data/stlink-1.6.1+ds/src/st-util/semihosting.c:353:23:  [1] (buffer) read:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
        read_result = read(fd, buffer, buffer_len);
data/stlink-1.6.1+ds/src/st-util/semihosting.c:475:21:  [1] (buffer) getchar:
  Check buffer boundaries if used in a loop including recursive loops
  (CWE-120, CWE-20).
        uint8_t c = getchar();
data/stlink-1.6.1+ds/src/tools/flash_opts.c:8: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).
    size_t n = strlen(prefix);
data/stlink-1.6.1+ds/src/tools/flash_opts.c:9: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) < n) return false;
data/stlink-1.6.1+ds/src/tools/flash_opts.c:117:34:  [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).
                serial = av[0] + strlen("--serial=");
data/stlink-1.6.1+ds/src/tools/flash_opts.c:120: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).
            int j = (int)strlen(serial);
data/stlink-1.6.1+ds/src/tools/flash_opts.c:138: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).
                area = av[0] + strlen("--area=");
data/stlink-1.6.1+ds/src/tools/flash_opts.c:161: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).
                freq = av[0] + strlen("--freq=");
data/stlink-1.6.1+ds/src/tools/flash_opts.c:211:34:  [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).
                format = av[0] + strlen("--format=");
data/stlink-1.6.1+ds/src/tools/flash_opts.c:221:39:  [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 char *arg = av[0] + strlen("--flash=");
data/stlink-1.6.1+ds/src/usb.c:1153:10:  [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(10000);
data/stlink-1.6.1+ds/src/usb.c:1162:9:  [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(10000);
data/stlink-1.6.1+ds/src/win32/unistd.h:62:5:  [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.
int usleep(unsigned int waitTime);
data/stlink-1.6.1+ds/tests/flash.c:40: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).
        char *cmd_line = alloca(strlen(test->cmd_line) + 1);
data/stlink-1.6.1+ds/tests/flash.c:42: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).
        char cmd_line[strlen(test->cmd_line) + 1];
data/stlink-1.6.1+ds/tests/sg.c:94:9:  [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(100 * 1000);
data/stlink-1.6.1+ds/tests/sg.c:98:9:  [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(100 * 1000);

ANALYSIS SUMMARY:

Hits = 118
Lines analyzed = 13743 in approximately 0.35 seconds (38794 lines/second)
Physical Source Lines of Code (SLOC) = 10445
Hits@level = [0] 186 [1]  39 [2]  56 [3]  10 [4]  13 [5]   0
Hits@level+ = [0+] 304 [1+] 118 [2+]  79 [3+]  23 [4+]  13 [5+]   0
Hits/KSLOC@level+ = [0+] 29.1048 [1+] 11.2973 [2+] 7.56343 [3+] 2.20201 [4+] 1.24461 [5+]   0
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.