mirror of
https://github.com/emqx/neuron.git
synced 2026-10-22 17:50:36 +08:00
Merge pull request #1568 from eeff/eeff/fix
fix: guard against empty mqtt subscription topic
This commit is contained in:
@@ -95,3 +95,5 @@ ${NEU_ERR_PLUGIN_NOT_FOUND} 3014
|
||||
${NEU_ERR_PLUGIN_DEVICE_NOT_RESPONSE} 3015
|
||||
${NEU_ERR_PLUGIN_NOT_SUPPORT_TEMPLATE} 3016
|
||||
${NEU_ERR_PLUGIN_NOT_SUPPORT_WRITE_TAGS} 3017
|
||||
|
||||
${NEU_ERR_MQTT_SUBSCRIBE_FAILURE} 4010
|
||||
|
||||
@@ -45,6 +45,14 @@ North APP subscribe multiple nonexistent groups, it should fail.
|
||||
Check Response Status ${res} 404
|
||||
Check Error Code ${res} ${NEU_ERR_GROUP_NOT_EXIST}
|
||||
|
||||
North MQTT APP subscribe with empty topic, it should fail.
|
||||
${g1} = Evaluate {"driver": "modbus-node", "group": "group1", "params":{"topic":""}}
|
||||
|
||||
${res}= Subscribe Groups mqtt ${g1}
|
||||
|
||||
Check Response Status ${res} 200
|
||||
Check Error Code ${res} ${NEU_ERR_MQTT_SUBSCRIBE_FAILURE}
|
||||
|
||||
North APP subscribe multiple groups, it should return success
|
||||
Add Group modbus-node group1 1000
|
||||
Add Group modbus-node group2 1000
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "utils/log.h"
|
||||
#include "json/neu_json_param.h"
|
||||
|
||||
#include "adapter.h"
|
||||
#include "errcodes.h"
|
||||
@@ -695,6 +696,19 @@ int neu_manager_subscribe(neu_manager_t *manager, const char *app,
|
||||
return NEU_ERR_NODE_NOT_EXIST;
|
||||
}
|
||||
|
||||
// guard against empty mqtt topic parameter
|
||||
// this is not an elegant solution due to the current architecture
|
||||
if (params && 0 == strcmp(adapter->module->module_name, "MQTT")) {
|
||||
neu_json_elem_t elem = { .name = "topic", .t = NEU_JSON_STR };
|
||||
neu_json_decode((char *) params, 1, &elem);
|
||||
neu_parse_param(params, NULL, 1, &elem);
|
||||
if (elem.v.val_str && 0 == strlen(elem.v.val_str)) {
|
||||
free(elem.v.val_str);
|
||||
return NEU_ERR_MQTT_SUBSCRIBE_FAILURE;
|
||||
}
|
||||
free(elem.v.val_str);
|
||||
}
|
||||
|
||||
if (NEU_NA_TYPE_APP != neu_adapter_get_type(adapter)) {
|
||||
return NEU_ERR_NODE_NOT_ALLOW_SUBSCRIBE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user