summaryrefslogtreecommitdiffstats
path: root/crypto/http
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2021-01-25 16:18:40 +0100
committerDr. David von Oheimb <dev@ddvo.net>2021-02-02 07:54:37 +0100
commit673474b1640a0265530ad42868d1c8b7d33bef77 (patch)
tree50b286a7087dc0905e32c62ff055a7755cecf4a4 /crypto/http
parentf2db0528d8d7015ba39faca78a16e5e820db9df6 (diff)
OSSL_HTTP_REQ_CTX_nbio(): Revert to having state var that keeps req len still to send
Otherwise, sending goes wrong in case BIO_write(rctx->wbio, ...) is incomplete at first. Fixes #13938 Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/13960)
Diffstat (limited to 'crypto/http')
-rw-r--r--crypto/http/http_client.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c
index 6b627e15b0..b4dfcb8151 100644
--- a/crypto/http/http_client.c
+++ b/crypto/http/http_client.c
@@ -50,6 +50,7 @@ struct ossl_http_req_ctx_st {
int method_POST; /* HTTP method is "POST" (else "GET") */
const char *expected_ct; /* expected Content-Type, or NULL */
int expect_asn1; /* response must be ASN.1-encoded */
+ long len_to_send; /* number of bytes in request still to send */
unsigned long resp_len; /* length of response */
unsigned long max_resp_len; /* Maximum length of response */
time_t max_time; /* Maximum end time of the transfer, or 0 */
@@ -68,7 +69,7 @@ struct ossl_http_req_ctx_st {
#define OHS_HEADERS 2 /* MIME headers being read */
#define OHS_ASN1_HEADER 3 /* HTTP initial header (tag+length) being read */
#define OHS_CONTENT 4 /* HTTP content octets being read */
-#define OHS_WRITE_INIT (5 | OHS_NOREAD) /* 1st call: ready to start I/O */
+#define OHS_WRITE_INIT (5 | OHS_NOREAD) /* 1st call: ready to start send */
#define OHS_WRITE (6 | OHS_NOREAD) /* Request being sent */
#define OHS_FLUSH (7 | OHS_NOREAD) /* Request being flushed */
#define OHS_DONE (8 | OHS_NOREAD) /* Completed */
@@ -420,7 +421,7 @@ static int check_set_resp_len(OSSL_HTTP_REQ_CTX *rctx, unsigned long len)
int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
{
int i;
- long n, n_to_send = 0;
+ long n;
unsigned long resp_len;
const unsigned char *p;
char *key, *value, *line_end = NULL;
@@ -456,14 +457,13 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
/* fall thru */
case OHS_WRITE_INIT:
- n_to_send = BIO_get_mem_data(rctx->mem, NULL);
+ rctx->len_to_send = BIO_get_mem_data(rctx->mem, NULL);
rctx->state = OHS_WRITE;
/* fall thru */
case OHS_WRITE:
- n = BIO_get_mem_data(rctx->mem, &p);
-
- i = BIO_write(rctx->wbio, p + (n - n_to_send), n_to_send);
+ n = BIO_get_mem_data(rctx->mem, &p) - rctx->len_to_send;
+ i = BIO_write(rctx->wbio, p + n, rctx->len_to_send);
if (i <= 0) {
if (BIO_should_retry(rctx->wbio))
@@ -472,9 +472,9 @@ int OSSL_HTTP_REQ_CTX_nbio(OSSL_HTTP_REQ_CTX *rctx)
return 0;
}
- n_to_send -= i;
+ rctx->len_to_send -= i;
- if (n_to_send > 0)
+ if (rctx->len_to_send > 0)
goto next_io;
rctx->state = OHS_FLUSH;