usbip: fix review findings
This commit is contained in:
@@ -166,6 +166,10 @@ func WriteSubmitCommand(w io.Writer, command SubmitCommand) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = validateUSBIPPayloadBuffer(command.Header.Direction, command.Buffer, command.TransferBufferLength, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
packetCount := normalizeUSBIPIsoPacketCount(command.NumberOfPackets, command.IsoPackets)
|
||||
err = validateUSBIPIsoPacketCount(packetCount)
|
||||
if err != nil {
|
||||
@@ -197,6 +201,10 @@ func WriteSubmitResponse(w io.Writer, response SubmitResponse) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = validateUSBIPPayloadBuffer(response.Header.Direction, response.Buffer, response.ActualLength, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
packetCount := normalizeUSBIPIsoPacketCount(response.NumberOfPackets, response.IsoPackets)
|
||||
err = validateUSBIPIsoPacketCount(packetCount)
|
||||
if err != nil {
|
||||
@@ -356,6 +364,19 @@ func validateUSBIPBufferLength(length int32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateUSBIPPayloadBuffer(direction uint32, buffer []byte, length int32, command bool) error {
|
||||
if shouldCarryUSBIPBuffer(direction, command) {
|
||||
if len(buffer) != int(length) {
|
||||
return E.New("USB/IP payload length mismatch: header length ", length, ", buffer length ", len(buffer))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(buffer) > 0 {
|
||||
return E.New("USB/IP unexpected payload buffer: ", len(buffer))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateUSBIPIsoPacketCount(count int32) error {
|
||||
if count < nonIsoPacketCount {
|
||||
return E.New("USB/IP iso packet count is negative: ", count)
|
||||
|
||||
Reference in New Issue
Block a user