Skip to content

Commit

Permalink
Fix 0-length Curl_client_write calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsha committed Apr 28, 2021
1 parent f303d7e commit e9da118
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/content_encoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions lib/pop3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/sendf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/transfer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
Expand Down

0 comments on commit e9da118

Please sign in to comment.