]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
mqtt: deal with 0 byte reads correctly
authorDaniel Stenberg <daniel@haxx.se>
Tue, 15 Dec 2020 07:51:33 +0000 (08:51 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 15 Dec 2020 10:38:29 +0000 (11:38 +0100)
OSS-Fuzz found it
Bug: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=28676

Closes #6327

lib/mqtt.c

index e324ec3dd7d0cbbf6b0d679d17f18c5610c08749..a56c7d5eb2705a8e8576d5329219d3ffb4317dcf 100644 (file)
@@ -553,7 +553,7 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
   case MQTT_FIRST:
     /* Read the initial byte only */
     result = Curl_read(conn, sockfd, (char *)&mq->firstbyte, 1, &nread);
-    if(result)
+    if(!nread)
       break;
     Curl_debug(data, CURLINFO_HEADER_IN, (char *)&mq->firstbyte, 1);
     /* remember the first byte */
@@ -563,7 +563,7 @@ static CURLcode mqtt_doing(struct connectdata *conn, bool *done)
   case MQTT_REMAINING_LENGTH:
     do {
       result = Curl_read(conn, sockfd, (char *)&byte, 1, &nread);
-      if(result)
+      if(!nread)
         break;
       Curl_debug(data, CURLINFO_HEADER_IN, (char *)&byte, 1);
       pkt[mq->npacket++] = byte;