From ed22785909387809a706f56ccc871cb820bf9c03 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 9 Dec 2017 19:50:43 +0200 Subject: [PATCH 1/2] Fix v3 to v4 crash with a variable with longer name than value --- src/config_parser.c | 2 +- testcases/t/183-config-variables.t | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/config_parser.c b/src/config_parser.c index 4e66c911..a27cfc5f 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -1065,7 +1065,7 @@ bool parse_file(const char *f, bool use_nagbar) { int version = detect_version(buf); if (version == 3) { /* We need to convert this v3 configuration */ - char *converted = migrate_config(new, stbuf.st_size); + char *converted = migrate_config(new, strlen(new)); if (converted != NULL) { ELOG("\n"); ELOG("****************************************************************\n"); diff --git a/testcases/t/183-config-variables.t b/testcases/t/183-config-variables.t index 4b225214..d135ed59 100644 --- a/testcases/t/183-config-variables.t +++ b/testcases/t/183-config-variables.t @@ -95,7 +95,19 @@ EOT is(launch_get_border($config), 'none', 'no border'); +##################################################################### +# test that variables with longer name than value don't crash i3 with +# v3 to v4 conversion. +# See: #3076 +##################################################################### +$config = <<'EOT'; +set $var a +EOT + +my $pid = launch_with_config($config); +does_i3_live; +exit_gracefully($pid); done_testing; From 1890517f96da54566bfb3e7273630f5d0f0ac32e Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 9 Dec 2017 19:56:54 +0200 Subject: [PATCH 2/2] migrate_config: scalloc converted config Prevents a false-positive error eg with config file: set $mod Mod4 bindsym $mod+h split h bindsym $mod+v split v ERROR: CONFIG: Expected one of these tokens: , '#', 'set ', ... ERROR: CONFIG: Line 8: status_command i3status ERROR: CONFIG: Line 9: } ERROR: CONFIG: Line 10: --- src/config_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config_parser.c b/src/config_parser.c index a27cfc5f..2d3f3bb9 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -743,7 +743,7 @@ static char *migrate_config(char *input, off_t size) { /* read the script’s output */ int conv_size = 65535; - char *converted = smalloc(conv_size); + char *converted = scalloc(conv_size, 1); int read_bytes = 0, ret; do { if (read_bytes == conv_size) {