fix: handle NULL from json_tokener_new_ex

if there is not enough memory to fit json_tokener and (depth *
json_tokener_srec) in RAM, don't segfault.
master
Sefa Eyeoglu 3 years ago committed by Simon Ser
parent 21d2fdf74c
commit 944d7031c5

@ -482,6 +482,10 @@ int main(int argc, char **argv) {
// pretty print the json // pretty print the json
json_tokener *tok = json_tokener_new_ex(INT_MAX); json_tokener *tok = json_tokener_new_ex(INT_MAX);
if (tok == NULL) {
sway_log(SWAY_ERROR, "failed allocating json_tokener");
ret = 1;
} else {
json_object *obj = json_tokener_parse_ex(tok, resp, -1); json_object *obj = json_tokener_parse_ex(tok, resp, -1);
enum json_tokener_error err = json_tokener_get_error(tok); enum json_tokener_error err = json_tokener_get_error(tok);
json_tokener_free(tok); json_tokener_free(tok);
@ -505,6 +509,7 @@ int main(int argc, char **argv) {
} }
json_object_put(obj); json_object_put(obj);
} }
}
free(command); free(command);
free(resp); free(resp);
@ -521,6 +526,11 @@ int main(int argc, char **argv) {
} }
json_tokener *tok = json_tokener_new_ex(INT_MAX); json_tokener *tok = json_tokener_new_ex(INT_MAX);
if (tok == NULL) {
sway_log(SWAY_ERROR, "failed allocating json_tokener");
ret = 1;
break;
}
json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1); json_object *obj = json_tokener_parse_ex(tok, reply->payload, -1);
enum json_tokener_error err = json_tokener_get_error(tok); enum json_tokener_error err = json_tokener_get_error(tok);
json_tokener_free(tok); json_tokener_free(tok);

Loading…
Cancel
Save