Commit d27a7c58 authored by Ian Craggs's avatar Ian Craggs

Allocate username/password buffers #431

parent 99fb071d
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
* Ian Craggs - auto reconnect timing fix #218 * Ian Craggs - auto reconnect timing fix #218
* Ian Craggs - fix for issue #190 * Ian Craggs - fix for issue #190
* Ian Craggs - check for NULL SSL options #334 * Ian Craggs - check for NULL SSL options #334
* Ian Craggs - allocate username/password buffers #431
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -2436,14 +2437,22 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options) ...@@ -2436,14 +2437,22 @@ int MQTTAsync_connect(MQTTAsync handle, const MQTTAsync_connectOptions* options)
} }
#endif #endif
m->c->username = options->username; if (m->c->username)
m->c->password = options->password; free((void*)m->c->username);
if (options->username)
m->c->username = MQTTStrdup(options->username);
if (m->c->password)
free((void*)m->c->password);
if (options->password) if (options->password)
{
m->c->password = MQTTStrdup(options->password);
m->c->passwordlen = strlen(options->password); m->c->passwordlen = strlen(options->password);
}
else if (options->struct_version >= 5 && options->binarypwd.data) else if (options->struct_version >= 5 && options->binarypwd.data)
{ {
m->c->password = options->binarypwd.data;
m->c->passwordlen = options->binarypwd.len; m->c->passwordlen = options->binarypwd.len;
m->c->password = malloc(m->c->passwordlen);
memcpy((void*)m->c->password, options->binarypwd.data, m->c->passwordlen);
} }
m->c->retryInterval = options->retryInterval; m->c->retryInterval = options->retryInterval;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
* Ian Craggs - binary will message support * Ian Craggs - binary will message support
* Ian Craggs - waitforCompletion fix #240 * Ian Craggs - waitforCompletion fix #240
* Ian Craggs - check for NULL SSL options #334 * Ian Craggs - check for NULL SSL options #334
* Ian Craggs - allocate username/password buffers #431
*******************************************************************************/ *******************************************************************************/
/** /**
...@@ -1149,16 +1150,23 @@ static int MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectOptions* o ...@@ -1149,16 +1150,23 @@ static int MQTTClient_connectURI(MQTTClient handle, MQTTClient_connectOptions* o
} }
#endif #endif
m->c->username = options->username; if (m->c->username)
m->c->password = options->password; free((void*)m->c->username);
if (options->username)
m->c->username = MQTTStrdup(options->username);
if (m->c->password)
free((void*)m->c->password);
if (options->password) if (options->password)
{
m->c->password = MQTTStrdup(options->password);
m->c->passwordlen = strlen(options->password); m->c->passwordlen = strlen(options->password);
}
else if (options->struct_version >= 5 && options->binarypwd.data) else if (options->struct_version >= 5 && options->binarypwd.data)
{ {
m->c->password = options->binarypwd.data;
m->c->passwordlen = options->binarypwd.len; m->c->passwordlen = options->binarypwd.len;
m->c->password = malloc(m->c->passwordlen);
memcpy((void*)m->c->password, options->binarypwd.data, m->c->passwordlen);
} }
m->c->retryInterval = options->retryInterval;
if (options->struct_version >= 3) if (options->struct_version >= 3)
MQTTVersion = options->MQTTVersion; MQTTVersion = options->MQTTVersion;
......
...@@ -681,6 +681,10 @@ void MQTTProtocol_freeClient(Clients* client) ...@@ -681,6 +681,10 @@ void MQTTProtocol_freeClient(Clients* client)
free(client->will->topic); free(client->will->topic);
free(client->will); free(client->will);
} }
if (client->username)
free((void*)client->username);
if (client->password)
free((void*)client->password);
#if defined(OPENSSL) #if defined(OPENSSL)
if (client->sslopts) if (client->sslopts)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment