Skip to content

Commit

Permalink
Check Map buffers on creation
Browse files Browse the repository at this point in the history
Replace calls to `MapBuffer::new` with `MapBuffer::new_checked`, during
link attribute parsing. Without this check, parsing `IFLA_MAP`
attributes would panic, if provided with a buffer too short to contain
the full `Map` attribute.
  • Loading branch information
Jeff-A-Martin authored and cathay4t committed Aug 12, 2024
1 parent 570c4f2 commit d53bbad
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/link/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,17 @@ impl<'a, T: AsRef<[u8]> + ?Sized>
.context("invalid IFLA_OPERSTATE value")?
.into(),
),
IFLA_MAP => Self::Map(
super::Map::parse(&MapBuffer::new(payload))
.context(format!("Invalid IFLA_MAP value {:?}", payload))?,
),
IFLA_MAP => {
let err =
|payload| format!("Invalid IFLA_MAP value {:?}", payload);
Self::Map(
super::Map::parse(
&MapBuffer::new_checked(payload)
.context(err(payload))?,
)
.context(err(payload))?,
)
}
IFLA_STATS => Self::Stats(
super::Stats::parse(&StatsBuffer::new(
expand_buffer_if_small(
Expand Down

0 comments on commit d53bbad

Please sign in to comment.