c-hyper: don't write to set.writeheader if null

Previously if a caller set CURLOPT_WRITEFUNCTION but did not set a
CURLOPT_HEADERDATA buffer, Hyper would still attempt to write headers to
the data->set.writeheader header buffer, even though it is null.  This
led to NPE segfaults attempting to use libcurl+Hyper with Git, for
example.

Instead, process the client write for the status line using the same
logic we use to process the client write for the later HTTP headers,
which contains the appropriate guard logic. As a side benefit,
data->set.writeheader is now only read in one file instead of two.

Fixes #6619
Fixes abetterinternet/crustls#49
Fixes hyperium/hyper#2438
Closes #6971
This commit is contained in:
Kevin Burke 2021-04-26 15:04:02 -07:00 коммит произвёл Daniel Stenberg
Родитель 9fc284427c
Коммит 76f33fd373
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 5CC908FDB71E12C2
1 изменённых файлов: 6 добавлений и 8 удалений

Просмотреть файл

@ -208,8 +208,6 @@ static CURLcode status_line(struct Curl_easy *data,
size_t wrote;
size_t len;
const char *vstr;
curl_write_callback writeheader =
data->set.fwrite_header? data->set.fwrite_header: data->set.fwrite_func;
vstr = http_version == HYPER_HTTP_VERSION_1_1 ? "1.1" :
(http_version == HYPER_HTTP_VERSION_2 ? "2" : "1.0");
conn->httpversion =
@ -232,12 +230,12 @@ static CURLcode status_line(struct Curl_easy *data,
len = Curl_dyn_len(&data->state.headerb);
Curl_debug(data, CURLINFO_HEADER_IN, Curl_dyn_ptr(&data->state.headerb),
len);
Curl_set_in_callback(data, true);
wrote = writeheader(Curl_dyn_ptr(&data->state.headerb), 1, len,
data->set.writeheader);
Curl_set_in_callback(data, false);
if(wrote != len)
return CURLE_WRITE_ERROR;
result = Curl_client_write(data, CLIENTWRITE_HEADER,
Curl_dyn_ptr(&data->state.headerb), len);
if(result) {
data->state.hresult = CURLE_ABORTED_BY_CALLBACK;
return HYPER_ITER_BREAK;
}
data->info.header_size += (long)len;
data->req.headerbytecount += (long)len;