dynsec: Fix listClients/getClient crashing if an anon user present

This only affects the unreleased `develop` branch.
pull/2624/head
Roger A. Light 3 years ago
parent 4997b40259
commit 1d230bd255

@ -915,18 +915,21 @@ static int dynsec__remove_client_from_all_groups(struct dynsec__data *data, cons
static int dynsec__add_client_address(const struct mosquitto *client, void *context_ptr)
{
struct connection_array_context *functor_context = (struct connection_array_context*)context_ptr;
const char *username = mosquitto_client_username(client);
if((username == NULL && functor_context->username == NULL)
|| (username && functor_context->username && !strcmp(functor_context->username, username))){
if(!strcmp(functor_context->username,mosquitto_client_username(client))){
cJSON *j_connection = cJSON_CreateObject();
const char *address;
if(!j_connection){
return MOSQ_ERR_NOMEM;
}
if((address=mosquitto_client_address(client)) && !cJSON_AddStringToObject(j_connection,"address",address)){
if((address = mosquitto_client_address(client)) && !cJSON_AddStringToObject(j_connection, "address", address)){
cJSON_Delete(j_connection);
return MOSQ_ERR_NOMEM;
}
cJSON_AddItemToArray(functor_context->j_connections,j_connection);
cJSON_AddItemToArray(functor_context->j_connections, j_connection);
}
return MOSQ_ERR_SUCCESS;
}

@ -67,6 +67,9 @@ rc = 1
connect_packet = mosq_test.gen_connect("ctrl-test", username="admin", password="admin")
connack_packet = mosq_test.gen_connack(rc=0)
anon_connect_packet = mosq_test.gen_connect("anon-helper")
anon_connack_packet = mosq_test.gen_connack(rc=0)
mid = 2
subscribe_packet = mosq_test.gen_subscribe(mid, "$CONTROL/dynamic-security/#", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
@ -80,6 +83,9 @@ except FileExistsError:
broker = mosq_test.start_broker(filename=os.path.basename(__file__), use_conf=True, port=port)
try:
# The anon user is used to ensure that when the commands are run they are also valid if an anon user is present.
anon_sock = mosq_test.do_client_connect(anon_connect_packet, anon_connack_packet, timeout=5, port=port)
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=5, port=port)
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")
@ -124,6 +130,7 @@ try:
rc = broker_terminate_rc
sock.close()
anon_sock.close()
except mosq_test.TestError:
pass
finally:

Loading…
Cancel
Save