mqtt: properly handle the message which exceeds maxsize

We should goto fail as topic is allocated.

Follow-up to 92fd791

Closes #19417
This commit is contained in:
x2018 2025-11-09 19:19:13 +08:00 committed by Daniel Stenberg
parent b0aba1005b
commit 87149c8383
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -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);