Skip to content

Commit

Permalink
Remove strlen call from Curl_client_write.
Browse files Browse the repository at this point in the history
At all call sites with an explicit 0 len, pass an appropriate nonzero
len.
  • Loading branch information
jsha committed Apr 25, 2021
1 parent 67d3afa commit 994f59b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
12 changes: 7 additions & 5 deletions lib/file.c
Expand Up @@ -410,16 +410,18 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
struct tm buffer;
const struct tm *tm = &buffer;
char header[80];
int headerlen;
char accept_ranges[24]= { "Accept-ranges: bytes\r\n" };
if(expected_size >= 0) {
msnprintf(header, sizeof(header),
headerlen = msnprintf(header, sizeof(header),
"Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n",
expected_size);
result = Curl_client_write(data, CLIENTWRITE_HEADER, header, 0);
result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen);
if(result)
return result;

result = Curl_client_write(data, CLIENTWRITE_HEADER,
(char *)"Accept-ranges: bytes\r\n", 0);
accept_ranges, strlen(accept_ranges));
if(result != CURLE_OK)
return result;
}
Expand All @@ -430,7 +432,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
return result;

/* format: "Tue, 15 Nov 1994 12:45:26 GMT" */
msnprintf(header, sizeof(header),
headerlen = msnprintf(header, sizeof(header),
"Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n%s",
Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
tm->tm_mday,
Expand All @@ -440,7 +442,7 @@ static CURLcode file_do(struct Curl_easy *data, bool *done)
tm->tm_min,
tm->tm_sec,
data->set.opt_no_body ? "": "\r\n");
result = Curl_client_write(data, CLIENTWRITE_HEADER, header, 0);
result = Curl_client_write(data, CLIENTWRITE_HEADER, header, headerlen);
if(result)
return result;
/* set the file size to make it available post transfer */
Expand Down
13 changes: 8 additions & 5 deletions lib/ftp.c
Expand Up @@ -2098,6 +2098,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data,
data->set.get_filetime &&
(data->info.filetime >= 0) ) {
char headerbuf[128];
int headerbuflen;
time_t filetime = data->info.filetime;
struct tm buffer;
const struct tm *tm = &buffer;
Expand All @@ -2107,7 +2108,7 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data,
return result;

/* format: "Tue, 15 Nov 1994 12:45:26" */
msnprintf(headerbuf, sizeof(headerbuf),
headerbuflen = msnprintf(headerbuf, sizeof(headerbuf),
"Last-Modified: %s, %02d %s %4d %02d:%02d:%02d GMT\r\n",
Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
tm->tm_mday,
Expand All @@ -2116,7 +2117,8 @@ static CURLcode ftp_state_mdtm_resp(struct Curl_easy *data,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
result = Curl_client_write(data, CLIENTWRITE_BOTH, headerbuf, 0);
result = Curl_client_write(data, CLIENTWRITE_BOTH, headerbuf,
headerbuflen);
if(result)
return result;
} /* end of a ridiculous amount of conditionals */
Expand Down Expand Up @@ -2321,9 +2323,9 @@ static CURLcode ftp_state_size_resp(struct Curl_easy *data,
#ifdef CURL_FTP_HTTPSTYLE_HEAD
if(-1 != filesize) {
char clbuf[128];
msnprintf(clbuf, sizeof(clbuf),
int clbuflen = msnprintf(clbuf, sizeof(clbuf),
"Content-Length: %" CURL_FORMAT_CURL_OFF_T "\r\n", filesize);
result = Curl_client_write(data, CLIENTWRITE_BOTH, clbuf, 0);
result = Curl_client_write(data, CLIENTWRITE_BOTH, clbuf, clbuflen);
if(result)
return result;
}
Expand Down Expand Up @@ -2357,7 +2359,8 @@ static CURLcode ftp_state_rest_resp(struct Curl_easy *data,
#ifdef CURL_FTP_HTTPSTYLE_HEAD
if(ftpcode == 350) {
char buffer[24]= { "Accept-ranges: bytes\r\n" };
result = Curl_client_write(data, CLIENTWRITE_BOTH, buffer, 0);
result = Curl_client_write(data, CLIENTWRITE_BOTH, buffer,
strlen(buffer));
if(result)
return result;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/openldap.c
Expand Up @@ -666,7 +666,7 @@ static ssize_t ldap_recv(struct Curl_easy *data, int sockindex, char *buf,

data->req.bytecount += bvals[i].bv_len + 1;
}
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
if(writeerr) {
*err = writeerr;
return -1;
Expand All @@ -675,14 +675,14 @@ static ssize_t ldap_recv(struct Curl_easy *data, int sockindex, char *buf,
data->req.bytecount++;
}
ber_memfree(bvals);
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
if(writeerr) {
*err = writeerr;
return -1;
}
data->req.bytecount++;
}
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 0);
writeerr = Curl_client_write(data, CLIENTWRITE_BODY, (char *)"\n", 1);
if(writeerr) {
*err = writeerr;
return -1;
Expand Down
3 changes: 1 addition & 2 deletions lib/sendf.c
Expand Up @@ -616,9 +616,8 @@ CURLcode Curl_client_write(struct Curl_easy *data,
size_t len)
{
struct connectdata *conn = data->conn;
if(0 == len)
len = strlen(ptr);

DEBUGASSERT(len);
DEBUGASSERT(type <= 3);

/* FTP data may need conversion. */
Expand Down

0 comments on commit 994f59b

Please sign in to comment.