Commit Graph

1783 Commits

Author SHA1 Message Date
CIPop 00877b0954 Updating the contributing guide regarding IP verification. 2023-09-20 20:36:13 +00:00
Ian Craggs 9613cf419c Free some allocated memory under some circumstances 2023-05-25 10:05:14 +01:00
Ian Craggs 5ce322200d Free some allocated test memory 2023-05-25 10:04:48 +01:00
Ian Craggs a9a8ea5619 Lock socket mutex on socket close #1219 2023-05-25 10:04:21 +01:00
Ian Craggs 08132d4cd7 Correct some memory accesses 2023-05-17 17:59:10 +01:00
Ian Craggs 357c392db1 Check cause connectionLost parameter in samples 2023-05-17 12:46:44 +01:00
Ian Craggs fd213a8461 Handle 0 length arrays properly #1356 2023-05-15 15:55:18 +01:00
Ian Craggs 3933f8b796 Change writeInt4 and readInt4 signatures to unsigned #1336 2023-04-27 18:33:02 +01:00
lijinggang ed07139291 fix: MQTTPacket.c read&write Int/Int4 error
readInt
writeInt
readInt4
writeInt4

eg:
writeInt4(0xFFFFFFFF)

Signed-off-by: lijinggang <lijinggang@aliyun.com>
2023-04-27 17:05:54 +01:00
Ian Craggs c2b51d7abf Limit subscribe/unsubscribe interleaving #1334 2023-04-27 15:58:16 +01:00
Neil Horman f3b1d763b9 Fix read/write race between in MQTTClient
Valgrind reported this error to me recently:

==258178== Invalid read of size 8
==258178==    at 0x3579AB: MQTTClient_waitForCompletion (in /home/nhorman/git/privafy/test/microedge-c/test)
==258178==    by 0x1724BF: publish_msg (comms_connect.c:625)
==258178==    by 0x16F55A: _send_message (comms_register.c:294)
==258178==    by 0x16F605: send_message_sync (comms_register.c:311)
==258178==    by 0x178AEA: send_obj_write_resp_mqtt_message (day0_mqtt_state.c:49)
==258178==    by 0x178FE5: day0_obj_write_req_mqtt_handler (day0_mqtt_state.c:170)
==258178==    by 0x1777A5: service_state_machine_run (service_state_machine_handler.c:670)
==258178==    by 0x49EE12C: start_thread (pthread_create.c:442)
==258178==    by 0x4A6ED73: clone (clone.S:100)
==258178==  Address 0x5075e38 is 24 bytes inside a block of size 152 free'd
==258178==    at 0x48460E4: free (vg_replace_malloc.c:884)
==258178==    by 0x3673FD: ListUnlink (in /home/nhorman/git/privafy/test/microedge-c/test)
==258178==    by 0x3674C0: ListRemove (in /home/nhorman/git/privafy/test/microedge-c/test)
==258178==    by 0x35206D: MQTTClient_destroy (in /home/nhorman/git/privafy/test/microedge-c/test)
==258178==    by 0x171BBD: comms_run (comms_connect.c:445)
==258178==    by 0x49EE12C: start_thread (pthread_create.c:442)
==258178==    by 0x4A6ED73: clone (clone.S:100)
==258178==  Block was alloc'd at
==258178==    at 0x484386F: malloc (vg_replace_malloc.c:393)
==258178==    by 0x351A96: MQTTClient_createWithOptions (in /home/nhorman/git/privafy/test/microedge-c/test)
==258178==    by 0x171987: comms_run (comms_connect.c:409)
==258178==    by 0x49EE12C: start_thread (pthread_create.c:442)
==258178==    by 0x4A6ED73: clone (clone.S:100)

Its occuring because, in MQTTClient_waitForCompletion, the
mqttclient_mutex is repeatedly dropped and re-aquired.  While thats fine
to do, it creates the possibility for another thread to run between the
time MQTClient_waitForCompletion calls MQTTClient_yield and the time it
reaquires the lock.  Valgrind notes that during that period, if another
thread calls MQTTCilent_destroy, the value of m->c in
MQTTClient_waitForCompletion will change, triggering the above invalid
read warning.

Fix is pretty easy, just move the if (m == NULL || m->c == NULL)
conditional to inside the while loop, so that the value of m->c is
revalidated after each lock re-aquisition.

