提交 4b8f58fc 编写于 作者: I Ian Craggs

Merge branch 'develop' into coverity-develop

......@@ -31,7 +31,6 @@ file(READ version.minor PAHO_VERSION_MINOR)
file(READ version.patch PAHO_VERSION_PATCH)
SET(CLIENT_VERSION ${PAHO_VERSION_MAJOR}.${PAHO_VERSION_MINOR}.${PAHO_VERSION_PATCH})
ENABLE_LANGUAGE(CXX)
INCLUDE(GNUInstallDirs)
STRING(TIMESTAMP BUILD_TIMESTAMP UTC)
......
/*******************************************************************************
* Copyright (c) 2009, 2019 IBM Corp.
* Copyright (c) 2009, 2020 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -124,24 +124,24 @@ typedef struct
unsigned int good : 1; /**< if we have an error on the socket we turn this off */
unsigned int ping_outstanding : 1;
signed int connect_state : 4;
networkHandles net;
int msgID;
int keepAliveInterval;
networkHandles net; /**< network info for this client */
int msgID; /**< the MQTT message id */
int keepAliveInterval; /**< the MQTT keep alive interval */
int retryInterval;
int maxInflightMessages;
willMessages* will;
List* inboundMsgs;
List* outboundMsgs; /**< in flight */
List* messageQueue;
int maxInflightMessages; /**< the max number of inflight outbound messages we allow */
willMessages* will; /**< the MQTT will message, if any */
List* inboundMsgs; /**< inbound in flight messages */
List* outboundMsgs; /**< outbound in flight messages */
List* messageQueue; /**< inbound complete but undelivered messages */
unsigned int qentry_seqno;
void* phandle; /* the persistence handle */
MQTTClient_persistence* persistence; /* a persistence implementation */
void* phandle; /**< the persistence handle */
MQTTClient_persistence* persistence; /**< a persistence implementation */
void* context; /* calling context - used when calling disconnect_internal */
int MQTTVersion;
int sessionExpiry; /**< MQTT 5 session expiry */
int MQTTVersion; /**< the version of MQTT being used, 3, 4 or 5 */
int sessionExpiry; /**< MQTT 5 session expiry */
#if defined(OPENSSL)
MQTTClient_SSLOptions *sslopts;
SSL_SESSION* session; /***< SSL session pointer for fast handhake */
MQTTClient_SSLOptions *sslopts; /**< the SSL/TLS connect options */
SSL_SESSION* session; /**< SSL session pointer for fast handhake */
#endif
} Clients;
......
......@@ -160,13 +160,14 @@ void* mymalloc(char* file, int line, size_t size)
storageElement* s = NULL;
size_t space = sizeof(storageElement);
size_t filenamelen = strlen(file)+1;
void* rc = NULL;
Thread_lock_mutex(heap_mutex);
size = Heap_roundup(size);
if ((s = malloc(sizeof(storageElement))) == NULL)
{
Log(LOG_ERROR, 13, errmsg);
return NULL;
goto exit;
}
memset(s, 0, sizeof(storageElement));
......@@ -175,7 +176,7 @@ void* mymalloc(char* file, int line, size_t size)
{
Log(LOG_ERROR, 13, errmsg);
free(s);
return NULL;
goto exit;
}
memset(s->file, 0, sizeof(filenamelen));
......@@ -188,7 +189,7 @@ void* mymalloc(char* file, int line, size_t size)
Log(LOG_ERROR, 13, errmsg);
free(s->file);
free(s);
return NULL;
goto exit;
}
memset(s->stack, 0, sizeof(filenamelen));
StackTrace_get(Thread_getid(), s->stack, STACK_LEN);
......@@ -200,7 +201,7 @@ void* mymalloc(char* file, int line, size_t size)
Log(LOG_ERROR, 13, errmsg);
free(s->file);
free(s);
return NULL;
goto exit;
}
memset(s->ptr, 0, size + 2*sizeof(eyecatcherType));
space += size + 2*sizeof(eyecatcherType);
......@@ -211,8 +212,10 @@ void* mymalloc(char* file, int line, size_t size)
state.current_size += size;
if (state.current_size > state.max_size)
state.max_size = state.current_size;
rc = ((eyecatcherType*)(s->ptr)) + 1; /* skip start eyecatcher */
exit:
Thread_unlock_mutex(heap_mutex);
return ((eyecatcherType*)(s->ptr)) + 1; /* skip start eyecatcher */
return rc;
}
......@@ -336,7 +339,7 @@ void *myrealloc(char* file, int line, void* p, size_t size)
if ((s->ptr = realloc(s->ptr, size + 2*sizeof(eyecatcherType))) == NULL)
{
Log(LOG_ERROR, 13, errmsg);
return NULL;
goto exit;
}
space += size + 2*sizeof(eyecatcherType) - s->size;
*(eyecatcherType*)(s->ptr) = eyecatcher; /* start eyecatcher */
......@@ -350,6 +353,7 @@ void *myrealloc(char* file, int line, void* p, size_t size)
rc = s->ptr;
TreeAdd(&heap, s, space);
}
exit:
Thread_unlock_mutex(heap_mutex);
return (rc == NULL) ? NULL : ((eyecatcherType*)(rc)) + 1; /* skip start eyecatcher */
}
......
......@@ -3472,6 +3472,7 @@ static int MQTTAsync_assignMsgId(MQTTAsyncs* m)
msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1;
while (ListFindItem(commands, &msgid, cmdMessageIDCompare) ||
ListFindItem(m->c->outboundMsgs, &msgid, messageIDCompare) ||
ListFindItem(m->responses, &msgid, cmdMessageIDCompare))
{
msgid = (msgid == MAX_MSG_ID) ? 1 : msgid + 1;
......@@ -3785,12 +3786,15 @@ int MQTTAsync_send(MQTTAsync handle, const char* destinationName, int payloadlen
}
if ((pub->command.details.pub.destinationName = MQTTStrdup(destinationName)) == NULL)
{
free(pub);
rc = PAHO_MEMORY_ERROR;
goto exit;
}
pub->command.details.pub.payloadlen = payloadlen;
if ((pub->command.details.pub.payload = malloc(payloadlen)) == NULL)
{
free(pub->command.details.pub.destinationName);
free(pub);
rc = PAHO_MEMORY_ERROR;
goto exit;
}
......
......@@ -345,12 +345,14 @@ static void WebSocket_unmaskData(uint8_t *mask, size_t idx, int count, char** bu
{
int i;
FUNC_ENTRY;
for (i = 0; i < count; ++i)
{
size_t j;
for ( j = 0u; j < buflens[i]; ++j, ++idx )
buffers[i][j] ^= mask[idx % 4];
}
FUNC_EXIT;
}
......@@ -912,9 +914,12 @@ int WebSocket_putdatas(networkHandles* net, char** buf0, size_t* buf0len,
#endif
rc = Socket_putdatas(net->socket, wsdata.wsbuf0, wsdata.wsbuf0len, count, buffers, buflens, freeData);
if (mask_data)
WebSocket_unmaskData(wsdata.mask, *buf0len, count, buffers, buflens);
free(wsdata.wsbuf0); /* free temporary ws header */
if (rc != TCPSOCKET_INTERRUPTED)
{
if (mask_data)
WebSocket_unmaskData(wsdata.mask, *buf0len, count, buffers, buflens);
free(wsdata.wsbuf0); /* free temporary ws header */
}
}
else
{
......@@ -1259,7 +1264,7 @@ int WebSocket_upgrade( networkHandles *net )
goto exit;
}
if ( rcv > 0 && strncmp( read_buf, "HTTP/1.1", 8u ) == 0 )
if (strncmp( read_buf, "HTTP/1.1", 8u ) == 0)
{
if (strncmp( &read_buf[9], "101", 3u ) != 0)
{
......@@ -1269,7 +1274,7 @@ int WebSocket_upgrade( networkHandles *net )
}
}
if ( rcv > 0 && strncmp( read_buf, "HTTP/1.1 101", 12u ) == 0 )
if (strncmp( read_buf, "HTTP/1.1 101", 12u ) == 0)
{
const char *p;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册