From: x2018 Date: Sun, 9 Nov 2025 11:19:13 +0000 (+0800) Subject: mqtt: properly handle the message which exceeds maxsize X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=87149c8383f7cdc85cd4780256afc1b5a923bac8;p=thirdparty%2Fcurl.git mqtt: properly handle the message which exceeds maxsize We should goto fail as topic is allocated. Follow-up to 92fd791 Closes #19417 --- diff --git a/lib/mqtt.c b/lib/mqtt.c index bac319e63a..713e4aa02c 100644 --- a/lib/mqtt.c +++ b/lib/mqtt.c @@ -613,8 +613,10 @@ static CURLcode mqtt_publish(struct Curl_easy *data) remaininglength = payloadlen + 2 + topiclen; encodelen = mqtt_encode_len(encodedbytes, remaininglength); - if(MAX_MQTT_MESSAGE_SIZE - remaininglength - 1 < encodelen) - return CURLE_TOO_LARGE; + if(MAX_MQTT_MESSAGE_SIZE - remaininglength - 1 < encodelen) { + result = CURLE_TOO_LARGE; + goto fail; + } /* add the control byte and the encoded remaining length */ pkt = malloc(remaininglength + 1 + encodelen);