Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null serial number generating crash in Windows #185

Open
luisfrossi opened this issue Sep 8, 2014 · 6 comments
Open

Null serial number generating crash in Windows #185

luisfrossi opened this issue Sep 8, 2014 · 6 comments

Comments

@luisfrossi
Copy link

Hi,

Hidapi 8.0-rc1 in windows.

At the hid_open with a defined serial_number as argument, sometimes, for some reason the cur_dev serial number is pointed to memory address 0 (not sure why) and so the wcscmp crashes the application.

Changing the line 522 to if (serial_number && cur_dev->serial_number) corrects the problem and is a safer operation.

Any comments on the wrong serial number address?

Regads,

Luis

@signal11
Copy link
Owner

signal11 commented Sep 8, 2014

hmm strange. The code is wrong, but it takes an unusual situation to trigger it. To trigger it, you have to ask for a device by VID/PID/serial, and a device must be connected with the same VID/PID that has no serial number (NULL). It's not something people normally encounter, since they know whether the device will have a serial number up front or not.

Regardless, it should be fixed. Would you mind sending a patch? All platforms will be affected by this, since hid_open() is nearly identical on all of them (as it uses the public API of hid_enumerate()).

Thanks for chasing this down.

@luisfrossi
Copy link
Author

Sorry,

Not pretty sure how to send a path. Any instructions?

In fact the real code should be:

        if (serial_number) {
            if(cur_dev->serial_number)

Otherway it will assign the path_to_open

Anyway, let me explain what i am doing so you might be able to explain me why i am getting NULL serial number.

I got an product that connects to my application. The application should be able to handle multiple devices at once and poll them to check their status. In order to manage from a connection point of view which device is which the class of the device interface stores the handle of the device. Them periodiaclly i call an hid_enumarate to check if got any new device connected. To check if the devices from the list are the same enumerated i compare the serial_number.. for some reason, sometimes i call the hid_open with the serial number as argument that i just got from the hid_enumerate and it happens to get an device with empty serial number at the hid_enumerate inside the hid_open.

Any idea why? Any sugestion on how to improve the management of the devices? If i could guarantee that they would not appear at the enumeration after the handle is open i would be fine.. but i am not sure how to do that...

Regards,

Luis

@signal11
Copy link
Owner

signal11 commented Sep 8, 2014

Any sugestion on how to improve the management of the devices?

From the results of hid_enumerate(), check the path instead of the serial.

@fallen
Copy link

fallen commented Jun 19, 2015

Hi,
This issue also happens when the device really has a serial number BUT you are not running with sufficient rights to get it, therefore it will still be NULL even if the device really has a serial number.

So you get in a situation where your program works fine when running as root, but segmentation faults when running as a simple user with no USB rights.
(have a look at this issue #23 on m-labs/artiq)

@fallen
Copy link

fallen commented Jun 19, 2015

I just noticed you fixed this bug in ac6120b
Maybe you should do a release which would allow Linux distributions to package it with the fix?

@sbourdeauducq
Copy link

Ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants