i3: Incorrect error handling on 'set' and 'set_from_resource' config statements

Output of i3 --moreversion 2>&- || i3 --version:

Binary i3 version:  4.12 (2016-03-06, branch "4.12") © 2009 Michael Stapelberg and contributors
Running i3 version: 4.12-76-g3ffa88e (2016-06-25, branch "next") (pid 24623)
Loaded i3 config: /home/leaf/.i3/config (Last modified: Thu 30 Jun 2016 10:24:23 AM PDT, 283 seconds ago)

The i3 binary you just called: /usr/bin/i3
The i3 binary you are running: /home/leaf/Programming/i3/i3

URL to a logfile as per http://i3wm.org/docs/debugging.html:

http://logs.i3wm.org/logs/5697124062724096.bz2

What I did:

I placed the following lines inside of my configuration file:

set $foo
set $
set_from_resource $bar
set_from_resource
bindsym Mod4+1 exec echo $foo >> /home/leaf/i3vartest
bindsym Mod4+2 exec echo $bar >> /home/leaf/i3vartest

Then I started i3 with that configuration file, and pressed Mod4+1, then Mod4+2

What I saw:

% cat i3vartest 
8: Slack

%

(note: “8: Slack” is the value of the last variable defined before $foo)

% ./i3 -C -c ~/.i3/config
% 

What I expected instead:

I was able to fix it by changing the scr/config_parser.c lines:

        if (strcasecmp(key, "set") == 0) {
            char v_key[512];
            char v_value[4096];

            if (sscanf(value, "%511s %4095[^\n]", v_key, v_value) < 1) {
                ELOG("Failed to parse variable specification '%s', skipping it.\n", value);
                continue;
            }

to:

        if (strcasecmp(key, "set") == 0) {
            char v_key[512];
            char v_value[4096];

            if (sscanf(value, "%511s %4095[^\n]", v_key, v_value) < 2) {
                ELOG("Failed to parse variable specification '%s', skipping it.\n", value);
                continue;
            }

and the same for set_from_resource, but with 3 as the desired sscanf return value.

This gave me the output:

% ./i3 -C -c ~/.i3/config
06/30/2016 10:48:35 AM - ERROR: Failed to parse variable specification '$foo', skipping it.
06/30/2016 10:48:35 AM - ERROR: Failed to parse variable specification '$', skipping it.
06/30/2016 10:48:35 AM - ERROR: Failed to parse resource specification '$bar', skipping it.
06/30/2016 10:48:35 AM - ERROR: Failed to parse resource specification '$bar', skipping it.

Considerations: While all of those set/set_from_resource attempts threw errors, they weren’t necessarily correct, the 4th on was not called ‘$bar’, but sscanf did not overwrite the string holding the variable’s key, it used the one from the previous line. While it still fails, it could be a better described error. Additionally, simply checking the number of arguments to set/set_from_resource, and verifying that the first one starts with ‘$’ allows a user to have a variable whose key is literally ‘$’. Because of my commit #2306 , this is actually harmless, and works fine, but is it desired??

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 15 (13 by maintainers)

Most upvoted comments

We don’t have versioned userguides on the website.

Actually, we do: https://i3wm.org/docs/4.12/userguide.html

I agree that we could do a better job at documenting what features went in at which version, and which version a userguide is documenting. Pull requests welcome.