Commit d1d6496d authored by Ian Craggs's avatar Ian Craggs

Check for bad protocol name #294

parent adf15a38
......@@ -465,6 +465,20 @@ int MQTTAsync_createWithOptions(MQTTAsync* handle, const char* serverURI, const
goto exit;
}
if (strstr(serverURI, "://") != NULL)
{
if (strncmp(URI_TCP, serverURI, strlen(URI_TCP)) != 0
#if defined(OPENSSL)
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
#endif
)
{
rc = MQTTASYNC_BAD_PROTOCOL;
goto exit;
}
}
if (options && (strncmp(options->struct_id, "MQCO", 4) != 0 || options->struct_version != 0))
{
rc = MQTTASYNC_BAD_STRUCTURE;
......
......@@ -172,6 +172,11 @@
* Return code: Attempting SSL connection using non-SSL version of library
*/
#define MQTTASYNC_SSL_NOT_SUPPORTED -13
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTASYNC_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
......
......@@ -320,6 +320,20 @@ int MQTTClient_create(MQTTClient* handle, const char* serverURI, const char* cli
goto exit;
}
if (strstr(serverURI, "://") != NULL)
{
if (strncmp(URI_TCP, serverURI, strlen(URI_TCP)) != 0
#if defined(OPENSSL)
&& strncmp(URI_SSL, serverURI, strlen(URI_SSL)) != 0
#endif
)
{
rc = MQTTCLIENT_BAD_PROTOCOL;
goto exit;
}
}
if (!initialized)
{
#if defined(HEAP_H)
......
/*******************************************************************************
* Copyright (c) 2009, 2017 IBM Corp.
* Copyright (c) 2009, 2018 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
......@@ -175,6 +175,10 @@
* Return code: Attempting SSL connection using non-SSL version of library
*/
#define MQTTCLIENT_SSL_NOT_SUPPORTED -10
/**
* Return code: protocol prefix in serverURI should be tcp:// or ssl://
*/
#define MQTTCLIENT_BAD_PROTOCOL -14
/**
* Default MQTT version to connect with. Use 3.1.1 then fall back to 3.1
......
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