mirror of
https://github.com/eclipse-mosquitto/mosquitto.git
synced 2026-09-28 16:14:35 +08:00
dynsec: Fix some keys being accessed even if they don't exist.
This commit is contained in:
@@ -693,7 +693,7 @@ int dynsec_clients__process_modify(cJSON *j_responses, struct mosquitto *context
|
|||||||
return MOSQ_ERR_INVAL;
|
return MOSQ_ERR_INVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "clientid", &clientid, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "clientid", &clientid, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(clientid);
|
str = mosquitto_strdup(clientid);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
||||||
@@ -703,7 +703,7 @@ int dynsec_clients__process_modify(cJSON *j_responses, struct mosquitto *context
|
|||||||
client->clientid = str;
|
client->clientid = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "password", &password, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "password", &password, false) == MOSQ_ERR_SUCCESS){
|
||||||
rc = client__set_password(client, password);
|
rc = client__set_password(client, password);
|
||||||
if(rc != MOSQ_ERR_SUCCESS){
|
if(rc != MOSQ_ERR_SUCCESS){
|
||||||
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
||||||
@@ -712,7 +712,7 @@ int dynsec_clients__process_modify(cJSON *j_responses, struct mosquitto *context
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textname", &text_name, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textname", &text_name, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_name);
|
str = mosquitto_strdup(text_name);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
||||||
@@ -723,7 +723,7 @@ int dynsec_clients__process_modify(cJSON *j_responses, struct mosquitto *context
|
|||||||
client->text_name = str;
|
client->text_name = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textdescription", &text_description, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textdescription", &text_description, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_description);
|
str = mosquitto_strdup(text_description);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyClient", "Internal error", correlation_data);
|
||||||
|
|||||||
@@ -273,7 +273,7 @@ int dynsec_groups__config_load(cJSON *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Text name */
|
/* Text name */
|
||||||
if(json_get_string(j_group, "textname", &str, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(j_group, "textname", &str, false) == MOSQ_ERR_SUCCESS){
|
||||||
if(str){
|
if(str){
|
||||||
group->text_name = strdup(str);
|
group->text_name = strdup(str);
|
||||||
if(group->text_name == NULL){
|
if(group->text_name == NULL){
|
||||||
@@ -286,7 +286,7 @@ int dynsec_groups__config_load(cJSON *tree)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Text description */
|
/* Text description */
|
||||||
if(json_get_string(j_group, "textdescription", &str, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(j_group, "textdescription", &str, false) == MOSQ_ERR_SUCCESS){
|
||||||
if(str){
|
if(str){
|
||||||
group->text_description = strdup(str);
|
group->text_description = strdup(str);
|
||||||
if(group->text_description == NULL){
|
if(group->text_description == NULL){
|
||||||
@@ -992,7 +992,7 @@ int dynsec_groups__process_modify(cJSON *j_responses, struct mosquitto *context,
|
|||||||
return MOSQ_ERR_INVAL;
|
return MOSQ_ERR_INVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textname", &text_name, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textname", &text_name, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_name);
|
str = mosquitto_strdup(text_name);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyGroup", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyGroup", "Internal error", correlation_data);
|
||||||
@@ -1002,7 +1002,7 @@ int dynsec_groups__process_modify(cJSON *j_responses, struct mosquitto *context,
|
|||||||
group->text_name = str;
|
group->text_name = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textdescription", &text_description, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textdescription", &text_description, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_description);
|
str = mosquitto_strdup(text_description);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyGroup", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyGroup", "Internal error", correlation_data);
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ Contributors:
|
|||||||
#include <cJSON.h>
|
#include <cJSON.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
/* "optional==false" can also be taken to mean "only return success if the key exists and is valid" */
|
||||||
int json_get_bool(cJSON *json, const char *name, bool *value, bool optional, bool default_value);
|
int json_get_bool(cJSON *json, const char *name, bool *value, bool optional, bool default_value);
|
||||||
int json_get_int(cJSON *json, const char *name, int *value, bool optional, int default_value);
|
int json_get_int(cJSON *json, const char *name, int *value, bool optional, int default_value);
|
||||||
int json_get_string(cJSON *json, const char *name, char **value, bool optional);
|
int json_get_string(cJSON *json, const char *name, char **value, bool optional);
|
||||||
|
|||||||
@@ -1086,7 +1086,7 @@ int dynsec_roles__process_modify(cJSON *j_responses, struct mosquitto *context,
|
|||||||
return MOSQ_ERR_INVAL;
|
return MOSQ_ERR_INVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textname", &text_name, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textname", &text_name, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_name);
|
str = mosquitto_strdup(text_name);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyRole", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyRole", "Internal error", correlation_data);
|
||||||
@@ -1096,7 +1096,7 @@ int dynsec_roles__process_modify(cJSON *j_responses, struct mosquitto *context,
|
|||||||
role->text_name = str;
|
role->text_name = str;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json_get_string(command, "textdescription", &text_description, true) == MOSQ_ERR_SUCCESS){
|
if(json_get_string(command, "textdescription", &text_description, false) == MOSQ_ERR_SUCCESS){
|
||||||
str = mosquitto_strdup(text_description);
|
str = mosquitto_strdup(text_description);
|
||||||
if(str == NULL){
|
if(str == NULL){
|
||||||
dynsec__command_reply(j_responses, context, "modifyRole", "Internal error", correlation_data);
|
dynsec__command_reply(j_responses, context, "modifyRole", "Internal error", correlation_data);
|
||||||
|
|||||||
Reference in New Issue
Block a user