diff options
author | William McKinnon <[email protected]> | 2022-04-26 21:44:51 -0400 |
---|---|---|
committer | GitHub <[email protected]> | 2022-04-26 21:44:51 -0400 |
commit | 4660771f6a25b93062df0698634059f893ae1999 (patch) | |
tree | b7135d20119a42d8381fb65004f476750d6212fd /swaymsg | |
parent | ccda4dae0f9b77b9760d6fdf178e0f0e2571cde0 (diff) | |
parent | 5543acff06981639086bc9a0fc9b608796a23e84 (diff) |
Merge pull request #1 from swaywm/v1.7
V1.7
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 574d3b75..0d9dc5a0 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -1,4 +1,6 @@ #define _POSIX_C_SOURCE 200809L + +#include <limits.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -480,12 +482,20 @@ int main(int argc, char **argv) { char *resp = ipc_single_command(socketfd, type, command, &len); // pretty print the json - json_object *obj = json_tokener_parse(resp); - if (obj == NULL) { + json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); + if (tok == NULL) { + if (quiet) { + exit(EXIT_FAILURE); + } + sway_abort("failed allocating json_tokener"); + } + json_object *obj = json_tokener_parse_ex(tok, resp, -1); + enum json_tokener_error err = json_tokener_get_error(tok); + json_tokener_free(tok); + if (obj == NULL || err != json_tokener_success) { if (!quiet) { - fprintf(stderr, "ERROR: Could not parse json response from ipc. " - "This is a bug in sway."); - printf("%s\n", resp); + sway_log(SWAY_ERROR, "failed to parse payload as json: %s", + json_tokener_error_desc(err)); } ret = 1; } else { @@ -517,13 +527,22 @@ int main(int argc, char **argv) { break; } - json_object *obj = json_tokener_parse(reply->payload); - if (obj == NULL) { + json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); + if (tok == NULL) { + if (quiet) { + exit(EXIT_FAILURE); + } + sway_abort("failed allocating json_tokener"); + } + json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); + enum json_tokener_error err = json_tokener_get_error(tok); + json_tokener_free(tok); + if (obj == NULL || err != json_tokener_success) { if (!quiet) { - fprintf(stderr, "ERROR: Could not parse json response from" - " ipc. This is a bug in sway."); - ret = 1; + sway_log(SWAY_ERROR, "failed to parse payload as json: %s", + json_tokener_error_desc(err)); } + ret = 1; break; } else if (quiet) { json_object_put(obj); |