]> git.sur5r.net Git - i3/i3/commitdiff
Explicitly terminate fallback in set_from_resource. (#2366)
authorIngo Bürk <admin@airblader.de>
Tue, 31 May 2016 20:58:23 +0000 (22:58 +0200)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Tue, 31 May 2016 20:58:23 +0000 (22:58 +0200)
src/config_parser.c

index 5b5e236303626796e4baa2d7287a085ef099e3b5..2a8847300340ea1a5ed44f99d02c9fc05b924cb0 100644 (file)
@@ -954,6 +954,14 @@ bool parse_file(const char *f, bool use_nagbar) {
             char v_key[512];
             char fallback[4096];
 
+            /* Ensure that this string is terminated. For example, a user might
+             * want a variable to be empty if the resource can't be found and
+             * uses
+             *   set_from_resource $foo i3wm.foo
+             * Without explicitly terminating the string first, sscanf() will
+             * leave it uninitialized, causing garbage in the config.*/
+            fallback[0] = '\0';
+
             if (sscanf(value, "%511s %511s %4095[^\n]", v_key, res_name, fallback) < 1) {
                 ELOG("Failed to parse resource specification '%s', skipping it.\n", value);
                 continue;