Skip to content

Commit 3973e7e

Browse files
committed
Add overflow check for descriptor lengths
1 parent 675dfe4 commit 3973e7e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/descriptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl DescriptorWriter<'_> {
6060
pub fn write(&mut self, descriptor_type: u8, descriptor: &[u8]) -> Result<()> {
6161
let length = descriptor.len();
6262

63-
if self.position + 2 + length > self.buf.len() {
63+
if (self.position + 2 + length) > self.buf.len() || (length + 2) > 255 {
6464
return Err(UsbError::BufferOverflow);
6565
}
6666

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ pub enum UsbError {
4545
/// Parsing failed due to invalid input.
4646
ParseError,
4747

48-
/// A buffer too short for the data to read was passed.
48+
/// A buffer too short for the data to read was passed, or provided data cannot fit within
49+
/// length constraints.
4950
BufferOverflow,
5051

5152
/// Classes attempted to allocate more endpoints than the peripheral supports.

0 commit comments

Comments
 (0)