From 55d0aa00019e2a38b05a2b048ef4e2148068dfe9 Mon Sep 17 00:00:00 2001 From: fengzero Date: Sat, 2 Apr 2022 08:44:46 +0000 Subject: [PATCH] fix write tag crash --- plugins/mqtt/command/read_write.c | 4 ++++ plugins/restful/rw_handle.c | 10 ++++++++-- src/parser/neu_json_fn.c | 7 ++++++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/mqtt/command/read_write.c b/plugins/mqtt/command/read_write.c index 45eb4d5a..424ef22e 100644 --- a/plugins/mqtt/command/read_write.c +++ b/plugins/mqtt/command/read_write.c @@ -336,6 +336,10 @@ int command_rw_write_request(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt, neu_datatag_t * tag = neu_datatag_tbl_get_by_name(table, write_req->tag_name); + if (tag == NULL) { + return -1; + } + neu_datatag_id_t id = tag->id; switch (tag->type) { diff --git a/plugins/restful/rw_handle.c b/plugins/restful/rw_handle.c index 20e70e5e..33602de5 100644 --- a/plugins/restful/rw_handle.c +++ b/plugins/restful/rw_handle.c @@ -198,8 +198,14 @@ void handle_write(nng_aio *aio) neu_datatag_table_t *table = neu_system_get_datatags_table(plugin, node_id); - neu_data_val_t *data = neu_parse_write_req_to_val(req, table); - uint32_t event_id = neu_plugin_get_event_id(plugin); + neu_data_val_t *data = neu_parse_write_req_to_val(req, table); + if (data == NULL) { + NEU_JSON_RESPONSE_ERROR(NEU_ERR_TAG_NOT_EXIST, { + http_response(aio, NEU_ERR_TAG_NOT_EXIST, result_error); + }) + return; + } + uint32_t event_id = neu_plugin_get_event_id(plugin); write_add_ctx(event_id, aio); neu_plugin_send_write_cmd(plugin, event_id, node_id, config, data); }) diff --git a/src/parser/neu_json_fn.c b/src/parser/neu_json_fn.c index ae65703e..9dd2353c 100644 --- a/src/parser/neu_json_fn.c +++ b/src/parser/neu_json_fn.c @@ -178,12 +178,17 @@ int neu_parse_param(char *buf, char **err_param, int n, neu_json_elem_t *ele, neu_data_val_t *neu_parse_write_req_to_val(neu_json_write_req_t *req, neu_datatag_table_t * tbl) { + neu_datatag_t *tag = neu_datatag_tbl_get_by_name(tbl, req->tag_name); + + if (tag == NULL) { + return NULL; + } + neu_data_val_t * val = neu_dvalue_unit_new(); neu_fixed_array_t *array = neu_fixed_array_new(1, sizeof(neu_int_val_t)); neu_int_val_t iv; neu_data_val_t *v; - neu_datatag_t * tag = neu_datatag_tbl_get_by_name(tbl, req->tag_name); switch (tag->type) { case NEU_DTYPE_UINT8: