usb_hid: Use user_memcpy in JoystickProtocolHandler::Read().
Also use a MutexLocker object, and fix a potential race around fCurrentValues.data_size. Fixes #15404.
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
#include <usb/USB_hid.h>
|
#include <usb/USB_hid.h>
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
#include <util/AutoLock.h>
|
||||||
|
|
||||||
|
|
||||||
JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
|
JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
|
||||||
@@ -236,14 +237,15 @@ JoystickProtocolHandler::Read(uint32 *cookie, off_t position, void *buffer,
|
|||||||
return B_BUFFER_OVERFLOW;
|
return B_BUFFER_OVERFLOW;
|
||||||
|
|
||||||
// this is a polling interface, we just return the current value
|
// this is a polling interface, we just return the current value
|
||||||
status_t result = mutex_lock(&fUpdateLock);
|
MutexLocker locker(fUpdateLock);
|
||||||
if (result != B_OK) {
|
if (!locker.IsLocked()) {
|
||||||
*numBytes = 0;
|
*numBytes = 0;
|
||||||
return result;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(buffer, fCurrentValues.data, fCurrentValues.data_size);
|
if (!IS_USER_ADDRESS(buffer) || user_memcpy(buffer, fCurrentValues.data,
|
||||||
mutex_unlock(&fUpdateLock);
|
fCurrentValues.data_size) != B_OK)
|
||||||
|
return B_BAD_ADDRESS;
|
||||||
|
|
||||||
*numBytes = fCurrentValues.data_size;
|
*numBytes = fCurrentValues.data_size;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
|||||||
Reference in New Issue
Block a user