Skip to content

mDNS shouldn't panic if response packet becomes too large #1872

Description

@tomaka

I'm getting this bug report:

   Alice ERR: 
   Alice ERR: ====================
   Alice ERR: 
   Alice ERR: Version: 0.8.26-065b2e076-x86_64-linux-gnu
   Alice ERR: 
   Alice ERR:    0: sp_panic_handler::set::{{closure}}
   Alice ERR:    1: std::panicking::rust_panic_with_hook
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/std/src/panicking.rs:595
   Alice ERR:    2: std::panicking::begin_panic_handler::{{closure}}
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/std/src/panicking.rs:497
   Alice ERR:    3: std::sys_common::backtrace::__rust_end_short_backtrace
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/std/src/sys_common/backtrace.rs:141
   Alice ERR:    4: rust_begin_unwind
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/std/src/panicking.rs:493
   Alice ERR:    5: core::panicking::panic_fmt
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/core/src/panicking.rs:92
   Alice ERR:    6: core::option::expect_none_failed
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/core/src/option.rs:1268
   Alice ERR:    7: <libp2p_mdns::behaviour::Mdns as libp2p_swarm::behaviour::NetworkBehaviour>::poll
   Alice ERR:    8: <sc_network::discovery::DiscoveryBehaviour as libp2p_swarm::behaviour::NetworkBehaviour>::poll
   Alice ERR:    9: libp2p_swarm::ExpandedSwarm<TBehaviour,TInEvent,TOutEvent,THandler>::poll_next_event
   Alice ERR:   10: <sc_network::service::NetworkWorker<B,H> as core::future::future::Future>::poll
   Alice ERR:   11: sc_service::build_network_future::{{closure}}::{{closure}}::{{closure}}
   Alice ERR:   12: <futures_util::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
   Alice ERR:   13: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   Alice ERR:   14: <sc_service::task_manager::prometheus_future::PrometheusFuture<T> as core::future::future::Future>::poll
   Alice ERR:   15: <futures_util::future::select::Select<A,B> as core::future::future::Future>::poll
   Alice ERR:   16: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   Alice ERR:   17: <tracing_futures::Instrumented<T> as core::future::future::Future>::poll
   Alice ERR:   18: std::thread::local::LocalKey<T>::with
   Alice ERR:   19: futures_executor::local_pool::block_on
   Alice ERR:   20: tokio::runtime::task::core::Core<T,S>::poll
   Alice ERR:   21: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   Alice ERR:   22: tokio::runtime::task::harness::Harness<T,S>::poll
   Alice ERR:   23: tokio::runtime::blocking::pool::Inner::run
   Alice ERR:   24: tokio::runtime::context::enter
   Alice ERR:   25: std::sys_common::backtrace::__rust_begin_short_backtrace
   Alice ERR:   26: core::ops::function::FnOnce::call_once{{vtable.shim}}
   Alice ERR:   27: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/alloc/src/boxed.rs:1327
   Alice ERR:       <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/alloc/src/boxed.rs:1327
   Alice ERR:       std::sys::unix::thread::Thread::new::thread_start
   Alice ERR:              at /rustc/b7ebc6b0c1ba3c27ebb17c0b496ece778ef11e18/library/std/src/sys/unix/thread.rs:71
   Alice ERR:   28: start_thread
   Alice ERR:   29: __clone
   Alice ERR: 
   Alice ERR: 
   Alice ERR: Thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: ResponseTooLong', /home/bernhard/.cargo/registry/src/github.com-1ecc6299db9ec823/libp2p-mdns-0.25.0/src/behaviour.rs:296
   Alice ERR: 

I haven't investigated the problem, but ResponseTooLong seems to indicate a malformed mDNS packet.
Regardless of whether the packet is indeed malformed or not, it shouldn't result in a panic.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions