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

drivers/libusb1.c: fix wrong return value of nut_libusb_get_interrupt() #2701

Merged
merged 1 commit into from
Nov 30, 2024

Conversation

fenugrec
Copy link
Contributor

@fenugrec fenugrec commented Nov 29, 2024

cf github #2401

When global var 'interrupt_size' is not set, a transfer size of SMALLBUF (512) is requested when calling libusb_interrupt_transfer(). Our function nut_libusb_get_interrupt() should return the actual transferred size. Otherwise, the caller will attempt to parse any uninitialized data in the buffer after the response.

In libusb0.c this was done correctly by using the return value of usb_interrupt_read(). With libusb1, the transferred size is written to tmpbufsize, and should therefore be used as the return val.


can we trust libusb to not return a value outside the range of usb_ctrl_charbufsize ? I did not add a check for this and simply cast the int. [edit - as noted in the review comments, this condition is already checked... 4 lines above)

cf github networkupstools#2401.

When global var 'interrupt_size' is not set, a transfer size of SMALLBUF (512) is requested when calling libusb_interrupt_transfer(). Our function nut_libusb_get_interrupt() should return the actual transferred size. Otherwise, the caller will attempt to parse any uninitialized data in the buffer after the response.

In libusb0.c this was done correctly by using the return value of usb_interrupt_read(). With libusb1, the transferred size is written to tmpbufsize, and should therefore be used as the return val.

Signed-off-by: fenugrec <[email protected]>
@jimklimov jimklimov added bug USB impacts-release-2.8.0 Issues reported against NUT release 2.8.0 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.1 Issues reported against NUT release 2.8.1 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) labels Nov 29, 2024
@jimklimov jimklimov added this to the 2.8.3 milestone Nov 29, 2024
@jimklimov jimklimov merged commit f4bbe62 into networkupstools:master Nov 30, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug impacts-release-2.8.0 Issues reported against NUT release 2.8.0 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.1 Issues reported against NUT release 2.8.1 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.2 Issues reported against NUT release 2.8.2 (maybe vanilla or with minor packaging tweaks) USB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants