aboutsummaryrefslogtreecommitdiff
path: root/lib/roles
diff options
context:
space:
mode:
authorChunho Lee <chunhole@amazon.com>2021-10-26 17:45:11 -0700
committerAndy Green <andy@warmcat.com>2021-10-27 16:55:12 +0100
commitb843c09dc24a674ec1857e6fdead20693bb0da7a (patch)
tree231a59012f040561c83883cf525776edc39efc5a /lib/roles
parent00b7fa23d059743986ce573a62545ca67a8fb902 (diff)
downloadlibwebsockets-b843c09dc24a674ec1857e6fdead20693bb0da7a.tar.gz
mqtt: allow indicating username and password are not on heap
Fix minimal-mqtt-client and minimal-mqtt-client-multi from crashes by allowing indicating username and password are not on heap.
Diffstat (limited to 'lib/roles')
-rw-r--r--lib/roles/mqtt/client/client-mqtt.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/roles/mqtt/client/client-mqtt.c b/lib/roles/mqtt/client/client-mqtt.c
index 6529fdc9..5324286e 100644
--- a/lib/roles/mqtt/client/client-mqtt.c
+++ b/lib/roles/mqtt/client/client-mqtt.c
@@ -122,6 +122,10 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i,
c->conn_flags = LMQCFT_CLEAN_START;
if (cp->client_id_nofree)
c->conn_flags |= LMQCFT_CLIENT_ID_NOFREE;
+ if (cp->username_nofree)
+ c->conn_flags |= LMQCFT_USERNAME_NOFREE;
+ if (cp->password_nofree)
+ c->conn_flags |= LMQCFT_PASSWORD_NOFREE;
if (!(c->conn_flags & LMQCFT_CLIENT_ID_NOFREE))
lws_free((void *)cp->client_id);
@@ -152,14 +156,16 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i,
if (!c->username)
goto oom3;
c->conn_flags |= LMQCFT_USERNAME;
- lws_free((void *)cp->username);
+ if (!(c->conn_flags & LMQCFT_USERNAME_NOFREE))
+ lws_free((void *)cp->username);
if (cp->password) {
c->password =
lws_mqtt_str_create_cstr_dup(cp->password, 0);
if (!c->password)
goto oom4;
c->conn_flags |= LMQCFT_PASSWORD;
- lws_free((void *)cp->password);
+ if (!(c->conn_flags & LMQCFT_PASSWORD_NOFREE))
+ lws_free((void *)cp->password);
}
}