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.
This commit is contained in:
Orestis Floros 2018-09-06 14:54:27 +03:00
parent e8d2b9b7b5
commit be6faa3161
No known key found for this signature in database
GPG Key ID: E9AD9F32E401E38F
1 changed files with 4 additions and 0 deletions

View File

@ -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); yajl_config(hand, yajl_allow_comments, true);
/* Allow multiple values, i.e. multiple nodes to attach */ /* Allow multiple values, i.e. multiple nodes to attach */
yajl_config(hand, yajl_allow_multiple_values, true); 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; json_node = con;
to_focus = NULL; to_focus = NULL;
incomplete = 0; incomplete = 0;