if (initial_pos < 0)
return -1;
- fseek(image, 0L, SEEK_END);
+ if (fseek(image, 0L, SEEK_END) != 0)
+ return -1;
file_size = ftell(image);
- fseek(image, initial_pos, SEEK_SET);
+ if (fseek(image, initial_pos, SEEK_SET) != 0)
+ return -1;
for (;;) {
/* Ignore the trailing reset IIC data (5 bytes) */
if (ftell(image) >= (file_size - 5))
if (dLength == 0)
break; // done
- dImageBuf = calloc(dLength, sizeof(uint32_t));
+ // coverity[tainted_data]
+ dImageBuf = (uint32_t*)calloc(dLength, sizeof(uint32_t));
if (dImageBuf == NULL) {
logerror("could not allocate buffer for image chunk\n");
ret = -4;
}
}
- if (verbose)
+ if (verbose && (ctx.count != 0)) {
logerror("... WROTE: %d bytes, %d segments, avg %d\n",
- (int)ctx.total, (int)ctx.count, (int)(ctx.total/ctx.count));
+ (int)ctx.total, (int)ctx.count, (int)(ctx.total/ctx.count));
+ }
/* if required, reset the CPU so it runs what we just uploaded */
if (cpucs_addr && !ezusb_cpucs(device, cpucs_addr, true))
uint8_t* port_numbers, int port_numbers_len)
{
int i = port_numbers_len;
+ struct libusb_context *ctx = DEVICE_CTX(dev);
- while(dev) {
- // HCDs can be listed as devices and would have port #0
- // TODO: see how the other backends want to implement HCDs as parents
- if (dev->port_number == 0)
- break;
- i--;
- if (i < 0) {
- usbi_warn(DEVICE_CTX(dev),
- "port numbers array too small");
+ if (port_numbers_len <= 0)
+ return LIBUSB_ERROR_INVALID_PARAM;
+
+ // HCDs can be listed as devices with port #0
+ while((dev) && (dev->port_number != 0)) {
+ if (--i < 0) {
+ usbi_warn(ctx, "port numbers array is too small");
return LIBUSB_ERROR_OVERFLOW;
}
port_numbers[i] = dev->port_number;
dev = dev->parent_dev;
}
- memmove(port_numbers, &port_numbers[i], port_numbers_len - i);
+ if (i < port_numbers_len)
+ memmove(port_numbers, &port_numbers[i], port_numbers_len - i);
return port_numbers_len - i;
}
size = safe_strlen(path)+1;
root_size = sizeof(root_prefix)-1;
- // Microsoft indiscriminatly uses '\\?\', '\\.\', '##?#" or "##.#" for root prefixes.
+ // Microsoft indiscriminately uses '\\?\', '\\.\', '##?#" or "##.#" for root prefixes.
if (!((size > 3) && (((path[0] == '\\') && (path[1] == '\\') && (path[3] == '\\')) ||
((path[0] == '#') && (path[1] == '#') && (path[3] == '#'))))) {
add_root = root_size;
safe_strcpy(&ret_path[add_root], size-add_root, path);
- // Ensure consistancy with root prefix
+ // Ensure consistency with root prefix
for (j=0; j<root_size; j++)
ret_path[j] = root_prefix[j];
// Dummy call to get the required data size. Initial failures are reported as info rather
// than error as they can occur for non-penalizing situations, such as with some hubs.
+ // coverity[tainted_data_argument]
if (!DeviceIoControl(hub_handle, IOCTL_USB_GET_DESCRIPTOR_FROM_NODE_CONNECTION, &cd_buf_short, size,
&cd_buf_short, size, &ret_size, NULL)) {
usbi_info(ctx, "could not access configuration descriptor (dummy) for '%s': %s", device_id, windows_error_str(0));
// Cache the descriptor
priv->config_descriptor[i] = (unsigned char*) malloc(cd_data->wTotalLength);
if (priv->config_descriptor[i] == NULL)
- return LIBUSB_ERROR_NO_MEM;
+ LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
memcpy(priv->config_descriptor[i], cd_data, cd_data->wTotalLength);
}
return LIBUSB_SUCCESS;
DWORD size;
USB_NODE_CONNECTION_INFORMATION_EX conn_info;
struct windows_device_priv *priv, *parent_priv;
- struct libusb_context *ctx = DEVICE_CTX(dev);
+ struct libusb_context *ctx;
struct libusb_device* tmp_dev;
unsigned i;
if ((dev == NULL) || (parent_dev == NULL)) {
return LIBUSB_ERROR_NOT_FOUND;
}
+ ctx = DEVICE_CTX(dev);
priv = _device_priv(dev);
parent_priv = _device_priv(parent_dev);
if (parent_priv->apib->id != USB_API_HUB) {
}
size = sizeof(conn_info);
conn_info.ConnectionIndex = (ULONG)port_number;
+ // coverity[tainted_data_argument]
if (!DeviceIoControl(handle, IOCTL_USB_GET_NODE_CONNECTION_INFORMATION_EX, &conn_info, size,
&conn_info, size, &size, NULL)) {
usbi_warn(ctx, "could not get node connection information for device '%s': %s",
}
// Unref newly allocated devs
- for (i=0; i<unref_cur; i++) {
- safe_unref_device(unref_list[i]);
+ if (unref_list != NULL) {
+ for (i=0; i<unref_cur; i++) {
+ safe_unref_device(unref_list[i]);
+ }
+ free(unref_list);
}
- safe_free(unref_list);
return r;
}
case 0:
WaitForSingleObject(timer_mutex, INFINITE);
// Requests to this thread are for hires always
- if (QueryPerformanceCounter(&hires_counter) != 0) {
+ if ((QueryPerformanceCounter(&hires_counter) != 0) && (hires_frequency != 0)) {
timer_tp.tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
timer_tp.tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency)/1000) * hires_ticks_to_ps);
} else {
usbi_err(ctx, "could not open device %s: %s", filter_path, windows_error_str(0));
} else {
WinUSBX[sub_api].Free(winusb_handle);
- if (!WinUSBX[sub_api].Initialize(file_handle, &winusb_handle)) {
- continue;
- }
- found_filter = true;
- break;
+ if (WinUSBX[sub_api].Initialize(file_handle, &winusb_handle))
+ found_filter = true;
+ else
+ usbi_err(ctx, "could not initialize filter driver for %s", filter_path);
}
}
}