usb: reject instead of panic on CONTROL OUT longer than the buf.

This commit is contained in:
Dario Nieuwenhuis 2023-11-06 03:26:00 +01:00
parent 46cffcc8d4
commit d9b00c01e0

View File

@ -406,6 +406,16 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> {
let max_packet_size = self.control.max_packet_size(); let max_packet_size = self.control.max_packet_size();
let mut total = 0; let mut total = 0;
if req_length > self.control_buf.len() {
warn!(
"got CONTROL OUT with length {} higher than the control_buf len {}, rejecting.",
req_length,
self.control_buf.len()
);
self.control.reject().await;
return;
}
let chunks = self.control_buf[..req_length].chunks_mut(max_packet_size); let chunks = self.control_buf[..req_length].chunks_mut(max_packet_size);
for (first, last, chunk) in first_last(chunks) { for (first, last, chunk) in first_last(chunks) {
let size = match self.control.data_out(chunk, first, last).await { let size = match self.control.data_out(chunk, first, last).await {