Skip to content

Commit

Permalink
Merge pull request #602 from itsenkov/itsenkov/master/bsod-adb-fix
Browse files Browse the repository at this point in the history
bugfix: Handle zero-len packets from ADB to avoid BSOD
  • Loading branch information
dorssel authored May 24, 2023
2 parents 81e89fb + 60d205d commit 2aa1573
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Usbipd/AttachedClient.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ async Task HandleSubmitAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSubmit submit
} }
pending = true; pending = true;


if (buf.Length > 0)
{
// Input or output, exceptions or not, this buffer must be locked until after the ioctl has completed. // Input or output, exceptions or not, this buffer must be locked until after the ioctl has completed.
var gcHandle = GCHandle.Alloc(buf, GCHandleType.Pinned); var gcHandle = GCHandle.Alloc(buf, GCHandleType.Pinned);
try try
Expand All @@ -366,6 +368,13 @@ async Task HandleSubmitAsync(UsbIpHeaderBasic basic, UsbIpHeaderCmdSubmit submit
gcHandle.Free(); gcHandle.Free();
}, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default); }, CancellationToken.None, TaskContinuationOptions.ExecuteSynchronously, TaskScheduler.Default);
} }
else
{
urb.buf = IntPtr.Zero;
StructToBytes(urb, bytes);
ioctl = Device.IoControlAsync(SUPUSB_IOCTL.SEND_URB, bytes, bytes);
}
}


// At this point we have initiated the ioctl (and possibly awaited it for special cases). // At this point we have initiated the ioctl (and possibly awaited it for special cases).
// Now we schedule a continuation to create the response once the ioctl completes. // Now we schedule a continuation to create the response once the ioctl completes.
Expand Down

0 comments on commit 2aa1573

Please sign in to comment.