Mercurial > hg > ucis.core
comparison USBLib/Communication/WinUsb/WinUsbDevice.cs @ 36:c4a5dbe62513
USBLib: small fix in WinUSB backend bounds checking
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Sun, 21 Apr 2013 18:32:43 +0200 |
parents | dcfec2be27c9 |
children | 053cc617af54 |
comparison
equal
deleted
inserted
replaced
35:6fcedb1030bf | 36:c4a5dbe62513 |
---|---|
170 public override int ControlRead(UsbControlRequestType requestType, byte request, short value, short index, byte[] buffer, int offset, int length) { | 170 public override int ControlRead(UsbControlRequestType requestType, byte request, short value, short index, byte[] buffer, int offset, int length) { |
171 return ControlTransfer((byte)(requestType | UsbControlRequestType.EndpointIn), request, value, index, buffer, offset, length); | 171 return ControlTransfer((byte)(requestType | UsbControlRequestType.EndpointIn), request, value, index, buffer, offset, length); |
172 } | 172 } |
173 | 173 |
174 public unsafe override int GetDescriptor(byte descriptorType, byte index, short langId, byte[] buffer, int offset, int length) { | 174 public unsafe override int GetDescriptor(byte descriptorType, byte index, short langId, byte[] buffer, int offset, int length) { |
175 if (length > short.MaxValue || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length"); | 175 if (length > short.MaxValue || offset < 0 || length < 0 || offset + length > buffer.Length) throw new ArgumentOutOfRangeException("length"); |
176 fixed (Byte* b = buffer) { | 176 fixed (Byte* b = buffer) { |
177 if (!WinUsb_GetDescriptor(InterfaceHandles[0], descriptorType, index, (ushort)langId, (IntPtr)(b + offset), length, out length)) | 177 if (!WinUsb_GetDescriptor(InterfaceHandles[0], descriptorType, index, (ushort)langId, (IntPtr)(b + offset), length, out length)) |
178 throw new Win32Exception(Marshal.GetLastWin32Error(), "Descriptor transfer failed"); | 178 throw new Win32Exception(Marshal.GetLastWin32Error(), "Descriptor transfer failed"); |
179 } | 179 } |
180 return length; | 180 return length; |