Skip to content

Commit

Permalink
phy: Ensure debug tracing can't crash
Browse files Browse the repository at this point in the history
For robustness, don't panic when unable to deserialize a telegram that
is to be transmitted by us.

This should never matter to real applications, but is needed for
fuzzing and other robustness test methods.
  • Loading branch information
Rahix committed Nov 22, 2024
1 parent 16f0917 commit 6aa8b48
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/phy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ pub trait ProfibusPhy {
let ttx = crate::fdl::TelegramTx::new(buffer);
let response = f(ttx);
if let Some(response) = response {
log::trace!(
"PHY TX {:?}",
crate::fdl::Telegram::deserialize(buffer).unwrap().unwrap()
);
let bytes_sent = response.bytes_sent();

if let Some(Ok(t)) = crate::fdl::Telegram::deserialize(buffer) {
log::trace!("PHY TX {:?}", t);
} else {
log::trace!("PHY TX {:?} (invalid!)", &buffer[..bytes_sent]);
}

(bytes_sent, Some(response))
} else {
(0, None)
Expand Down

0 comments on commit 6aa8b48

Please sign in to comment.