mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-30 00:00:16 +01:00
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.
This commit is contained in:
parent
41c88959d2
commit
8e4336838a
4 changed files with 23 additions and 3 deletions
|
@ -74,6 +74,10 @@ typedef struct lws_mqtt_client_connect_param_s {
|
||||||
session */
|
session */
|
||||||
uint8_t client_id_nofree:1;
|
uint8_t client_id_nofree:1;
|
||||||
/**< do not free the client id */
|
/**< do not free the client id */
|
||||||
|
uint8_t username_nofree:1;
|
||||||
|
/**< do not free the username */
|
||||||
|
uint8_t password_nofree:1;
|
||||||
|
/**< do not free the password */
|
||||||
struct {
|
struct {
|
||||||
const char *topic;
|
const char *topic;
|
||||||
const char *message;
|
const char *message;
|
||||||
|
@ -152,6 +156,8 @@ typedef enum {
|
||||||
|
|
||||||
/* flags from byte 8 of C_TO_S CONNECT */
|
/* flags from byte 8 of C_TO_S CONNECT */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
LMQCFT_USERNAME_NOFREE = (1 << 10),
|
||||||
|
LMQCFT_PASSWORD_NOFREE = (1 << 9),
|
||||||
LMQCFT_CLIENT_ID_NOFREE = (1 << 8),
|
LMQCFT_CLIENT_ID_NOFREE = (1 << 8),
|
||||||
/* only the low 8 are standardized and go out in the protocol */
|
/* only the low 8 are standardized and go out in the protocol */
|
||||||
LMQCFT_USERNAME = (1 << 7),
|
LMQCFT_USERNAME = (1 << 7),
|
||||||
|
|
|
@ -122,6 +122,10 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i,
|
||||||
c->conn_flags = LMQCFT_CLEAN_START;
|
c->conn_flags = LMQCFT_CLEAN_START;
|
||||||
if (cp->client_id_nofree)
|
if (cp->client_id_nofree)
|
||||||
c->conn_flags |= LMQCFT_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))
|
if (!(c->conn_flags & LMQCFT_CLIENT_ID_NOFREE))
|
||||||
lws_free((void *)cp->client_id);
|
lws_free((void *)cp->client_id);
|
||||||
|
@ -152,6 +156,7 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i,
|
||||||
if (!c->username)
|
if (!c->username)
|
||||||
goto oom3;
|
goto oom3;
|
||||||
c->conn_flags |= LMQCFT_USERNAME;
|
c->conn_flags |= LMQCFT_USERNAME;
|
||||||
|
if (!(c->conn_flags & LMQCFT_USERNAME_NOFREE))
|
||||||
lws_free((void *)cp->username);
|
lws_free((void *)cp->username);
|
||||||
if (cp->password) {
|
if (cp->password) {
|
||||||
c->password =
|
c->password =
|
||||||
|
@ -159,6 +164,7 @@ lws_create_client_mqtt_object(const struct lws_client_connect_info *i,
|
||||||
if (!c->password)
|
if (!c->password)
|
||||||
goto oom4;
|
goto oom4;
|
||||||
c->conn_flags |= LMQCFT_PASSWORD;
|
c->conn_flags |= LMQCFT_PASSWORD;
|
||||||
|
if (!(c->conn_flags & LMQCFT_PASSWORD_NOFREE))
|
||||||
lws_free((void *)cp->password);
|
lws_free((void *)cp->password);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,9 @@ static const lws_mqtt_client_connect_param_t client_connect_param = {
|
||||||
.client_id = NULL,
|
.client_id = NULL,
|
||||||
.keep_alive = 60,
|
.keep_alive = 60,
|
||||||
.clean_start = 1,
|
.clean_start = 1,
|
||||||
|
.client_id_nofree = 1,
|
||||||
|
.username_nofree = 1,
|
||||||
|
.password_nofree = 1,
|
||||||
.will_param = {
|
.will_param = {
|
||||||
.topic = "good/bye",
|
.topic = "good/bye",
|
||||||
.message = "sign-off",
|
.message = "sign-off",
|
||||||
|
|
|
@ -42,6 +42,8 @@ static const lws_mqtt_client_connect_param_t client_connect_param = {
|
||||||
.keep_alive = 60,
|
.keep_alive = 60,
|
||||||
.clean_start = 1,
|
.clean_start = 1,
|
||||||
.client_id_nofree = 1,
|
.client_id_nofree = 1,
|
||||||
|
.username_nofree = 1,
|
||||||
|
.password_nofree = 1,
|
||||||
.will_param = {
|
.will_param = {
|
||||||
.topic = "good/bye",
|
.topic = "good/bye",
|
||||||
.message = "sign-off",
|
.message = "sign-off",
|
||||||
|
@ -184,6 +186,7 @@ callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason,
|
||||||
|
|
||||||
case LWS_CALLBACK_MQTT_SUBSCRIBED:
|
case LWS_CALLBACK_MQTT_SUBSCRIBED:
|
||||||
lwsl_user("%s: MQTT_SUBSCRIBED\n", __func__);
|
lwsl_user("%s: MQTT_SUBSCRIBED\n", __func__);
|
||||||
|
lws_callback_on_writable(wsi);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE:
|
case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE:
|
||||||
|
@ -250,8 +253,10 @@ callback_mqtt(struct lws *wsi, enum lws_callback_reasons reason,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
pss->state++;
|
pss->state++;
|
||||||
if (pss->state != STATE_TEST_FINISH)
|
if (pss->state != STATE_TEST_FINISH) {
|
||||||
|
lws_callback_on_writable(wsi);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Oh we are done then */
|
/* Oh we are done then */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue