Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index out of bounds #222

Open
tsankuanglee opened this issue Aug 24, 2023 · 1 comment
Open

index out of bounds #222

tsankuanglee opened this issue Aug 24, 2023 · 1 comment
Assignees

Comments

@tsankuanglee
Copy link
Contributor

Version Information

  • Distribution Information ( run uname -a ): Linux hostname 6.4.11-arch2-1 #1 SMP PREEMPT_DYNAMIC Sat, 19 Aug 2023 15:38:34 +0000 x86_64 GNU/Linux
  • swhkd version ( swhkd -V ): 1.2.1

Describe the bug

In the process of trying to do #219 , I accidentally found that a wrong config could cause index out of bounds.

Expected behavior

Even though the config is wrong, we expect swhkd to catch it and quit gracefully.

Actual behavior

See log:

[2023-08-24T07:24:51Z TRACE swhks] Setting process umask.
[2023-08-24T07:24:51Z INFO  swhks] XDG_RUNTIME_DIR Variable is present, using it's value as default file path.
[2023-08-24T07:24:51Z TRACE swhks] Reading /run/user/1000/swhks.pid file and checking for running instances.
[2023-08-24T07:24:51Z DEBUG swhks] Previous PID: 191474
[2023-08-24T07:24:51Z TRACE swhkd] Logger initialized.
[2023-08-24T07:24:51Z TRACE swhkd] Invoking UID: 1000
[2023-08-24T07:24:51Z TRACE swhkd] Setting process umask.
[2023-08-24T07:24:51Z ERROR swhkd] XDG_RUNTIME_DIR has not been set.
[2023-08-24T07:24:51Z TRACE swhkd] Reading /run/swhkd/swhkd_1000.pid file and checking for running instances.
[2023-08-24T07:24:51Z DEBUG swhkd] Previous PID: 191496
[2023-08-24T07:24:52Z TRACE swhks] Sockfile exists, attempting to remove it.
[2023-08-24T07:24:52Z DEBUG swhks] Removed old socket file
[2023-08-24T07:24:52Z WARN  swhkd] Running swhkd as root!
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting initgroups...
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting EGID...
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting EUID...
[2023-08-24T07:24:52Z DEBUG swhkd] Using config file path: "/home/user/.config/swhkd/swhkdrc.test.conf"
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting EGID...
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting EUID...
[2023-08-24T07:24:52Z DEBUG swhkd::perms] Setting initgroups...
[2023-08-24T07:24:52Z TRACE swhkd] Attempting to find all keyboard file descriptors.
[2023-08-24T07:24:52Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:52Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] Keyboard: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z TRACE swhkd] Other: <REDACTED>
[2023-08-24T07:24:53Z DEBUG swhkd] 6 Keyboard device(s) detected.
[2023-08-24T07:24:53Z ERROR swhkd] XDG_RUNTIME_DIR has not been set.
[2023-08-24T07:25:02Z DEBUG swhkd] state_modifiers: {
        Super,
        Control,
        Shift,
        Alt,
    }
[2023-08-24T07:25:02Z DEBUG swhkd] state_keysyms: {}
[2023-08-24T07:25:02Z DEBUG swhkd] hotkey: [
        Hotkey {
            keybinding: KeyBinding {
                keysym: KEY_E,
                modifiers: [
                    Alt,
                    Control,
                    Shift,
                    Super,
                ],
                send: false,
                on_release: false,
            },
            command: "@escape && touch /tmp/test && @enter hello && @enter hello2",
        },
    ]
[2023-08-24T07:25:02Z DEBUG swhkd] state_modifiers: {
        Super,
        Control,
        Shift,
        Alt,
    }
[2023-08-24T07:25:02Z DEBUG swhkd] state_keysyms: {
        KEY_E,
    }
[2023-08-24T07:25:02Z DEBUG swhkd] hotkey: [
        Hotkey {
            keybinding: KeyBinding {
                keysym: KEY_E,
                modifiers: [
                    Alt,
                    Control,
                    Shift,
                    Super,
                ],
                send: false,
                on_release: false,
            },
            command: "@escape && touch /tmp/test && @enter hello && @enter hello2",
        },
    ]
[2023-08-24T07:25:02Z INFO  swhkd] Hotkey pressed: Hotkey {
        keybinding: KeyBinding {
            keysym: KEY_E,
            modifiers: [
                Alt,
                Control,
                Shift,
                Super,
            ],
            send: false,
            on_release: false,
        },
        command: "@escape && touch /tmp/test && @enter hello && @enter hello2",
    }
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551615', swhkd/src/daemon.rs:356:25
stack backtrace:
   0:     0x560f08029be7 - <unknown>
   1:     0x560f07f98f7c - <unknown>
   2:     0x560f080088f4 - <unknown>
   3:     0x560f0802aa76 - <unknown>
   4:     0x560f0802bae3 - <unknown>
   5:     0x560f0802b5a2 - <unknown>
   6:     0x560f0802b516 - <unknown>
   7:     0x560f0802b4d2 - <unknown>
   8:     0x560f07f0a512 - <unknown>
   9:     0x560f07f0a591 - <unknown>
  10:     0x560f07f43291 - <unknown>
  11:     0x560f07f2ea60 - <unknown>
  12:     0x560f07f18993 - <unknown>
  13:     0x560f07f43db0 - <unknown>
  14:     0x7f6745a27cd0 - <unknown>
  15:     0x7f6745a27d8a - __libc_start_main
  16:     0x560f07f17485 - <unknown>
  17:                0x0 - <unknown>
/home/user/.config/systemd/user/swhkd_wrapper.sh: line 3: 191722 Aborted                 (core dumped) RUST_BACKTRACE=full swhkd --config /home/user/.config/swhkd/swhkdrc.test.conf --debug

To Reproduce

/home/user/.config/swhkd/swhkdrc.test.conf

alt + ctrl + shift + super + e
    @escape && touch /tmp/test && @enter hello && @enter hello2
mode hello1 swallow
1
    @escape && touch /tmp/hello1
endmode
mode hello2 swallow
2
    @escape && touch /tmp/hello2
endmode

startup script

#!/usr/bin/env bash

killall swhks
sudo pkill -9 swhkd
swhks & pkexec env RUST_BACKTRACE=full swhkd --config /home/user/.config/swhkd/swhkdrc.test.conf --debug

keys pressed

alt+ctrl+shift+super+e
The error occurred as soon as these keys are down.

@tsankuanglee
Copy link
Contributor Author

tsankuanglee commented Aug 24, 2023

This one is less strange, but it creates a similar error as well:

alt + ctrl + shift + super + e
    @escape && touch /tmp/test && @enter screenshot

mode screenshot swallow
5
    @escape && touch /tmp/test.5
endmode

error:

thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 18446744073709551615', swhkd/src/daemon.rs:318:68

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants