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/libusb-0.1.12/usb.c Examining data/libusb-0.1.12/usbi.h Examining data/libusb-0.1.12/linux.h Examining data/libusb-0.1.12/usbpp.cpp Examining data/libusb-0.1.12/tests/descriptor_test.cpp Examining data/libusb-0.1.12/tests/driver_name.cpp Examining data/libusb-0.1.12/tests/find_hubs.cpp Examining data/libusb-0.1.12/tests/find_mice.cpp Examining data/libusb-0.1.12/tests/get_resolution.cpp Examining data/libusb-0.1.12/tests/hub_strings.cpp Examining data/libusb-0.1.12/tests/id_test.cpp Examining data/libusb-0.1.12/tests/testlibusb.c Examining data/libusb-0.1.12/usbpp.h Examining data/libusb-0.1.12/darwin.c Examining data/libusb-0.1.12/bsd.c Examining data/libusb-0.1.12/freebsd-usb.h Examining data/libusb-0.1.12/descriptors.c Examining data/libusb-0.1.12/dummy.c Examining data/libusb-0.1.12/linux.c Examining data/libusb-0.1.12/error.c Examining data/libusb-0.1.12/error.h FINAL RESULTS: data/libusb-0.1.12/error.h:24:4: [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(usb_error_str, sizeof(usb_error_str) - 1, format, ## args); \ data/libusb-0.1.12/linux.c:658: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. if (getenv("USB_DEVFS_PATH")) { data/libusb-0.1.12/linux.c:659:23: [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. if (check_usb_vfs(getenv("USB_DEVFS_PATH"))) { data/libusb-0.1.12/linux.c:660:25: [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. strncpy(usb_path, getenv("USB_DEVFS_PATH"), sizeof(usb_path) - 1); data/libusb-0.1.12/usb.c:192: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. if (getenv("USB_DEBUG")) data/libusb-0.1.12/usb.c:193:24: [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. usb_set_debug(atoi(getenv("USB_DEBUG"))); data/libusb-0.1.12/bsd.c:150: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 ctlpath[PATH_MAX + 1]; data/libusb-0.1.12/bsd.c:162: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). dev->fd = open(ctlpath, O_RDWR); data/libusb-0.1.12/bsd.c:164: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). dev->fd = open(ctlpath, O_RDONLY); data/libusb-0.1.12/bsd.c:261: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 buf[20]; data/libusb-0.1.12/bsd.c:278: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). fd = open(buf, O_RDWR); data/libusb-0.1.12/bsd.c:280:12: [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(buf, mode); data/libusb-0.1.12/bsd.c:496: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 buf[20]; data/libusb-0.1.12/bsd.c:502: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). fd = open(buf, O_RDWR); data/libusb-0.1.12/bsd.c:538:9: [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). cfd = open(bus->dirname, O_RDONLY); data/libusb-0.1.12/bsd.c:546: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 device_desc[DEVICE_DESC_LENGTH]; data/libusb-0.1.12/bsd.c:547: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 buf[20]; data/libusb-0.1.12/bsd.c:566:11: [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). dfd = open(buf, O_RDONLY); data/libusb-0.1.12/darwin.c:153: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). int open; data/libusb-0.1.12/darwin.c:984: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 buf[20]; data/libusb-0.1.12/darwin.c:1009: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(buf, "%03i", i++); data/libusb-0.1.12/darwin.c:1062: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 device_desc[DEVICE_DESC_LENGTH]; data/libusb-0.1.12/darwin.c:1084:7: [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(dev->filename, "%03i-%04x-%04x-%02x-%02x", address, data/libusb-0.1.12/darwin.c:1089:7: [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(dev->dev, &location, 4); data/libusb-0.1.12/descriptors.c:57:7: [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(dp, sp, 2); sp += 2; dp += 2; data/libusb-0.1.12/descriptors.c:61:7: [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(dp, sp, 4); sp += 4; dp += 4; data/libusb-0.1.12/descriptors.c:155:3: [2] (buffer) memcpy: Does not check for buffer overflows when copying to destination (CWE-120). Make sure destination can always hold the source data. memcpy(endpoint->extra, begin, len); data/libusb-0.1.12/descriptors.c:231:7: [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(ifp->extra, begin, len); data/libusb-0.1.12/descriptors.c:372: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(config->extra, begin, len); data/libusb-0.1.12/descriptors.c:460: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 buffer[8], *bigbuffer; data/libusb-0.1.12/error.c:15:1: [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 usb_error_str[8192] = ""; data/libusb-0.1.12/error.h:10: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. extern char usb_error_str[8192]; data/libusb-0.1.12/freebsd-usb.h:613: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 udi_product[USB_MAX_STRING_LEN]; data/libusb-0.1.12/freebsd-usb.h:614: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 udi_vendor[USB_MAX_STRING_LEN]; data/libusb-0.1.12/freebsd-usb.h:615: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 udi_release[8]; data/libusb-0.1.12/freebsd-usb.h:629: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 udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN]; data/libusb-0.1.12/freebsd-usb.h:665: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 ue_devname[16]; data/libusb-0.1.12/linux.c:21: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 usb_path[PATH_MAX] = ""; data/libusb-0.1.12/linux.c:25: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 filename[PATH_MAX]; data/libusb-0.1.12/linux.c:34: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_RDWR); data/libusb-0.1.12/linux.c:36: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). fd = open(filename, O_RDONLY); data/libusb-0.1.12/linux.c:363:21: [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). bus->location = atoi(bus->dirname); data/libusb-0.1.12/linux.c:383: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 dirpath[PATH_MAX]; data/libusb-0.1.12/linux.c:397: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 device_desc[DEVICE_DESC_LENGTH]; data/libusb-0.1.12/linux.c:398: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 filename[PATH_MAX]; data/libusb-0.1.12/linux.c:423: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). fd = open(filename, O_RDWR); data/libusb-0.1.12/linux.c:425:12: [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/libusb-0.1.12/linux.c:485:16: [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 buffer[8], *bigbuffer; data/libusb-0.1.12/linux.c:511:7: [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(bigbuffer, buffer, 8); data/libusb-0.1.12/linux.h:42: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 driver[USB_MAXDRIVERNAME + 1]; data/libusb-0.1.12/linux.h:90:11: [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 port[127]; /* port to device num mapping */ data/libusb-0.1.12/tests/get_resolution.cpp:24:11: [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 resolution[1]; data/libusb-0.1.12/tests/testlibusb.c:65: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 description[259]; data/libusb-0.1.12/tests/testlibusb.c:66: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 string[256]; data/libusb-0.1.12/usb.c:193: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). usb_set_debug(atoi(getenv("USB_DEBUG"))); data/libusb-0.1.12/usb.c:232: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 tbuf[255]; /* Some devices choke on size > 255 */ data/libusb-0.1.12/usbpp.cpp:182: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 tmpBuff[256]; data/libusb-0.1.12/usbpp.cpp:389: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 tmpString[256]; data/libusb-0.1.12/bsd.c:356:9: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, bytes, size); data/libusb-0.1.12/bsd.c:440:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, bytes+retrieved, size-retrieved); data/libusb-0.1.12/bsd.c:518:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(bus->dirname, buf, sizeof(bus->dirname) - 1); data/libusb-0.1.12/bsd.c:589:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(dev->filename, buf, sizeof(dev->filename) - 1); data/libusb-0.1.12/darwin.c:1012:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(bus->dirname, buf, sizeof(bus->dirname) - 1); data/libusb-0.1.12/linux.c:348: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 (!strchr("0123456789", entry->d_name[strlen(entry->d_name) - 1])) { data/libusb-0.1.12/linux.c:361:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(bus->dirname, entry->d_name, sizeof(bus->dirname) - 1); data/libusb-0.1.12/linux.c:415:5: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(dev->filename, entry->d_name, sizeof(dev->filename) - 1); data/libusb-0.1.12/linux.c:444:11: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, (void *)device_desc, DEVICE_DESC_LENGTH); data/libusb-0.1.12/linux.c:489:13: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, (void *)buffer, 8); data/libusb-0.1.12/linux.c:513:13: [1] (buffer) read: Check buffer boundaries if used in a loop including recursive loops (CWE-120, CWE-20). ret = read(fd, (void *)(bigbuffer + 8), config.wTotalLength - 8); data/libusb-0.1.12/linux.c:660:7: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(usb_path, getenv("USB_DEVFS_PATH"), sizeof(usb_path) - 1); data/libusb-0.1.12/linux.c:668:7: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). Risk is low because the source is a constant string. strncpy(usb_path, "/dev/bus/usb", sizeof(usb_path) - 1); data/libusb-0.1.12/linux.c:671:7: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). Risk is low because the source is a constant string. strncpy(usb_path, "/proc/bus/usb", sizeof(usb_path) - 1); data/libusb-0.1.12/linux.c:731:3: [1] (buffer) strncpy: Easily used incorrectly; doesn't always \0-terminate or check for invalid pointers [MS-banned] (CWE-120). strncpy(name, getdrv.driver, namelen - 1); data/libusb-0.1.12/tests/testlibusb.c:85: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). snprintf(description + strlen(description), sizeof(description) - data/libusb-0.1.12/tests/testlibusb.c:86:18: [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). strlen(description), "%s", string); data/libusb-0.1.12/tests/testlibusb.c:88: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). snprintf(description + strlen(description), sizeof(description) - data/libusb-0.1.12/tests/testlibusb.c:89:18: [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). strlen(description), "%04X", dev->descriptor.idProduct); data/libusb-0.1.12/tests/testlibusb.c:91: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). snprintf(description + strlen(description), sizeof(description) - data/libusb-0.1.12/tests/testlibusb.c:92: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). strlen(description), "%04X", dev->descriptor.idProduct); ANALYSIS SUMMARY: Hits = 79 Lines analyzed = 6545 in approximately 0.19 seconds (34025 lines/second) Physical Source Lines of Code (SLOC) = 4241 Hits@level = [0] 151 [1] 21 [2] 52 [3] 5 [4] 1 [5] 0 Hits@level+ = [0+] 230 [1+] 79 [2+] 58 [3+] 6 [4+] 1 [5+] 0 Hits/KSLOC@level+ = [0+] 54.2325 [1+] 18.6277 [2+] 13.676 [3+] 1.41476 [4+] 0.235793 [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.