@@ -36,6 +36,10 @@ typedef LONG NTSTATUS;
36
36
#define _wcsdup wcsdup
37
37
#endif
38
38
39
+ /* The maximum number of characters that can be passed into the
40
+ HidD_Get*String() functions without it failing.*/
41
+ #define MAX_STRING_WCHARS 0xFFF
42
+
39
43
/*#define HIDAPI_USE_DDK*/
40
44
41
45
#ifdef __cplusplus
@@ -62,6 +66,9 @@ extern "C" {
62
66
63
67
#include "hidapi.h"
64
68
69
+ #undef MIN
70
+ #define MIN (x ,y ) ((x) < (y)? (x): (y))
71
+
65
72
#ifdef _MSC_VER
66
73
/* Thanks Microsoft, but I know how to use strncpy(). */
67
74
#pragma warning(disable:4996)
@@ -811,7 +818,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_manufacturer_string(hid_device *dev
811
818
{
812
819
BOOL res ;
813
820
814
- res = HidD_GetManufacturerString (dev -> device_handle , string , sizeof (wchar_t ) * maxlen );
821
+ res = HidD_GetManufacturerString (dev -> device_handle , string , sizeof (wchar_t ) * MIN ( maxlen , MAX_STRING_WCHARS ) );
815
822
if (!res ) {
816
823
register_error (dev , "HidD_GetManufacturerString" );
817
824
return -1 ;
@@ -824,7 +831,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_product_string(hid_device *dev, wch
824
831
{
825
832
BOOL res ;
826
833
827
- res = HidD_GetProductString (dev -> device_handle , string , sizeof (wchar_t ) * maxlen );
834
+ res = HidD_GetProductString (dev -> device_handle , string , sizeof (wchar_t ) * MIN ( maxlen , MAX_STRING_WCHARS ) );
828
835
if (!res ) {
829
836
register_error (dev , "HidD_GetProductString" );
830
837
return -1 ;
@@ -837,7 +844,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_serial_number_string(hid_device *de
837
844
{
838
845
BOOL res ;
839
846
840
- res = HidD_GetSerialNumberString (dev -> device_handle , string , sizeof (wchar_t ) * maxlen );
847
+ res = HidD_GetSerialNumberString (dev -> device_handle , string , sizeof (wchar_t ) * MIN ( maxlen , MAX_STRING_WCHARS ) );
841
848
if (!res ) {
842
849
register_error (dev , "HidD_GetSerialNumberString" );
843
850
return -1 ;
@@ -850,7 +857,7 @@ int HID_API_EXPORT_CALL HID_API_CALL hid_get_indexed_string(hid_device *dev, int
850
857
{
851
858
BOOL res ;
852
859
853
- res = HidD_GetIndexedString (dev -> device_handle , string_index , string , sizeof (wchar_t ) * maxlen );
860
+ res = HidD_GetIndexedString (dev -> device_handle , string_index , string , sizeof (wchar_t ) * MIN ( maxlen , MAX_STRING_WCHARS ) );
854
861
if (!res ) {
855
862
register_error (dev , "HidD_GetIndexedString" );
856
863
return -1 ;
0 commit comments