diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index d3554560..90b5dfb6 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -97,7 +97,11 @@ int neu_json_decode_write_req(char *buf, neu_json_write_req_t **result) req->group_config_name = req_elems[1].v.val_str; req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags"); - req->tags = calloc(req->n_tag, sizeof(neu_json_write_req_tag_t)); + if (req->n_tag < 0) { + goto decode_fail; + } + + req->tags = calloc(req->n_tag, sizeof(neu_json_write_req_tag_t)); neu_json_write_req_tag_t *p_tag = req->tags; for (int i = 0; i < req->n_tag; i++) { neu_json_elem_t tag_elems[] = { { diff --git a/src/parser/neu_json_tag.c b/src/parser/neu_json_tag.c index 68e2bdb0..b0135632 100644 --- a/src/parser/neu_json_tag.c +++ b/src/parser/neu_json_tag.c @@ -58,7 +58,11 @@ int neu_json_decode_add_tags_req(char *buf, neu_json_add_tags_req_t **result) req->group_config_name = req_elems[1].v.val_str; req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags"); - req->tags = calloc(req->n_tag, sizeof(neu_json_add_tags_req_tag_t)); + if (req->n_tag < 0) { + goto decode_fail; + } + + req->tags = calloc(req->n_tag, sizeof(neu_json_add_tags_req_tag_t)); neu_json_add_tags_req_tag_t *p_tag = req->tags; for (int i = 0; i < req->n_tag; i++) { neu_json_elem_t tag_elems[] = { { @@ -154,7 +158,11 @@ int neu_json_decode_del_tags_req(char *buf, neu_json_del_tags_req_t **result) req->group_config_name = req_elems[1].v.val_str; req->n_id = neu_json_decode_array_size_by_json(json_obj, "ids"); - req->ids = calloc(req->n_id, sizeof(neu_json_del_tags_req_id_t)); + if (req->n_id < 0) { + goto decode_fail; + } + + req->ids = calloc(req->n_id, sizeof(neu_json_del_tags_req_id_t)); neu_json_del_tags_req_id_t *p_id = req->ids; for (int i = 0; i < req->n_id; i++) { neu_json_elem_t id_elems[] = { { @@ -337,7 +345,11 @@ int neu_json_decode_update_tags_req(char * buf, req->group_config_name = req_elems[1].v.val_str; req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags"); - req->tags = calloc(req->n_tag, sizeof(neu_json_update_tags_req_tag_t)); + if (req->n_tag < 0) { + goto decode_fail; + } + + req->tags = calloc(req->n_tag, sizeof(neu_json_update_tags_req_tag_t)); neu_json_update_tags_req_tag_t *p_tag = req->tags; for (int i = 0; i < req->n_tag; i++) { neu_json_elem_t tag_elems[] = { { diff --git a/src/persist/json/persist_json_adapter.c b/src/persist/json/persist_json_adapter.c index a5dc8bb9..5cc8fcc4 100644 --- a/src/persist/json/persist_json_adapter.c +++ b/src/persist/json/persist_json_adapter.c @@ -85,7 +85,11 @@ int neu_json_decode_node_req(char *buf, neu_json_node_req_t **result) json_obj = neu_json_decode_new(buf); req->n_node = neu_json_decode_array_size_by_json(json_obj, "nodes"); - req->nodes = calloc(req->n_node, sizeof(neu_json_node_req_node_t)); + if (req->n_node < 0) { + goto decode_fail; + } + + req->nodes = calloc(req->n_node, sizeof(neu_json_node_req_node_t)); neu_json_node_req_node_t *p_node = req->nodes; for (int i = 0; i < req->n_node; i++) { neu_json_elem_t node_elems[] = { { diff --git a/src/persist/json/persist_json_datatags.c b/src/persist/json/persist_json_datatags.c index 030a6191..8f651162 100644 --- a/src/persist/json/persist_json_datatags.c +++ b/src/persist/json/persist_json_datatags.c @@ -41,7 +41,11 @@ int neu_json_decode_datatag_req(char *buf, neu_json_datatag_req_t **result) json_obj = neu_json_decode_new(buf); req->n_tag = neu_json_decode_array_size_by_json(json_obj, "tags"); - req->tags = calloc(req->n_tag, sizeof(neu_json_datatag_req_tag_t)); + if (req->n_tag < 0) { + goto decode_fail; + } + + req->tags = calloc(req->n_tag, sizeof(neu_json_datatag_req_tag_t)); neu_json_datatag_req_tag_t *p_tag = req->tags; for (int i = 0; i < req->n_tag; i++) { neu_json_elem_t tag_elems[] = { { diff --git a/src/persist/json/persist_json_plugin.c b/src/persist/json/persist_json_plugin.c index 733c95df..7c686ee4 100644 --- a/src/persist/json/persist_json_plugin.c +++ b/src/persist/json/persist_json_plugin.c @@ -41,7 +41,11 @@ int neu_json_decode_plugin_req(char *buf, neu_json_plugin_req_t **result) json_obj = neu_json_decode_new(buf); req->n_plugin = neu_json_decode_array_size_by_json(json_obj, "plugins"); - req->plugins = calloc(req->n_plugin, sizeof(neu_json_plugin_req_plugin_t)); + if (req->n_plugin < 0) { + goto decode_fail; + } + + req->plugins = calloc(req->n_plugin, sizeof(neu_json_plugin_req_plugin_t)); neu_json_plugin_req_plugin_t *p_plugin = req->plugins; for (int i = 0; i < req->n_plugin; i++) { neu_json_elem_t plugin_elems[] = { { diff --git a/src/persist/json/persist_json_subs.c b/src/persist/json/persist_json_subs.c index 2ee2112b..c2f43a74 100644 --- a/src/persist/json/persist_json_subs.c +++ b/src/persist/json/persist_json_subs.c @@ -44,6 +44,10 @@ int neu_json_decode_subscriptions_req(char * buf, req->n_subscription = neu_json_decode_array_size_by_json(json_obj, "subscriptions"); + if (req->n_subscription < 0) { + goto decode_fail; + } + req->subscriptions = calloc( req->n_subscription, sizeof(neu_json_subscriptions_req_subscription_t)); neu_json_subscriptions_req_subscription_t *p_subscription =