diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-06 03:26:00 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-11-06 03:26:00 +0100 |
| commit | d9b00c01e09deea8d1255a89ce40174960aad793 (patch) | |
| tree | eace31596529836a1f1bee4d6ba57af1b906bf65 /embassy-usb/src/lib.rs | |
| parent | 46cffcc8d4f545f1ffd998d04c09e615e9b12091 (diff) | |
usb: reject instead of panic on CONTROL OUT longer than the buf.
Diffstat (limited to 'embassy-usb/src/lib.rs')
| -rw-r--r-- | embassy-usb/src/lib.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/embassy-usb/src/lib.rs b/embassy-usb/src/lib.rs index 88d88cad7..9fc1e3320 100644 --- a/embassy-usb/src/lib.rs +++ b/embassy-usb/src/lib.rs | |||
| @@ -406,6 +406,16 @@ impl<'d, D: Driver<'d>> UsbDevice<'d, D> { | |||
| 406 | let max_packet_size = self.control.max_packet_size(); | 406 | let max_packet_size = self.control.max_packet_size(); |
| 407 | let mut total = 0; | 407 | let mut total = 0; |
| 408 | 408 | ||
| 409 | if req_length > self.control_buf.len() { | ||
| 410 | warn!( | ||
| 411 | "got CONTROL OUT with length {} higher than the control_buf len {}, rejecting.", | ||
| 412 | req_length, | ||
| 413 | self.control_buf.len() | ||
| 414 | ); | ||
| 415 | self.control.reject().await; | ||
| 416 | return; | ||
| 417 | } | ||
| 418 | |||
| 409 | let chunks = self.control_buf[..req_length].chunks_mut(max_packet_size); | 419 | let chunks = self.control_buf[..req_length].chunks_mut(max_packet_size); |
| 410 | for (first, last, chunk) in first_last(chunks) { | 420 | for (first, last, chunk) in first_last(chunks) { |
| 411 | let size = match self.control.data_out(chunk, first, last).await { | 421 | let size = match self.control.data_out(chunk, first, last).await { |
