mirror of
https://github.com/moparisthebest/curl
synced 2024-11-04 16:45:06 -05:00
lib: remove strlen call from Curl_client_write
At all call sites with an explicit 0 len, pass an appropriate nonzero len. Closes #6954
This commit is contained in:
parent
6aae7b1761
commit
f4b85d24b2
12
lib/file.c
12
lib/file.c
@ -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;
|
||||
}
|
||||
@ -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,
|
||||
@ -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 */
|
||||
|
13
lib/ftp.c
13
lib/ftp.c
@ -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;
|
||||
@ -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,
|
||||
@ -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 */
|
||||
@ -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;
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
@ -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;
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user