From 14858e68afde2ddb64279f87dd469511c0d65778 Mon Sep 17 00:00:00 2001 From: Erik Karlsson <erik.karlsson@iopsys.eu> Date: Mon, 3 Jun 2024 14:48:15 +0200 Subject: [PATCH] Only write to socket pair in threaded mode Otherwise it is possible to write to the socket pair when there is no consumer resulting in the buffer growing indefinitely. This issue manifests itself when an external event loop is used together with mosquitto_loop_read/mosquitto_loop_write/mosquitto_loop_misc instead of using mosquitto_loop, mosquitto_loop_forever or threaded mode with mosquitto_loop_start/mosquitto_loop_stop Signed-off-by: Erik Karlsson <erik.karlsson@iopsys.eu> --- lib/packet_mosq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/packet_mosq.c b/lib/packet_mosq.c index fd716baf..11ab5259 100644 --- a/lib/packet_mosq.c +++ b/lib/packet_mosq.c @@ -190,7 +190,7 @@ int packet__queue(struct mosquitto *mosq, struct mosquitto__packet *packet) /* Write a single byte to sockpairW (connected to sockpairR) to break out * of select() if in threaded mode. */ - if(mosq->sockpairW != INVALID_SOCKET){ + if(mosq->threaded == mosq_ts_self && mosq->sockpairW != INVALID_SOCKET){ #ifndef WIN32 if(write(mosq->sockpairW, &sockpair_data, 1)){ } -- 2.45.1