core: Fix unlocked access to timeout_flags
authorHans de Goede <hdegoede@redhat.com>
Mon, 6 Jun 2016 15:43:23 +0000 (17:43 +0200)
committerNathan Hjelm <hjelmn@me.com>
Wed, 17 Aug 2016 18:52:40 +0000 (12:52 -0600)
commitce59e6ea12852f25025fef5ef42da9e271049a59
tree1bc1df42be82856d2a6d7e5ebb752a092f9db841
parentefcfe05a2a572b67a5fbacdc855ac678b2ce8380
core: Fix unlocked access to timeout_flags

There is a race between handle_timeout() and the completion functions.
When one thread is in handle_timeout() and another thread wakes
up from a poll(), there exists a window where the transfer has been
cancelled, but USBI_TRANSFER_TIMED_OUT is not yet set in timeout_flags.
Therefore, usbi_handle_transfer_completion() is sometimes called
with LIBUSB_TRANSFER_CANCELLED instead of the expected
LIBUSB_TRANSFER_TIMED_OUT.

timeout_flags is protected by the flying_transfers_lock, this commit
makes usbi_handle_transfer_cancellation() take that lock before
checking for USBI_TRANSFER_TIMED_OUT in timeout_flags, fixing this.

Reported-by: Joost Muller <joostmuller@gmail.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
libusb/io.c
libusb/version_nano.h