aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-10-22 19:50:43 -0400
committerDrew DeVault <sir@cmpwn.com>2017-10-23 21:17:55 -0400
commit6383c4d91c7a71492556046c603eea1704ae7b8d (patch)
tree69ad279926d48dc20265cb45c95dfabff5f0fddb
parent0f7e84c11060d5d4388c60a990fdc4cbb839dc70 (diff)
downloadsway-6383c4d91c7a71492556046c603eea1704ae7b8d.zip
sway-6383c4d91c7a71492556046c603eea1704ae7b8d.tar.gz
sway-6383c4d91c7a71492556046c603eea1704ae7b8d.tar.bz2
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 80dae29..32b6861 100644
--- a/swaygrab/json.c
+++ b/swaygrab/json.c
@@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
+#include "log.h"
#include "ipc-client.h"
#include "swaygrab/json.h"
@@ -12,7 +13,15 @@ static json_object *tree;
void init_json_tree(int socketfd) {
uint32_t len = 0;
char *res = ipc_single_command(socketfd, IPC_GET_TREE, NULL, &len);
- tree = json_tokener_parse(res);
+ struct json_tokener *tok = json_tokener_new_ex(256);
+ if (!tok) {
+ sway_abort("Unable to get json tokener.");
+ }
+ tree = json_tokener_parse_ex(tok, res, len);
+ if (!tree || tok->err != json_tokener_success) {
+ sway_abort("Unable to parse IPC response as JSON: %s", json_tokener_error_desc(tok->err));
+ }
+ json_tokener_free(tok);
}
void free_json_tree() {