Commit 779ca42a authored by Juergen Kosel's avatar Juergen Kosel

Protect call of Socket_noPendingWrites() with socket_mutex to fix issue #385

It turned out in https://github.com/eclipse/paho.mqtt.c/issues/385 that
Socket_getReadySocket() could remove a list element, which is currently
in use by a function called by Socket_noPendingWirte().
And this leads to memory corruption or segmentation fault.
To fix this, this call of Socket_PendingWrites() in MQTTAsync.c needs to be protected by mutex_socket.
Signed-off-by: 's avatarJuergen Kosel <juergen.kosel@softing.com>
parent 6a2c1c48
...@@ -973,6 +973,17 @@ static void MQTTAsync_checkDisconnect(MQTTAsync handle, MQTTAsync_command* comma ...@@ -973,6 +973,17 @@ static void MQTTAsync_checkDisconnect(MQTTAsync handle, MQTTAsync_command* comma
FUNC_EXIT; FUNC_EXIT;
} }
/**
* Call Socket_noPendingWrites(int socket) with protection by socket_mutex, see https://github.com/eclipse/paho.mqtt.c/issues/385
*/
static int MQTTAsync_Socket_noPendingWrites(int socket)
{
int rc;
Thread_lock_mutex(socket_mutex);
rc = Socket_noPendingWrites(socket);
Thread_unlock_mutex(socket_mutex);
return rc;
}
/** /**
* See if any pending writes have been completed, and cleanup if so. * See if any pending writes have been completed, and cleanup if so.
...@@ -1154,7 +1165,7 @@ static int MQTTAsync_processCommand(void) ...@@ -1154,7 +1165,7 @@ static int MQTTAsync_processCommand(void)
continue; continue;
if (cmd->command.type == CONNECT || cmd->command.type == DISCONNECT || (cmd->client->c->connected && if (cmd->command.type == CONNECT || cmd->command.type == DISCONNECT || (cmd->client->c->connected &&
cmd->client->c->connect_state == 0 && Socket_noPendingWrites(cmd->client->c->net.socket))) cmd->client->c->connect_state == 0 && MQTTAsync_Socket_noPendingWrites(cmd->client->c->net.socket)))
{ {
if ((cmd->command.type == PUBLISH || cmd->command.type == SUBSCRIBE || cmd->command.type == UNSUBSCRIBE) && if ((cmd->command.type == PUBLISH || cmd->command.type == SUBSCRIBE || cmd->command.type == UNSUBSCRIBE) &&
cmd->client->c->outboundMsgs->count >= MAX_MSG_ID - 1) cmd->client->c->outboundMsgs->count >= MAX_MSG_ID - 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