Commit 9bd6c09d authored by Keith Holman's avatar Keith Holman

prevent segfault for unknown protocol in test app

This patch updates the source code to not seg fault when an unknown
protocol is specified on the command line in the test app: paho_cs_sub

Previously the output would be:
```
./paho_cs_pub my/topic --host bad://test.mosquitto.org --port 8081
Using topic my/topic
Connecting
Segmentation fault (core dumped)
```

After this patch the output is:
```
./paho_cs_pub my/topic --host bad://test.mosquitto.org --port 8081
Using topic my/topic
Connecting
Failed to connect
```
Signed-off-by: 's avatarKeith Holman <keith.holman@windriver.com>
parent c897ebac
...@@ -1319,7 +1319,14 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options) ...@@ -1319,7 +1319,14 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
} }
if (options->struct_version < 2 || options->serverURIcount == 0) if (options->struct_version < 2 || options->serverURIcount == 0)
{
if ( !m )
{
rc = MQTTCLIENT_NULL_PARAMETER;
goto exit;
}
rc = MQTTClient_connectURI(handle, options, m->serverURI); rc = MQTTClient_connectURI(handle, options, m->serverURI);
}
else else
{ {
int i; int i;
...@@ -1354,7 +1361,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options) ...@@ -1354,7 +1361,7 @@ int MQTTClient_connect(MQTTClient handle, MQTTClient_connectOptions* options)
} }
exit: exit:
if (m->c->will) if (m && m->c && m->c->will)
{ {
if (m->c->will->payload) if (m->c->will->payload)
free(m->c->will->payload); free(m->c->will->payload);
......
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