]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
lib: fix 0-length Curl_client_write calls
authorJacob Hoffman-Andrews <github@hoffman-andrews.com>
Tue, 27 Apr 2021 22:48:01 +0000 (15:48 -0700)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 29 Apr 2021 13:02:32 +0000 (15:02 +0200)
Closes #6954

lib/content_encoding.c
lib/pop3.c
lib/sendf.c
lib/transfer.c

index 77814ac30247b2edc75d91ede6073e9b1ec59e05..a84ff543b92513f22c6fecd9ba08549b159591d4 100644 (file)
@@ -985,7 +985,8 @@ new_unencoding_writer(struct Curl_easy *data,
   return writer;
 }
 
-/* Write data using an unencoding writer stack. */
+/* Write data using an unencoding writer stack. "nbytes" is not
+   allowed to be 0. */
 CURLcode Curl_unencode_write(struct Curl_easy *data,
                              struct contenc_writer *writer,
                              const char *buf, size_t nbytes)
index ccfebd02af2ff05bf875b7b0369d11471ad125d5..275ffeada9236dc324d9fac6767bf489b066c22c 100644 (file)
@@ -1515,8 +1515,17 @@ CURLcode Curl_pop3_write(struct Curl_easy *data, char *str, size_t nread)
       if(prev) {
         /* If the partial match was the CRLF and dot then only write the CRLF
            as the server would have inserted the dot */
-        result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)POP3_EOB,
-                                   strip_dot ? prev - 1 : prev);
+        if(strip_dot && prev - 1 > 0) {
+          result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)POP3_EOB,
+                                     prev - 1);
+        }
+        else if(!strip_dot) {
+          result = Curl_client_write(data, CLIENTWRITE_BODY, (char *)POP3_EOB,
+                                     prev);
+        }
+        else {
+          result = CURLE_OK;
+        }
 
         if(result)
           return result;
index 17d3d51e36bc40190a6fde05ec9054c18e18474d..fa3c5a35d40589375640e31a926671d225d88b28 100644 (file)
@@ -604,7 +604,7 @@ static CURLcode chop_write(struct Curl_easy *data,
 /* Curl_client_write() sends data to the write callback(s)
 
    The bit pattern defines to what "streams" to write to. Body and/or header.
-   The defines are in sendf.h of course.
+   The defines are in sendf.h of course. "len" is not allowed to be 0.
 
    If CURL_DO_LINEEND_CONV is enabled, data is converted IN PLACE to the
    local character encoding.  This is a problem and should be changed in
index 56ad5e612eac0aab41c87b56483c9398aaeed8d5..c31e22e00caddf0138373f49818181dd39fae7b0 100644 (file)
@@ -830,7 +830,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
              Make sure that ALL_CONTENT_ENCODINGS contains all the
              encodings handled here. */
           if(data->set.http_ce_skip || !k->writer_stack) {
-            if(!k->ignorebody) {
+            if(!k->ignorebody && nread) {
 #ifndef CURL_DISABLE_POP3
               if(conn->handler->protocol & PROTO_FAMILY_POP3)
                 result = Curl_pop3_write(data, k->str, nread);
@@ -840,7 +840,7 @@ static CURLcode readwrite_data(struct Curl_easy *data,
                                            nread);
             }
           }
-          else if(!k->ignorebody)
+          else if(!k->ignorebody && nread)
             result = Curl_unencode_write(data, k->writer_stack, k->str, nread);
         }
         k->badheader = HEADER_NORMAL; /* taken care of now */