diff options
author | Sefa Eyeoglu <contact@scrumplex.net> | 2021-10-21 18:22:50 +0200 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2021-10-22 09:57:05 +0200 |
commit | 96baef8ae9955dd7ffd85c6b769a14df1f95bc97 (patch) | |
tree | 5e6af92bb5d149c5e5f1141d79a9b7a25bcb2673 /swaymsg | |
parent | 944d7031c5a1ffebb105fb1fed3f957903abe8da (diff) |
fix: use sane value for json_tokener max_depth
INT_MAX causes a NULL pointer if there is not enough memory available to
fit (INT_MAX * sizeof(struct json_tokener_srec)).
Diffstat (limited to 'swaymsg')
-rw-r--r-- | swaymsg/main.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/swaymsg/main.c b/swaymsg/main.c index 3698294a..dcf42cb6 100644 --- a/swaymsg/main.c +++ b/swaymsg/main.c @@ -1,4 +1,8 @@ #define _POSIX_C_SOURCE 200809L + +// arbitrary number, it's probably sufficient, higher number = more memory usage +#define JSON_MAX_DEPTH 512 + #include <limits.h> #include <stdio.h> #include <stdlib.h> @@ -481,7 +485,7 @@ int main(int argc, char **argv) { char *resp = ipc_single_command(socketfd, type, command, &len); // pretty print the json - json_tokener *tok = json_tokener_new_ex(INT_MAX); + json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); if (tok == NULL) { sway_log(SWAY_ERROR, "failed allocating json_tokener"); ret = 1; @@ -525,7 +529,7 @@ int main(int argc, char **argv) { break; } - json_tokener *tok = json_tokener_new_ex(INT_MAX); + json_tokener *tok = json_tokener_new_ex(JSON_MAX_DEPTH); if (tok == NULL) { sway_log(SWAY_ERROR, "failed allocating json_tokener"); ret = 1; |