summaryrefslogtreecommitdiffstats
path: root/crypto/http/http_client.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2022-07-11 13:52:01 +0200
committerDr. David von Oheimb <dev@ddvo.net>2022-07-14 10:20:21 +0200
commitcf56f4425708a1ad8af8aede104a5e1c0294aafd (patch)
tree12257e7d61cda1b8aab9b80a101bc02c086167f7 /crypto/http/http_client.c
parent3c85170e1c2d67ca7fac84af1cfd5cb33fc24abc (diff)
http_client.c: 2nd fix for calculation of Content-Length in set1_content()
Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> (Merged from https://github.com/openssl/openssl/pull/18779) (cherry picked from commit 8c65e1f719ecf7ec7ed3094bbd763f88708d26eb)
Diffstat (limited to 'crypto/http/http_client.c')
-rw-r--r--crypto/http/http_client.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/crypto/http/http_client.c b/crypto/http/http_client.c
index 08e726013c..0d62f1c7bf 100644
--- a/crypto/http/http_client.c
+++ b/crypto/http/http_client.c
@@ -266,8 +266,10 @@ int OSSL_HTTP_REQ_CTX_set_expected(OSSL_HTTP_REQ_CTX *rctx,
static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
const char *content_type, BIO *req)
{
- long req_len;
+ long req_len = 0;
+#ifndef OPENSSL_NO_STDIO
FILE *fp = NULL;
+#endif
if (rctx == NULL || (req == NULL && content_type != NULL)) {
ERR_raise(ERR_LIB_HTTP, ERR_R_PASSED_NULL_PARAMETER);
@@ -295,10 +297,15 @@ static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
* BIO_CTRL_INFO yields the data length at least for memory BIOs, but for
* file-based BIOs it gives the current position, which is not what we need.
*/
- if (BIO_get_fp(req, &fp) == 1) {
- fseek(fp, 0, SEEK_END);
- req_len = ftell(fp);
- fseek(fp, 0, SEEK_SET);
+ if (BIO_method_type(req) == BIO_TYPE_FILE) {
+#ifndef OPENSSL_NO_STDIO
+ if (BIO_get_fp(req, &fp) == 1 && fseek(fp, 0, SEEK_END) == 0) {
+ req_len = ftell(fp);
+ (void)fseek(fp, 0, SEEK_SET);
+ } else {
+ fp = NULL;
+ }
+#endif
} else {
req_len = BIO_ctrl(req, BIO_CTRL_INFO, 0, NULL);
/*
@@ -306,7 +313,11 @@ static int set1_content(OSSL_HTTP_REQ_CTX *rctx,
* and we assume we got a correct value if req_len > 0.
*/
}
- if ((fp != NULL /* definitely correct req_len */ || req_len > 0)
+ if ((
+#ifndef OPENSSL_NO_STDIO
+ fp != NULL /* definitely correct req_len */ ||
+#endif
+ req_len > 0)
&& BIO_printf(rctx->mem, "Content-Length: %ld\r\n", req_len) < 0)
return 0;