...
 
Commits (3)
    https://gitcode.net/awesome-mirrors/eclipse/paho.mqtt.c/-/commit/fd213a8461946dded03033ba9e4e99e046af6967 Handle 0 length arrays properly #1356 2023-05-15T15:55:18+01:00 Ian Craggs icraggs@gmail.com https://gitcode.net/awesome-mirrors/eclipse/paho.mqtt.c/-/commit/357c392db101042e9253b39e640308eff9741c0d Check cause connectionLost parameter in samples 2023-05-17T12:46:44+01:00 Ian Craggs icraggs@gmail.com https://gitcode.net/awesome-mirrors/eclipse/paho.mqtt.c/-/commit/08132d4cd76883b6e7c4a3d31891e7fa43171fbc Correct some memory accesses 2023-05-17T17:59:10+01:00 Ian Craggs icraggs@gmail.com
......@@ -3034,9 +3034,9 @@ static MQTTPacket* MQTTAsync_cycle(SOCKET* sock, unsigned long timeout, int* rc)
pack->header.bits.type == PUBREC)
{
int msgid = 0,
msgtype = 0,
ackrc = 0,
mqttversion = 0;
unsigned int msgtype = 0,
ackrc = 0;
MQTTProperties msgprops = MQTTProperties_initializer;
Publications* pubToRemove = NULL;
......@@ -3055,11 +3055,11 @@ static MQTTPacket* MQTTAsync_cycle(SOCKET* sock, unsigned long timeout, int* rc)
}
}
if (pack->header.bits.type == PUBCOMP)
if (msgtype == PUBCOMP)
*rc = MQTTProtocol_handlePubcomps(pack, *sock, &pubToRemove);
else if (pack->header.bits.type == PUBREC)
else if (msgtype == PUBREC)
*rc = MQTTProtocol_handlePubrecs(pack, *sock, &pubToRemove);
else if (pack->header.bits.type == PUBACK)
else if (msgtype == PUBACK)
*rc = MQTTProtocol_handlePubacks(pack, *sock, &pubToRemove);
if (!m)
Log(LOG_ERROR, -1, "PUBCOMP, PUBACK or PUBREC received for no client, msgid %d", msgid);
......@@ -3114,7 +3114,7 @@ static MQTTPacket* MQTTAsync_cycle(SOCKET* sock, unsigned long timeout, int* rc)
data.token = command->command.token;
data.reasonCode = ackrc;
data.properties = msgprops;
data.packet_type = pack->header.bits.type;
data.packet_type = msgtype;
Log(TRACE_MIN, -1, "Calling publish failure for client %s", m->c->clientID);
(*(command->command.onFailure5))(command->command.context, &data);
}
......
/*******************************************************************************
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs and others
* Copyright (c) 2009, 2023 IBM Corp., Ian Craggs and others
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -516,17 +516,40 @@ SOCKET Socket_getReadySocket(int more_work, int timeout, mutex_type mutex, int*
if (mod_s.nfds != mod_s.saved.nfds)
{
mod_s.saved.nfds = mod_s.nfds;
if (mod_s.saved.fds_read)
if (mod_s.nfds == 0)
{
if (mod_s.saved.fds_read)
{
free(mod_s.saved.fds_read);
mod_s.saved.fds_read = NULL;
}
}
else if (mod_s.saved.fds_read)
mod_s.saved.fds_read = realloc(mod_s.saved.fds_read, mod_s.nfds * sizeof(struct pollfd));
else
mod_s.saved.fds_read = malloc(mod_s.nfds * sizeof(struct pollfd));
if (mod_s.saved.fds_write)
if (mod_s.nfds == 0)
{
if (mod_s.saved.fds_write)
{
free(mod_s.saved.fds_write);
mod_s.saved.fds_write = NULL;
}
}
else if (mod_s.saved.fds_write)
mod_s.saved.fds_write = realloc(mod_s.saved.fds_write, mod_s.nfds * sizeof(struct pollfd));
else
mod_s.saved.fds_write = malloc(mod_s.nfds * sizeof(struct pollfd));
}
memcpy(mod_s.saved.fds_read, mod_s.fds_read, mod_s.nfds * sizeof(struct pollfd));
memcpy(mod_s.saved.fds_write, mod_s.fds_write, mod_s.nfds * sizeof(struct pollfd));
if (mod_s.fds_read == NULL)
mod_s.saved.fds_read = NULL;
else
memcpy(mod_s.saved.fds_read, mod_s.fds_read, mod_s.nfds * sizeof(struct pollfd));
if (mod_s.fds_write == NULL)
mod_s.saved.fds_write = NULL;
else
memcpy(mod_s.saved.fds_write, mod_s.fds_write, mod_s.nfds * sizeof(struct pollfd));
if (mod_s.saved.nfds == 0)
{
......
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -45,7 +45,8 @@ void connlost(void *context, char *cause)
int rc;
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
if (cause)
printf(" cause: %s\n", cause);
printf("Reconnecting\n");
conn_opts.keepAliveInterval = 20;
......
/*******************************************************************************
* Copyright (c) 2012, 2020 IBM Corp.
* Copyright (c) 2012, 2023 IBM Corp.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -62,7 +62,8 @@ void connlost(void *context, char *cause)
int rc;
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
if (cause)
printf(" cause: %s\n", cause);
printf("Reconnecting\n");
conn_opts.keepAliveInterval = 20;
......
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -53,7 +53,8 @@ int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *m
void connlost(void *context, char *cause)
{
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
if (cause)
printf(" cause: %s\n", cause);
}
int main(int argc, char* argv[])
......
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -47,7 +47,8 @@ int msgarrvd(void *context, char *topicName, int topicLen, MQTTClient_message *m
void connlost(void *context, char *cause)
{
printf("\nConnection lost\n");
printf(" cause: %s\n", cause);
if (cause)
printf(" cause: %s\n", cause);
}
int main(int argc, char* argv[])
......
/*******************************************************************************
* Copyright (c) 2009, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2009, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -750,9 +750,9 @@ int test4_run(int qos)
while (tokens[i] != -1)
MyLog(LOGA_DEBUG, "Pending delivery token %d", tokens[i++]);
MQTTClient_free(tokens);
assert1("no of tokens should be count", i == count, "no of tokens %d count %d", i, count);
mytoken = tokens[0];
MQTTClient_free(tokens);
}
MQTTClient_destroy(&c); /* force re-reading persistence on create */
......
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -338,7 +338,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test1_will_message_received = 1;
else
test1_messages_received++;
......@@ -599,7 +599,7 @@ int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test2_will_message_received = 1;
else
test2_messages_received++;
......@@ -868,9 +868,9 @@ int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MQTTAsync c = (MQTTAsync)context;
static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\" %d", topicName, message->payloadlen, message->payload, message->payloadlen);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test3_will_message_received = 1;
else
test3_messages_received++;
......@@ -1129,7 +1129,7 @@ int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test4_will_message_received = 1;
else
test4_messages_received++;
......@@ -1391,9 +1391,9 @@ int test5_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MQTTAsync c = (MQTTAsync)context;
static int message_count = 0;
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\" %d", topicName, message->payloadlen, message->payload, message->payloadlen);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test5_will_message_received = 1;
else
test5_messages_received++;
......@@ -1716,7 +1716,7 @@ int test6(struct Options options)
/* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts;
opts.will->payload.data = "will message";
opts.will->payload.len = (int)strlen(opts.will->payload.data) + 1;
opts.will->payload.len = (int)strlen(opts.will->payload.data);
opts.will->qos = 1;
opts.will->retained = 0;
opts.will->topicName = willTopic;
......@@ -1814,7 +1814,7 @@ int test7_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test7_will_message_received = 1;
else
test7_messages_received++;
......
/*******************************************************************************
* Copyright (c) 2012, 2022 IBM Corp., Ian Craggs
* Copyright (c) 2012, 2023 IBM Corp., Ian Craggs
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
......@@ -383,7 +383,7 @@ int test1_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test1_will_message_received = 1;
else
test1_messages_received++;
......@@ -720,7 +720,7 @@ int test2_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test2_will_message_received = 1;
else
test2_messages_received++;
......@@ -992,7 +992,7 @@ int test3_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test3_will_message_received = 1;
else
test3_messages_received++;
......@@ -1260,7 +1260,7 @@ int test4_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen,
message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test4_will_message_received = 1;
else
test4_messages_received++;
......@@ -1532,7 +1532,7 @@ int test5_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test5_will_message_received = 1;
else
test5_messages_received++;
......@@ -1869,7 +1869,7 @@ int test6(struct Options options)
/* let client c go: connect, and send disconnect command to proxy */
opts.will = &wopts;
opts.will->payload.data = "will message";
opts.will->payload.len = (int)strlen(opts.will->payload.data) + 1;
opts.will->payload.len = (int)strlen(opts.will->payload.data);
opts.will->qos = 1;
opts.will->retained = 0;
opts.will->topicName = willTopic;
......@@ -1970,7 +1970,7 @@ int test7_messageArrived(void* context, char* topicName, int topicLen, MQTTAsync
MyLog(LOGA_DEBUG, "Message received on topic %s, \"%.*s\"", topicName, message->payloadlen, message->payload);
if (memcmp(message->payload, "will message", message->payloadlen) == 0)
if (message->payloadlen == strlen("will message") && memcmp(message->payload, "will message", message->payloadlen) == 0)
test7_will_message_received = 1;
else
test7_messages_received++;
......