swaywm/swayidle

Couple of issues when parsing the config file

apiraino opened this issue · 2 comments

Running swayidle 04a176e

Exhibit # 1: Config file without empty newline segfaults

$ cat -p swayidle/.config/swayidle/config
timeout 3 'swaylock'
before-sleep 'swaylock'
$ swayidle 
Segmentation fault (core dumped)

With an empty newline no problems

$ cat -p swayidle/.config/swayidle/config
timeout 3 'swaylock'
before-sleep 'swaylock'

$ swayidle 
Failed to find session

Exhibit # 2: Command without quotes is not correctly parsed

$ cat -p swayidle/.config/swayidle/config
timeout 3 'swaylock'
timeout 6 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'
before-sleep swaylock

$ swayidle -d
...
Command: swayloc
Setup sleep lock: swayloc
...

With quotes or a random char (in the example a dash -) fixes

$ cat -p swayidle/.config/swayidle/config
timeout 3 'swaylock'
timeout 6 'swaymsg "output * dpms off"' resume 'swaymsg "output * dpms on"'
before-sleep swaylock-

$ swayidle -d
...
Command: swaylock
Setup sleep lock: swaylock
...

Exhibit # 3: Misc

  • before-sleep directive without quotes refused
  • UTF-8 is not supported (minor issue, just for completeness)
    timeout 3 'swaylock🐶🔥' => Command: swaylock🐶�

Thank you for the report!
Exibit 1 is explained by

swayidle/main.c

Line 930 in aa11c41

line[nread-1] = '\0';

which assumes that the line ends with an newline. I'll send a patch when I am I'm range of my laptop again.

Exibit 2 seems related to exhibit 1. In fact it should not have anything to do with quotes but with the last char being replaced by \0 .

I'll investigate in the next days.

As for Unicode support I think the problem is that the file is read as chars and thus multibyte utf8 encoded symbols will get split up and not properly printed. It should not have any effect on the commands executed.