From 43f137e04794e692e5c21e51fd0b47058b163404 Mon Sep 17 00:00:00 2001 From: gc87 Date: Wed, 11 May 2022 15:43:53 +0800 Subject: [PATCH] fix(mqtt): upload topic str double free Resolves #481 --- include/neuron/connection/mqtt_client_intf.h | 3 --- plugins/mqtt/mqtt.c | 2 +- plugins/mqtt/util.c | 20 -------------------- 3 files changed, 1 insertion(+), 24 deletions(-) diff --git a/include/neuron/connection/mqtt_client_intf.h b/include/neuron/connection/mqtt_client_intf.h index c8d93755..d81259e2 100644 --- a/include/neuron/connection/mqtt_client_intf.h +++ b/include/neuron/connection/mqtt_client_intf.h @@ -33,8 +33,6 @@ typedef struct { int verbose; /* MQTT options */ int MQTT_version; // 3-3_1, 4-3_3_1, 5-5 - char *topic; - char *respons_topic; char *clientid; int qos; int retained; @@ -52,7 +50,6 @@ typedef struct { int will_qos; int will_retain; /* TLS options */ - char *ca_path; char *ca; char *cert; char *key; diff --git a/plugins/mqtt/mqtt.c b/plugins/mqtt/mqtt.c index 21bdc5d2..bc3603c2 100644 --- a/plugins/mqtt/mqtt.c +++ b/plugins/mqtt/mqtt.c @@ -147,7 +147,7 @@ static void topics_generate(vector_t *topics, char *name, char *upload_topic) char *upload_req = NULL; char *upload_res = NULL; if (NULL != upload_topic && 0 < strlen(upload_topic)) { - upload_res = upload_topic; + upload_res = strdup(upload_topic); } else { upload_res = real_topic_generate(TOPIC_UPLOAD_RES, name); } diff --git a/plugins/mqtt/util.c b/plugins/mqtt/util.c index 1f4a7f48..3205b696 100644 --- a/plugins/mqtt/util.c +++ b/plugins/mqtt/util.c @@ -29,11 +29,6 @@ #include #include -#define MQTT_CERT_PATH "config" -#define MQTT_CA_FILE "mqtt_ca.crt" -#define MQTT_CERT_FILE "mqtt_cert.crt" -#define MQTT_KEY_FILE "mqtt_key.key" - void mqtt_option_uninit(neu_mqtt_option_t *option) { if (NULL != option->clientid) { @@ -46,16 +41,6 @@ void mqtt_option_uninit(neu_mqtt_option_t *option) option->upload_topic = NULL; } - if (NULL != option->topic) { - free(option->topic); - option->topic = NULL; - } - - if (NULL != option->respons_topic) { - free(option->respons_topic); - option->respons_topic = NULL; - } - if (NULL != option->connection) { free(option->connection); option->connection = NULL; @@ -81,11 +66,6 @@ void mqtt_option_uninit(neu_mqtt_option_t *option) option->password = NULL; } - if (NULL != option->ca_path) { - free(option->ca_path); - option->ca_path = NULL; - } - if (NULL != option->ca) { free(option->ca); option->ca = NULL;