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/libmodbus-3.1.6/src/modbus-private.h Examining data/libmodbus-3.1.6/src/modbus-rtu-private.h Examining data/libmodbus-3.1.6/src/modbus-rtu.c Examining data/libmodbus-3.1.6/src/modbus-rtu.h Examining data/libmodbus-3.1.6/src/modbus-tcp-private.h Examining data/libmodbus-3.1.6/src/modbus-tcp.c Examining data/libmodbus-3.1.6/src/modbus-tcp.h Examining data/libmodbus-3.1.6/src/modbus.c Examining data/libmodbus-3.1.6/src/modbus.h Examining data/libmodbus-3.1.6/src/modbus-data.c Examining data/libmodbus-3.1.6/tests/bandwidth-client.c Examining data/libmodbus-3.1.6/tests/bandwidth-server-many-up.c Examining data/libmodbus-3.1.6/tests/bandwidth-server-one.c Examining data/libmodbus-3.1.6/tests/random-test-client.c Examining data/libmodbus-3.1.6/tests/random-test-server.c Examining data/libmodbus-3.1.6/tests/unit-test-server.c Examining data/libmodbus-3.1.6/tests/version.c Examining data/libmodbus-3.1.6/tests/unit-test-client.c FINAL RESULTS: data/libmodbus-3.1.6/src/modbus-rtu.c:1264: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(ctx_rtu->device, device); data/libmodbus-3.1.6/src/modbus.c:681:9: [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, template, ap); data/libmodbus-3.1.6/src/modbus-data.c:137: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(&f, &i, 4); data/libmodbus-3.1.6/src/modbus-data.c:158: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(&f, &i, 4); data/libmodbus-3.1.6/src/modbus-data.c:179: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(&f, &i, 4); data/libmodbus-3.1.6/src/modbus-data.c:200: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(&f, &i, 4); data/libmodbus-3.1.6/src/modbus-data.c:212: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(&f, &i, sizeof(float)); data/libmodbus-3.1.6/src/modbus-data.c:225: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(&i, &f, sizeof(uint32_t)); data/libmodbus-3.1.6/src/modbus-data.c:244: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(&i, &f, sizeof(uint32_t)); data/libmodbus-3.1.6/src/modbus-data.c:264: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(&i, &f, sizeof(uint32_t)); data/libmodbus-3.1.6/src/modbus-data.c:283: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(&i, &f, sizeof(uint32_t)); data/libmodbus-3.1.6/src/modbus-data.c:300: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(&i, &f, sizeof(uint32_t)); data/libmodbus-3.1.6/src/modbus-rtu.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(p_msg, ws->buf, n); data/libmodbus-3.1.6/src/modbus-rtu.c:591: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). ctx->s = open(ctx_rtu->device, flags); data/libmodbus-3.1.6/src/modbus-tcp-private.h:27: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 ip[16]; data/libmodbus-3.1.6/src/modbus-tcp-private.h:39: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 node[_MODBUS_TCP_PI_NODE_LENGTH]; data/libmodbus-3.1.6/src/modbus-tcp-private.h:41: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 service[_MODBUS_TCP_PI_SERVICE_LENGTH]; data/libmodbus-3.1.6/src/modbus-tcp.c:449: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 devnull[MODBUS_TCP_MAX_ADU_LENGTH]; data/libmodbus-3.1.6/src/modbus.c:238: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(req + req_length, raw_req + 2, raw_req_length - 2); data/libmodbus-3.1.6/src/modbus.c:810: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(rsp, req, req_length); data/libmodbus-3.1.6/src/modbus.c:835: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(rsp, req, req_length); data/libmodbus-3.1.6/src/modbus.c:867: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(rsp + rsp_length, req + rsp_length, 4); data/libmodbus-3.1.6/src/modbus.c:898: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(rsp + rsp_length, req + rsp_length, 4); data/libmodbus-3.1.6/src/modbus.c:915: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(rsp + rsp_length, "LMB" LIBMODBUS_VERSION_STRING, str_len); data/libmodbus-3.1.6/src/modbus.c:942: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(rsp, req, req_length); data/libmodbus-3.1.6/src/modbus-rtu.c:287: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(ctx_rtu->rts_delay); data/libmodbus-3.1.6/src/modbus-rtu.c:291: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(ctx_rtu->onebyte_time * req_length + ctx_rtu->rts_delay); data/libmodbus-3.1.6/src/modbus-rtu.c:332:12: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). return read(ctx->s, rsp, rsp_length); data/libmodbus-3.1.6/src/modbus-rtu.c:1258: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). ctx_rtu->device = (char *)malloc((strlen(device) + 1) * sizeof(char)); data/libmodbus-3.1.6/src/modbus.c:914: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). str_len = 3 + strlen(LIBMODBUS_VERSION_STRING); data/libmodbus-3.1.6/tests/unit-test-client.c:587: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. usleep(old_response_to_sec * 1000000 + old_response_to_usec); data/libmodbus-3.1.6/tests/unit-test-client.c:599: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. usleep(400000); data/libmodbus-3.1.6/tests/unit-test-client.c:632: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(11 * 5000); data/libmodbus-3.1.6/tests/unit-test-server.c:156:17: [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/libmodbus-3.1.6/tests/unit-test-server.c:173: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(5000); ANALYSIS SUMMARY: Hits = 35 Lines analyzed = 6953 in approximately 0.20 seconds (34992 lines/second) Physical Source Lines of Code (SLOC) = 5157 Hits@level = [0] 266 [1] 10 [2] 23 [3] 0 [4] 2 [5] 0 Hits@level+ = [0+] 301 [1+] 35 [2+] 25 [3+] 2 [4+] 2 [5+] 0 Hits/KSLOC@level+ = [0+] 58.3673 [1+] 6.78689 [2+] 4.84778 [3+] 0.387822 [4+] 0.387822 [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.