aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-10-22 19:50:43 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-10-23 21:17:55 -0400
commit6383c4d91c7a71492556046c603eea1704ae7b8d (patch)
tree69ad279926d48dc20265cb45c95dfabff5f0fddb
parentMerge pull request #1419 from 4e554c4c/better_logs (diff)
downloadsway-6383c4d91c7a71492556046c603eea1704ae7b8d.tar.gz
sway-6383c4d91c7a71492556046c603eea1704ae7b8d.tar.zst
sway-6383c4d91c7a71492556046c603eea1704ae7b8d.zip
Merge pull request #1424 from ggreer/swaygrab-json
swaygrab: Prevent segfault if IPC response can't be parsed.
-rw-r--r--swaygrab/json.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/swaygrab/json.c b/swaygrab/json.c
index 80dae299..32b68612 100644
--- a/swaygrab/json.c
+++ b/swaygrab/json.c
@@ -4,6 +4,7 @@
4#include <stdbool.h> 4#include <stdbool.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <unistd.h> 6#include <unistd.h>
7#include "log.h"
7#include "ipc-client.h" 8#include "ipc-client.h"
8#include "swaygrab/json.h" 9#include "swaygrab/json.h"
9 10
@@ -12,7 +13,15 @@ static json_object *tree;
12void init_json_tree(int socketfd) { 13void init_json_tree(int socketfd) {
13 uint32_t len = 0; 14 uint32_t len = 0;
14 char *res = ipc_single_command(socketfd, IPC_GET_TREE, NULL, &len); 15 char *res = ipc_single_command(socketfd, IPC_GET_TREE, NULL, &len);
15 tree = json_tokener_parse(res); 16 struct json_tokener *tok = json_tokener_new_ex(256);
17 if (!tok) {
18 sway_abort("Unable to get json tokener.");
19 }
20 tree = json_tokener_parse_ex(tok, res, len);
21 if (!tree || tok->err != json_tokener_success) {
22 sway_abort("Unable to parse IPC response as JSON: %s", json_tokener_error_desc(tok->err));
23 }
24 json_tokener_free(tok);
16} 25}
17 26
18void free_json_tree() { 27void free_json_tree() {