greshake / i3status-rust

Very resourcefriendly and feature-rich replacement for i3status, written in pure Rust
GNU General Public License v3.0
2.88k stars 475 forks source link

Crash when adding net block for wireless device #1271

Closed teeratpitakrat closed 3 years ago

teeratpitakrat commented 3 years ago

i3status-rust crashes when I add a net block for the wireless device on my laptop. I'm on Archlinux. ethtool, iw, and ip are installed. I'm running i3status-rust 0.20.2. This problem occurs since 0.20.0 in May.

[[block]]
block = "net"
device = "wlan0"
format = "{signal_strength} {speed_down;K} {speed_up;K}"
interval = 5
hide_inactive = true
$ RUST_BACKTRACE=full i3status-rs config.toml
{"version": 1, "click_events": true}
[
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', src/blocks/net.rs:668:60
stack backtrace:
   0:     0x559f38cf96c0 - <unknown>
   1:     0x559f38d2156f - <unknown>
   2:     0x559f38cf5955 - <unknown>
   3:     0x559f38cfba3b - <unknown>
   4:     0x559f38cfb50d - <unknown>
   5:     0x559f38cfc05d - <unknown>
   6:     0x559f38cfbbe7 - <unknown>
   7:     0x559f38cf9b5c - <unknown>
   8:     0x559f38cfbb49 - <unknown>
   9:     0x559f38924b51 - <unknown>
  10:     0x559f38924c43 - <unknown>
  11:     0x559f389981f7 - <unknown>
  12:     0x559f38ae61bd - <unknown>
  13:     0x559f389e832a - <unknown>
  14:     0x559f38a322ba - <unknown>
  15:     0x559f389ed103 - <unknown>
  16:     0x559f38ad65f9 - <unknown>
  17:     0x559f38cfc55a - <unknown>
  18:     0x559f38a36a92 - main
  19:     0x7f58bff8bb25 - __libc_start_main
  20:     0x559f3892531e - <unknown>
  21:                0x0 - <unknown>
$ ip addr
...
4: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff
    inet xx.xx.xx.xx/xx brd xx.xx.xx.xx scope global dynamic noprefixroute wlan0
       valid_lft 84293sec preferred_lft 84293sec
    inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/xxx scope global dynamic noprefixroute
       valid_lft 49sec preferred_lft 19sec
    inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/xxx scope global dynamic noprefixroute
       valid_lft 172792sec preferred_lft 86392sec
    inet6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/xxx scope link noprefixroute
       valid_lft forever preferred_lft forever
...
MaxVerevkin commented 3 years ago

Can you please compile from source in debug mode (i.e. just cargo build) and then post output of $ RUST_BACKTRACE=full <path-to-i3status-rs> config.toml?

teeratpitakrat commented 3 years ago
$ RUST_BACKTRACE=full ./i3status-rs config.toml
{"version": 1, "click_events": true}
[
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', src/blocks/net.rs:668:60
stack backtrace:
   0:     0x55cbbb418720 - std::backtrace_rs::backtrace::libunwind::trace::h90af754674ffafa4
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x55cbbb418720 - std::backtrace_rs::backtrace::trace_unsynchronized::hd35318b4e6e81148
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x55cbbb418720 - std::sys_common::backtrace::_print_fmt::h7571a6f5687a20d1
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x55cbbb418720 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he0119e0b769c2e9a
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x55cbbb4405df - core::fmt::write::h2b69bbb8432077e1
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/fmt/mod.rs:1094:17
   5:     0x55cbbb4149b5 - std::io::Write::write_fmt::h46cf1a7fb24b0a65
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/io/mod.rs:1584:15
   6:     0x55cbbb41aa9b - std::sys_common::backtrace::_print::h78ae9eccd44fa022
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x55cbbb41aa9b - std::sys_common::backtrace::print::h09e94b2c5bb4dae0
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x55cbbb41aa9b - std::panicking::default_hook::{{closure}}::hfc3b9f31beb26f15
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:208:50
   9:     0x55cbbb41a56d - std::panicking::default_hook::h24b36b429c561a5b
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:225:9
  10:     0x55cbbb41b0bd - std::panicking::rust_panic_with_hook::hcd8fcee5516a9191
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:591:17
  11:     0x55cbbb41ac47 - std::panicking::begin_panic_handler::{{closure}}::h19af3da01a9817bd
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:497:13
  12:     0x55cbbb418bbc - std::sys_common::backtrace::__rust_end_short_backtrace::h0a6d1565730521c9
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x55cbbb41aba9 - rust_begin_unwind
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:493:5
  14:     0x55cbba84c661 - core::panicking::panic_fmt::h4cabb5e7744685f2
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/panicking.rs:92:14
  15:     0x55cbba84c753 - core::result::unwrap_failed::ha412bb7b0e63ae4c
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/result.rs:1355:5
  16:     0x55cbba900302 - core::result::Result<T,E>::unwrap::he20d9fb8ab64251c
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/result.rs:1037:23
  17:     0x55cbbac66001 - i3status_rs::blocks::net::decode_escaped_unicode::hcd6c88f4524b67ac
                               at /tmp/i3status-rust/src/blocks/net.rs:668:32
  18:     0x55cbbac5d72d - i3status_rs::blocks::net::NetworkDevice::wifi_info::h75f1afc777660df1
                               at /tmp/i3status-rust/src/blocks/net.rs:178:55
  19:     0x55cbbac6489c - <i3status_rs::blocks::net::Net as i3status_rs::blocks::Block>::update::h9b39e525b4eaf810
                               at /tmp/i3status-rust/src/blocks/net.rs:603:36
  20:     0x55cbbaa3c19a - <i3status_rs::blocks::base_block::BaseBlock<T> as i3status_rs::blocks::Block>::update::h78949974ca266e3b
                               at /tmp/i3status-rust/src/blocks/base_block.rs:28:9
  21:     0x55cbbabdefde - i3status_rs::scheduler::UpdateScheduler::do_scheduled_updates::hd7c39949c161a272
                               at /tmp/i3status-rust/src/scheduler.rs:107:32
  22:     0x55cbbac77fff - i3status_rs::run::hf7bdd8b703c3c934
                               at /tmp/i3status-rust/src/main.rs:225:17
  23:     0x55cbbac75e9b - i3status_rs::main::h35bc860824e7d247
                               at /tmp/i3status-rust/src/main.rs:117:25
  24:     0x55cbbaba0efb - core::ops::function::FnOnce::call_once::hb4479b9a875f1b30
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/ops/function.rs:227:5
  25:     0x55cbbaa15a4e - std::sys_common::backtrace::__rust_begin_short_backtrace::h6b1e012f024705de
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/sys_common/backtrace.rs:125:18
  26:     0x55cbba882741 - std::rt::lang_start::{{closure}}::hed9be66ca3164534
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/rt.rs:49:18
  27:     0x55cbbb41b5ba - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h38252fcc236f7c8b
                               at /build/rust/src/rustc-1.53.0-src/library/core/src/ops/function.rs:259:13
  28:     0x55cbbb41b5ba - std::panicking::try::do_call::h1ec5110d27df1229
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:379:40
  29:     0x55cbbb41b5ba - std::panicking::try::h8d5e4776be23290c
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panicking.rs:343:19
  30:     0x55cbbb41b5ba - std::panic::catch_unwind::hf36a3ca3a68c9a49
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/panic.rs:431:14
  31:     0x55cbbb41b5ba - std::rt::lang_start_internal::h82c01d0d3e63445d
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/rt.rs:34:21
  32:     0x55cbba882720 - std::rt::lang_start::h7ee6163310c37b8b
                               at /build/rust/src/rustc-1.53.0-src/library/std/src/rt.rs:48:5
  33:     0x55cbbac8cc4c - main
  34:     0x7f51f3416b25 - __libc_start_main
  35:     0x55cbba84ce0e - _start
  36:                0x0 - <unknown>                                                                                                                                                                            /0.7s
GladOSkar commented 3 years ago

Looks like net::decode_escaped_unicode() detects an (invalid?) escape sequence and tries to parse it as hex, which then fails because the characters aren't valid hex.

Sounds to me like it either shouldn't be detected as an escape sequence or result in a block_error.

That entire function looks very unsafe though anyways.

@teeratpitakrat do you have an example of the SSID of the wifi network you were connected to at the time? Maybe it happens to contain a backslash? Thanks!

teeratpitakrat commented 3 years ago

The SSID is a Windows path containing some symbols like C:\Program Files(x86)\Custom\Utilities\Tool.exe.

GladOSkar commented 3 years ago

Oh yeah okay the decoder definitely thinks those backslashes are escape sequences. I can probably fix this tomorrow if nobody else wants to

GladOSkar commented 3 years ago

@teeratpitakrat could you try #1274 ? Thanks!

teeratpitakrat commented 3 years ago

@GladOSkar Seems to be fixed. Thanks!