Signed-off-by: Neil Horman <nhorman@gmail.com>
2023-04-26 16:49:12 +01:00
Ian Craggs ade43fbd9e Don't call websocket_connect twice #1348 2023-04-16 13:05:58 +01:00
Ian Craggs b585c1f41e Correct behaviour when settings changed in the connectionLost callback #1341 2023-04-16 12:43:39 +01:00
Ian Craggs d46de46e5b Update Github action Linux build version 2023-04-14 11:55:11 +01:00
Ian Craggs 153b0a2ef5 Merge branch 'develop' of github.com:eclipse/paho.mqtt.c into develop 2023-04-13 16:08:56 +01:00
Ian Craggs f8c1e0dbed Update expired TLS certificates 2023-04-13 15:55:13 +01:00
Ian Craggs 3b03bebb70 Correct script name #1273 2023-01-31 12:47:47 +13:00
Ian Craggs 8f017d7d10 Update version numbers 2022-12-21 11:32:41 +00:00
Ian Craggs 4ec20ae224 Correct windows conditional compilation #1275 2022-12-20 09:01:19 +00:00
Ian Craggs 6abae59191 Convert thread name to wide chars #1280 and correct conditional compilation #1275 2022-12-19 20:18:14 +00:00
Ian Craggs 000175a6b0
Merge pull request #1305 from axelsommerfeldt/fix_eyecatcher_check
checkEyecatchers() used to crash if a heap problem was detected
2022-12-06 15:06:22 +00:00
Axel Sommerfeldt 6602a789a8 checkEyecatchers() used to crash if a heap problem was detected
checkEyecatchers() used vsnprintf() with a format specifier "%d" to print the wrong eyecatcher content, but an eyecatcher was defined as 'double'.
Since "%d" expects an 'int' on the stack (which is usually 32 bit in size) but gets a 'double' instead (which is usually 64 bit), the following 'file' argument will be retrieved as wrong pointer value from stack, resulting in a crash in Log() -> vsnprintf() -> strlen().

This was fixed by defining 'eyecatcher' as 'uint64_t' (instead of 'double') and printing an eyecatcher using 'PRIx64' (instead of "d").

Signed-off-by: Axel Sommerfeldt <axel.sommerfeldt@fastmail.de>
2022-12-06 10:19:03 +01:00
Ian Craggs 122d9afc9f Ensure connectionLost/retry etc is invoked after keepalive disconnect #1276 2022-11-30 13:41:08 +00:00
Ian Craggs 76a01f5ae8 Protect data structure alteration when creating sockets #1219 #1290 - part 2 2022-11-29 18:33:51 +00:00
Ian Craggs c3048f90f1 Protect data structure alteration when creating sockets #1219 #1290 2022-11-29 18:24:20 +00:00
Tony Jiang 5a9e2e4070 fix to realloc memory if any queued data should be copied into new buffer #1303
Signed-off-by: Tony Jiang <tony_jansan@aliyun.com>
2022-11-29 14:05:27 +00:00
Neil Horman 911488a9f0 Ensure connection lost callbacks are complte prior to disconnect end
Encountered this valgrind error while testing some code the other day:

