Commit 6645291b authored by Ian Craggs's avatar Ian Craggs

Fix a memory allocation issue in websockets

parent 09db5293
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2018 Wind River Systems, Inc. All Rights Reserved. * Copyright (c) 2018 Wind River Systems, Inc. and others. All Rights Reserved.
* *
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
* *
* Contributors: * Contributors:
* Keith Holman - initial implementation and documentation * Keith Holman - initial implementation and documentation
* Ian Craggs - use memory tracking
*******************************************************************************/ *******************************************************************************/
#include <stdint.h> #include <stdint.h>
...@@ -82,6 +83,8 @@ ...@@ -82,6 +83,8 @@
#include <openssl/rand.h> #include <openssl/rand.h>
#endif /* if defined(OPENSSL) */ #endif /* if defined(OPENSSL) */
#include "Heap.h"
/** @brief raw uuid type */ /** @brief raw uuid type */
typedef unsigned char uuid_t[16]; typedef unsigned char uuid_t[16];
...@@ -308,6 +311,9 @@ int WebSocket_connect( networkHandles *net, const char *uri ) ...@@ -308,6 +311,9 @@ int WebSocket_connect( networkHandles *net, const char *uri )
const char *topic = NULL; const char *topic = NULL;
/* Generate UUID */ /* Generate UUID */
if (net->websocket_key == NULL)
net->websocket_key = malloc(25u);
else
net->websocket_key = realloc(net->websocket_key, 25u); net->websocket_key = realloc(net->websocket_key, 25u);
#if defined(WIN32) || defined(WIN64) #if defined(WIN32) || defined(WIN64)
UUID uuid; UUID uuid;
...@@ -426,7 +432,10 @@ void WebSocket_close(networkHandles *net, int status_code, const char *reason) ...@@ -426,7 +432,10 @@ void WebSocket_close(networkHandles *net, int status_code, const char *reason)
free( buf0 ); free( buf0 );
} }
if ( net->websocket_key ) if ( net->websocket_key )
{
free( net->websocket_key ); free( net->websocket_key );
net->websocket_key = NULL;
}
} }
/** /**
...@@ -784,6 +793,9 @@ int WebSocket_receiveFrame(networkHandles *net, ...@@ -784,6 +793,9 @@ int WebSocket_receiveFrame(networkHandles *net,
if ( res ) if ( res )
cur_len = res->len; cur_len = res->len;
if (res == NULL)
res = malloc( sizeof(struct ws_frame) + cur_len + len );
else
res = realloc( res, sizeof(struct ws_frame) + cur_len + len ); res = realloc( res, sizeof(struct ws_frame) + cur_len + len );
memcpy( (unsigned char *)res + sizeof(struct ws_frame) + cur_len, b, len ); memcpy( (unsigned char *)res + sizeof(struct ws_frame) + cur_len, b, len );
res->pos = 0u; res->pos = 0u;
......
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