Skip to content

Commit

Permalink
* FIX [tcp&tls] Fix the double free on property in connect msg.
Browse files Browse the repository at this point in the history
Signed-off-by: wanghaemq <[email protected]>
  • Loading branch information
wanghaEMQ authored and JaylinYu committed Jul 30, 2024
1 parent 78c4de6 commit bea103e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
20 changes: 8 additions & 12 deletions src/mqtt/transport/tcp/mqtt_tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,12 @@ mqtt_tcptran_pipe_start(
rv = nni_mqtt_msg_encode(connmsg);
else if (mqtt_version == MQTT_PROTOCOL_VERSION_v5) {
property *prop = nni_mqtt_msg_get_connect_property(connmsg);
property_data *data;
data = property_get_value(prop, MAXIMUM_PACKET_SIZE);
if (data)
p->rcvmax = data->p_value.u32;

#ifdef SUPP_SCRAM
if (prop == NULL)
prop = mqtt_property_alloc();
char *pwd = NULL, *username = NULL;
char *pwd2 = NULL, *username2 = NULL;
int pwdsz, usernamesz;
Expand All @@ -1115,27 +1118,20 @@ mqtt_tcptran_pipe_start(
char *client_first_msg = scram_client_first_msg(ep->scram_ctx, username2);
property *prop_auth_data = property_set_value_str(
AUTHENTICATION_DATA, client_first_msg, strlen(client_first_msg), true);
if (prop == NULL)
prop = mqtt_property_alloc();
property_append(prop, prop_auth_method);
property_append(prop, prop_auth_data);
nni_mqtt_msg_set_connect_property(connmsg, prop);
prop = NULL;
log_info("auth:client_first_msg:%s", client_first_msg);
log_debug("auth:client_first_msg:%s", client_first_msg);
//property_free(prop_auth_method);
//property_free(prop_auth_data);
}
if (pwd2)
nng_free(pwd2, 0);
if (username2)
nng_free(username2, 0);
if (prop) {
mqtt_property_free(prop);
prop = NULL;
}
#endif
property_data *data;
data = property_get_value(prop, MAXIMUM_PACKET_SIZE);
if (data)
p->rcvmax = data->p_value.u32;
rv = nni_mqttv5_msg_encode(connmsg);
} else {
nni_plat_printf("Warning. MQTT protocol version is not specificed.\n");
Expand Down
18 changes: 7 additions & 11 deletions src/mqtt/transport/tls/mqtt_tls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1042,9 +1042,12 @@ mqtts_tcptran_pipe_start(
rv = nni_mqtt_msg_encode(connmsg);
else if (mqtt_version == MQTT_PROTOCOL_VERSION_v5) {
property *prop = nni_mqtt_msg_get_connect_property(connmsg);
property_data *data;
data = property_get_value(prop, MAXIMUM_PACKET_SIZE);
if (data)
p->rcvmax = data->p_value.u32;

#ifdef SUPP_SCRAM
if (prop == NULL)
prop = mqtt_property_alloc();
char *pwd = NULL, *username = NULL;
char *pwd2 = NULL, *username2 = NULL;
int pwdsz, usernamesz;
Expand All @@ -1068,10 +1071,11 @@ mqtts_tcptran_pipe_start(
char *client_first_msg = scram_client_first_msg(ep->scram_ctx, username2);
property *prop_auth_data = property_set_value_str(
AUTHENTICATION_DATA, client_first_msg, strlen(client_first_msg), true);
if (prop == NULL)
prop = mqtt_property_alloc();
property_append(prop, prop_auth_method);
property_append(prop, prop_auth_data);
nni_mqtt_msg_set_connect_property(connmsg, prop);
prop = NULL;
log_debug("auth:client_first_msg:%s\n", client_first_msg);
//property_free(prop_auth_method);
//property_free(prop_auth_data);
Expand All @@ -1080,15 +1084,7 @@ mqtts_tcptran_pipe_start(
nng_free(pwd2, 0);
if (username2)
nng_free(username2, 0);
if (prop) {
mqtt_property_free(prop);
prop = NULL;
}
#endif
property_data *data;
data = property_get_value(prop, MAXIMUM_PACKET_SIZE);
if (data)
p->rcvmax = data->p_value.u32;
rv = nni_mqttv5_msg_encode(connmsg);
} else {
nni_plat_printf("Warning. MQTT protocol version is not specificed.\n");
Expand Down

0 comments on commit bea103e

Please sign in to comment.