Skip to content

Commit

Permalink
backend: Check number of fds before parsing message
Browse files Browse the repository at this point in the history
This prevents an fd from being consumed if the message will later fail
to parse because another fd has been read. Which is theoretically
possible.
  • Loading branch information
ids1024 committed Nov 2, 2023
1 parent 2a505ed commit 707f0b9
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions wayland-backend/src/rs/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ pub fn parse_message<'a>(
return Err(MessageParseError::MissingData);
}

let fd_len = signature.iter().filter(|x| matches!(x, ArgumentType::Fd)).count();
if fd_len > fds.len() {
return Err(MessageParseError::MissingFD);
}

let (mut payload, rest) = raw.split_at(len);
payload = &payload[2..];

Expand Down

0 comments on commit 707f0b9

Please sign in to comment.