aatxe / irc

the irc crate – usable, async IRC for Rust
Mozilla Public License 2.0
526 stars 100 forks source link

Panic on PRIVMSG with single SOH #170

Closed Blajda closed 5 years ago

Blajda commented 5 years ago

Hi! I recently had a panic when a server sent a malformed ctcp message which had only a single SOH character. :user!user@test.irc PRIVMSG #testchan :

I've included a patch that checks the message length and a test to prevent regression.

thread 'tokio-runtime-worker-0' panicked at 'begin <= end (1 <= 0) when slicing ``', libcore/str/mod.rs:2098:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:477
   5: std::panicking::continue_panic_fmt
             at libstd/panicking.rs:391
   6: rust_begin_unwind
             at libstd/panicking.rs:326
   7: core::panicking::panic_fmt
             at libcore/panicking.rs:77
   8: core::str::slice_error_fail
             at libcore/str/mod.rs:0
   9: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index::{{closure}}
             at libcore/str/mod.rs:1894
  10: <core::option::Option<T>>::unwrap_or_else
             at libcore/option.rs:396
  11: core::str::traits::<impl core::slice::SliceIndex<str> for core::ops::range::Range<usize>>::index
             at libcore/str/mod.rs:1894
  12: core::str::traits::<impl core::ops::index::Index<core::ops::range::Range<usize>> for str>::index
             at libcore/str/mod.rs:1670
  13: <alloc::string::String as core::ops::index::Index<core::ops::range::Range<usize>>>::index
             at liballoc/string.rs:1945
  14: irc::client::ClientState::handle_message
             at /home/david/.cargo/git/checkouts/irc-064afc2c41a8d908/949b18e/src/client/mod.rs:344
  15: <irc::client::ClientStream as futures::stream::Stream>::poll
             at /home/david/.cargo/git/checkouts/irc-064afc2c41a8d908/949b18e/src/client/mod.rs:215
  16: <futures::stream::map_err::MapErr<S, F> as futures::stream::Stream>::poll
             at /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-0.1.25/src/stream/map_err.rs:78
  17: <futures::stream::for_each::ForEach<S, F, U> as futures::future::Future>::poll
aatxe commented 5 years ago

Fixed in #171! Thanks!