question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Smart card reader causes libusb crash

See original GitHub issue

Insert and unplug the smart card reader on windows platform causes libusb crash. releated issues #285

static char *parse_device_interface_path(const char *interface_path)
{
	char *device_id, *guid_start;
	unsigned int i, len;

	len = safe_strlen(interface_path);
	if (len < 4) {
		return NULL;
	}

	// Microsoft indiscriminatly uses '\\?\', '\\.\', '##?#" or "##.#" for root prefixes.
	if (((interface_path[0] == '\\') && (interface_path[1] == '\\') && (interface_path[3] == '\\')) ||
		((interface_path[0] == '#') && (interface_path[1] == '#') && (interface_path[3] == '#'))) {
		interface_path += 4;
		len -= 4;
	}

	guid_start = strchr(interface_path, '{');
	if (guid_start != NULL) {
		len = (guid_start - interface_path) - 1; // One more for separator
	}

	if (len <= 0) {
		usbi_err(NULL, "program assertion failed: invalid device interface path");
		return NULL;
	}

	device_id = calloc(len + 1, 1); // One additional for NULL term.
	if (device_id == NULL) {
		return NULL;
	}
	strncat(device_id, interface_path, len);

	// Now convert to uppercase and replace '#' with '\'
	for (i = 0; i < len; i++) {
		device_id[i] = (char)toupper((int)device_id[i]);
		if (device_id[i] == '#')
			device_id[i] = '\\';
	}

	return device_id;
}

The unsigned int len cause the len Value cannot be negative and then Cause the code if(len<=0) not to be executed when len should be -1;

device_id[i] emit Array out of bounds exception

Just need to modify unsigned int len to int len

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
danielmaincommented, Sep 15, 2021

Having the same Issue. Thank you @xdimh now can I patch it in my project.

Dont you @xdimh want to create a PR so that the node-usb Team can apply it faster?

0reactions
thegeckocommented, Mar 26, 2022

Excellent, closing. Please re open this if required.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pcscd crashes when disconnecting / reconnecting USB device
I have libusb only in use for the smart card reader and for a scanner. The scanner is addressed by xsane and this...
Read more >
USB card readers crash computer in Windows 8
I am having problems getting two of my computers to work with card readers. Both are Windows 8 and one of the two...
Read more >
Bountysource
Smart card reader causes libusb crash.
Read more >
August 2010 - Ludovic Rousseau's blog
If libusb is used by pcsc-lite the USB bus is scanned every 1 second. ... The card status is asked by pcscd to...
Read more >
Charon crash issue on remote device after restart on local ...
Charon crash issue due to usage of smartcard-hsm ... operations using the PKCS#11 with the same device, card reader and smart cards, ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found