==2568== Memcheck, a memory error detector
==2568== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2568== Using Valgrind-3.16.1 and LibVEX; rerun with -h for copyright info
==2568== Command: ./test
==2568== Parent PID: 2560
==2568==
==2568== Thread 7:
==2568== Invalid read of size 8
==2568==    at 0x4CDA970: connectionLost_call (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x500AEA6: start_thread (pthread_create.c:477)
==2568==    by 0x5121A2E: clone (clone.S:95)
==2568==  Address 0x91e8238 is 40 bytes inside a block of size 176 free'd
==2568==    at 0x48399AB: free (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==2568==    by 0x4CF8B0F: myfree (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x4CF3947: ListUnlink (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x4CF3A16: ListRemove (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x4CDA612: MQTTClient_destroy (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x142BC0: comms_run (comms_connect.c:436)
==2568==    by 0x500AEA6: start_thread (pthread_create.c:477)
==2568==    by 0x5121A2E: clone (clone.S:95)
==2568==  Block was alloc'd at
==2568==    at 0x483877F: malloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==2568==    by 0x4CF8725: mymalloc (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x4CD9F58: MQTTClient_createWithOptions (in /usr/lib/libpaho-mqtt3cs.so.1.3.9)
==2568==    by 0x1428FB: comms_run (comms_connect.c:404)
==2568==    by 0x500AEA6: start_thread (pthread_create.c:477)
==2568==    by 0x5121A2E: clone (clone.S:95)
==2568==

It indicates a use after free of the MQTTClient data structure in the
connectionLost_call.

A bit of digging revealed that the problem was that my code Called
MQTTClient_disconnect and MQTTClient_destroy in rapid succession.
Because MQTTClient_disconnect does this:

Thread_start(connectionLost_call, m);

Its entirely possible for connectionLost_call to be executed after the
return from MQTTClient_disconnect completes, at which time the Client
may be destroyed/freed, leading to the above valgrind error.

fix is pretty straightforward. We could use a mutex and condition
variable to serialize the two threads, but Windows doesn't have support
for condition variables currently, so just use one time semaphore to
ensure serialization

Signed-off-by: Neil Horman <nhorman@gmail.com>

convert to use of semaphore
2022-11-28 13:00:41 +00:00
Ian Craggs be035e77b5 Add reconnect to paho_cs_pub sample #1294 2022-11-28 12:50:36 +00:00
Ian Craggs a633019b66 Reset reconnect intervals on MQTTAsync_reconnect #1274 2022-11-28 12:06:45 +00:00
Ian Craggs ab26b3cae4 Fix up keep alive processing #1277 #1276 2022-11-27 16:41:23 +00:00
Ian Craggs 5ae44bdc2e Don't call writeContinue if not set #1286 #1293 #1286 2022-11-27 15:23:51 +00:00
Ian Craggs 4ec7ec3cb2 Update version to 1.3.11 2022-09-29 11:23:27 +01:00
Ian Craggs 697f4008fa Add doc to highlight WebSocket connect option initializers #724 2022-09-29 10:59:42 +01:00
Finlay Morrison 87fc8162d5 fixed error in comment 2022-09-28 16:57:10 +01:00
Ian Craggs 749515ddc7 Add Frank's musl thoughts to README #901 2022-09-28 16:52:00 +01:00
Jonliu1993 7761747083 Add vcpkg installation instructions 2022-09-28 16:35:05 +01:00
Ian Craggs 8419ce091e Merge branch 'fpagliughi-mqtt-protocol-url' into develop 2022-09-28 16:12:16 +01:00
Ian Craggs ee37c780cd Merge branch 'mqtt-protocol-url' of https://github.com/fpagliughi/paho.mqtt.c into fpagliughi-mqtt-protocol-url 2022-09-28 16:11:56 +01:00
Ian Craggs fc8e0d4a2b Merge branch 'chenzhenhua5-develop' into develop 2022-09-28 16:09:55 +01:00
Ian Craggs 951a263dcd Fix up suback count check 2022-09-28 14:19:29 +01:00
Ian Craggs 09ffa867e4 Merge branch 'develop' of https://github.com/chenzhenhua5/paho.mqtt.c into chenzhenhua5-develop 2022-09-28 13:58:40 +01:00
fpagliughi cfc5aaa3bf Added documentation for mqtt:// and mqtts:// protocols. Changed some tests and samples to use them. 2022-09-27 20:26:30 -04:00
Ian Craggs d27fdd82a2 Merge branch 'fpagliughi-readme-updates' into develop 2022-09-27 14:37:48 +01:00
Ian Craggs 86db2e1cdc Merge branch 'readme-updates' of https://github.com/fpagliughi/paho.mqtt.c into fpagliughi-readme-updates 2022-09-27 14:36:24 +01:00
Ian Craggs 7cfd87223e Fix install list #1260 2022-09-27 14:17:10 +01:00
Ian Craggs 772a83ba1c Add thread names if possible #1100 2022-09-27 13:11:52 +01:00
Ian Craggs 14bc391398 Fix some types to allow USE_SELECT to build on Windows #1271 2022-09-26 12:19:47 +01:00
Ian Craggs 4da5ef65e2 Merge branch 'develop' of github.com:eclipse/paho.mqtt.c into develop 2022-09-24 10:19:21 +01:00
Ian Craggs 9b7ae98783 Allow topic and payload to be returned in publish onSuccess/onFailure callbacks #1133 2022-09-23 18:07:29 +01:00
Ian Craggs 7249106011 Merge branch 'develop' of github.com:eclipse/paho.mqtt.c into develop 2022-09-22 17:39:04 +01:00