Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle missing Content-Length in client #125

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/est/est_client_http.c
Original file line number Diff line number Diff line change
Expand Up @@ -1457,8 +1457,7 @@ static EST_ERROR est_io_check_http_hdrs (HTTP_HEADER *hdrs, int hdr_cnt,
return EST_ERR_HTTP_UNSUPPORTED;
}
if (content_length_present == 0) {
EST_LOG_ERR("Missing HTTP content length header");
return EST_ERR_HTTP_UNSUPPORTED;
EST_LOG_INFO("Missing HTTP content length header");
}

return EST_ERR_NONE;
Expand Down Expand Up @@ -1557,6 +1556,7 @@ EST_ERROR est_io_get_response_internal (EST_CTX *ctx, SSL *ssl, EST_OPERATION op
unsigned char *raw_buf = NULL, *payload_skip_extra = NULL;
unsigned char *payload, *payload_buf;
int raw_len = 0;
int body_len;
errno_t safec_rc;


Expand Down Expand Up @@ -1763,6 +1763,15 @@ EST_ERROR est_io_get_response_internal (EST_CTX *ctx, SSL *ssl, EST_OPERATION op
*/
rv = est_io_check_http_hdrs(hdrs, hdr_cnt, op, cert_buf_len);
if (rv == EST_ERR_NONE) {
body_len = (raw_len + raw_buf) - payload;

if (*cert_buf_len == -1) {
/*
* Connection is being closed. Allocate just enough
* for the body we have received.
*/
*cert_buf_len = body_len;
}

EST_LOG_INFO("HTTP Content len=%d", *cert_buf_len);

Expand All @@ -1778,7 +1787,7 @@ EST_ERROR est_io_get_response_internal (EST_CTX *ctx, SSL *ssl, EST_OPERATION op
rv = EST_ERR_HTTP_UNSUPPORTED;
*cert_buf_len = 0;
*cert_buf = NULL;
} else if (*cert_buf_len != (raw_len + raw_buf) - payload) {
} else if (*cert_buf_len != body_len) {
EST_LOG_ERR(
"Content Length (%d) and body length (%d) mismatch.",
*cert_buf_len, (raw_len + raw_buf) - payload);
Expand Down