diff options
| author | Jan Niehusmann <[email protected]> | 2022-08-30 20:36:57 +0000 |
|---|---|---|
| committer | Jan Niehusmann <[email protected]> | 2022-08-30 20:37:02 +0000 |
| commit | acaa8b3e8b80ccd49e04a6dc7d595d3a52d1ad0d (patch) | |
| tree | 49f718ce3ec80d8f99059842597fce52023f87fa /src/lib.rs | |
| parent | 69e92e5639e0a86994c9bdf647a0f2d57f768898 (diff) | |
Fix calculation of slice index
total_len is already rounded up, so the `+ 3` is not needed.
And even if it was, the calculation should have been `((total_len + 3) / 4)`.
`(total_len + 3 / 4)` is equivalent to `total_len` and can overflow
the slice, leading to a panic which can easily be triggered by sending
large ICMP ECHO packets to the device.
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs index 8f439cf2f..34170a266 100644 --- a/src/lib.rs +++ b/src/lib.rs | |||
| @@ -762,7 +762,7 @@ where | |||
| 762 | let bus = unsafe { &mut *bus }; | 762 | let bus = unsafe { &mut *bus }; |
| 763 | async { | 763 | async { |
| 764 | bus.write(&[cmd]).await?; | 764 | bus.write(&[cmd]).await?; |
| 765 | bus.write(&buf[..(total_len + 3 / 4)]).await?; | 765 | bus.write(&buf[..(total_len / 4)]).await?; |
| 766 | Ok(()) | 766 | Ok(()) |
| 767 | } | 767 | } |
| 768 | }) | 768 | }) |
