[haiku-commits] haiku: hrev53478 - src/add-ons/kernel/drivers/input/usb_hid

  • From: Stephan Aßmus <superstippi@xxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 13 Sep 2019 13:40:53 -0400 (EDT)

hrev53478 adds 1 changeset to branch 'master'
old head: be06cb25e905e1a130746668018fdde58e3305f3
new head: 428d8bc6fcdc949dc538d29e32255402072f10a5
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=428d8bc6fcdc+%5Ebe06cb25e905

----------------------------------------------------------------------------

428d8bc6fcdc: usb_hid: use user_memcpy in JoystickProtocolHandler::Control().
  
  on success, returns B_OK instead of B_ERROR.
  
  Change-Id: I3e415d812ddbc6dbc4d27f346bbe7ea59374b39f
  Reviewed-on: https://review.haiku-os.org/c/haiku/+/1861
  Reviewed-by: Stephan Aßmus <superstippi@xxxxxx>

                                   [ Jérôme Duval <jerome.duval@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev53478
Commit:      428d8bc6fcdc949dc538d29e32255402072f10a5
URL:         https://git.haiku-os.org/haiku/commit/?id=428d8bc6fcdc
Author:      Jérôme Duval <jerome.duval@xxxxxxxxx>
Date:        Fri Sep 13 16:51:56 2019 UTC
Committer:   Stephan Aßmus <superstippi@xxxxxx>
Commit-Date: Fri Sep 13 17:40:27 2019 UTC

----------------------------------------------------------------------------

1 file changed, 14 insertions(+), 4 deletions(-)
.../input/usb_hid/JoystickProtocolHandler.cpp      | 18 ++++++++++++++----

----------------------------------------------------------------------------

diff --git 
a/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp 
b/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
index 6900951c20..0dbcb3ce94 100644
--- a/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
+++ b/src/add-ons/kernel/drivers/input/usb_hid/JoystickProtocolHandler.cpp
@@ -19,6 +19,8 @@
 #include <string.h>
 #include <usb/USB_hid.h>
 
+#include <kernel.h>
+
 
 JoystickProtocolHandler::JoystickProtocolHandler(HIDReport &report)
        :
@@ -271,7 +273,11 @@ JoystickProtocolHandler::Control(uint32 *cookie, uint32 
op, void *buffer,
                        if (result != B_OK)
                                return result;
 
-                       fJoystickModuleInfo = *(joystick_module_info *)buffer;
+                       if (!IS_USER_ADDRESS(buffer)
+                               || user_memcpy(&fJoystickModuleInfo, buffer,
+                                       sizeof(joystick_module_info)) != B_OK) {
+                               return B_BAD_ADDRESS;
+                       }
 
                        bool supportsVariable = (fJoystickModuleInfo.flags
                                & js_flag_variable_size_reads) != 0;
@@ -298,15 +304,19 @@ JoystickProtocolHandler::Control(uint32 *cookie, uint32 
op, void *buffer,
                        fJoystickModuleInfo.num_sticks = 1;
                        fJoystickModuleInfo.config_size = 0;
                        mutex_unlock(&fUpdateLock);
-                       break;
+                       return B_OK;
                }
 
                case B_JOYSTICK_GET_DEVICE_MODULE:
                        if (length < sizeof(joystick_module_info))
                                return B_BAD_VALUE;
 
-                       *(joystick_module_info *)buffer = fJoystickModuleInfo;
-                       break;
+                       if (!IS_USER_ADDRESS(buffer)
+                               || user_memcpy(buffer, &fJoystickModuleInfo,
+                                       sizeof(joystick_module_info)) != B_OK) {
+                               return B_BAD_ADDRESS;
+                       }
+                       return B_OK;
        }
 
        return B_ERROR;


Other related posts:

  • » [haiku-commits] haiku: hrev53478 - src/add-ons/kernel/drivers/input/usb_hid - Stephan Aßmus