From 891c07ea08f051aaeb8b1a96b8b11b8d1a6c494b Mon Sep 17 00:00:00 2001 From: wanghaemq Date: Fri, 14 Apr 2023 15:01:28 +0800 Subject: [PATCH] * ADD [mqtt_quic] Add strdup for the path to tls configuration files. --- include/nng/mqtt/mqtt_quic.h | 1 + src/mqtt/protocol/mqtt/mqtt_quic.c | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/include/nng/mqtt/mqtt_quic.h b/include/nng/mqtt/mqtt_quic.h index d9ad7d7b..346c95de 100644 --- a/include/nng/mqtt/mqtt_quic.h +++ b/include/nng/mqtt/mqtt_quic.h @@ -45,6 +45,7 @@ struct conf_quic { uint8_t qcongestion_control; // congestion control algorithm 1: bbr 0: cubic }; +// It is an interface only for ffi. void conf_quic_tls_create(conf_quic **cqp, char *cafile, char *certfile, char *keyfile, char *key_pwd); diff --git a/src/mqtt/protocol/mqtt/mqtt_quic.c b/src/mqtt/protocol/mqtt/mqtt_quic.c index 22262d39..f8230021 100644 --- a/src/mqtt/protocol/mqtt/mqtt_quic.c +++ b/src/mqtt/protocol/mqtt/mqtt_quic.c @@ -1832,14 +1832,22 @@ nng_mqtt_quic_client_open_conf(nng_socket *sock, const char *url, conf_quic *con return rv; } +/* + * It is an interface only for ffi. + */ void conf_quic_tls_create(conf_quic **cqp, char *cafile, char *certfile, char *keyfile, char *key_pwd) { conf_quic *cq = nng_alloc(sizeof(conf_quic)); + cq->tls.enable = true; - cq->tls.cafile = cafile; - cq->tls.certfile = certfile; - cq->tls.keyfile = keyfile; - cq->tls.key_password = key_pwd; + + // Leak here. But on some ffi. + // The input arguments would be lost when exit current scope. + cq->tls.cafile = strdup(cafile); + cq->tls.certfile = strdup(certfile); + cq->tls.keyfile = strdup(keyfile); + cq->tls.key_password = strdup(key_pwd); + cq->tls.verify_peer = true; cq->multi_stream = false; cq->qos_first = false; @@ -1850,6 +1858,7 @@ void conf_quic_tls_create(conf_quic **cqp, char *cafile, char *certfile, *cqp = cq; } + /** * init an AIO for Acknoledgement message only, in order to make QoS/connect truly asychrounous * For QoS 0 message, we do not care the result of sending