From e8d2b9b7b53b12f81d019b856c54ed2225ec820c Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Thu, 6 Sep 2018 14:48:21 +0300 Subject: [PATCH 1/2] tree_append_json: don't focus freed container --- src/load_layout.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/load_layout.c b/src/load_layout.c index add78875..5f391ad7 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -632,6 +632,9 @@ void tree_append_json(Con *con, const char *buf, const size_t len, char **errorm while (incomplete-- > 0) { Con *parent = json_node->parent; DLOG("freeing incomplete container %p\n", json_node); + if (json_node == to_focus) { + to_focus = NULL; + } con_free(json_node); json_node = parent; } From be6faa31617e3da2fc5c4af43821e9d76dc6d5ac Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Thu, 6 Sep 2018 14:54:27 +0300 Subject: [PATCH 2/2] tree_append_json: Allow strings that are not valid UTF8 Fixes #3156. I couldn't reproduce the problem in a "natural" way so I cheated: 1. Start i3 with gdb 2. Set breakpoing on tree_restore 3. Run, open window, i3-msg restart 5. Open the file in *path with a hex editor 6. Edit the "name" field of the window and insert bytes that are not valid UTF8 7. Continue After parsing fails, all nodes including croot are incomplete, meaning they have to be deleted. We can't recover in any reasonable way so we have to allow non-UTF8 characters to avoid this situation altogether. --- src/load_layout.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/load_layout.c b/src/load_layout.c index 5f391ad7..d2ad4e87 100644 --- a/src/load_layout.c +++ b/src/load_layout.c @@ -611,6 +611,10 @@ void tree_append_json(Con *con, const char *buf, const size_t len, char **errorm yajl_config(hand, yajl_allow_comments, true); /* Allow multiple values, i.e. multiple nodes to attach */ yajl_config(hand, yajl_allow_multiple_values, true); + /* Allow strings that are not valid UTF8. Could be possible if a container + * name contains such characters. If yajl stops parsing because of this, an + * in-place restart could fail: see #3156. */ + yajl_config(hand, yajl_dont_validate_strings, true); json_node = con; to_focus = NULL; incomplete = 0;