aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Landau <hlandau@openssl.org>2024-02-12 10:06:23 +0000
committerTomas Mraz <tomas@openssl.org>2024-02-19 10:15:46 +0100
commit5fd1f46fb054ef583e070dd15d1b76e0f0fc910b (patch)
tree09d71bbf9712cfbb23d19dcd4fbe835ff3fcaef7
parente825599213119b8ff56b4bb4df40b898dd68572e (diff)
downloadopenssl-5fd1f46fb054ef583e070dd15d1b76e0f0fc910b.tar.gz
JSON_ENC: Ensure ossl_json_flush() really flushes the BIO
Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/23535)
-rw-r--r--ssl/quic/json_enc.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ssl/quic/json_enc.c b/ssl/quic/json_enc.c
index da698c2222..5222a4560e 100644
--- a/ssl/quic/json_enc.c
+++ b/ssl/quic/json_enc.c
@@ -16,7 +16,7 @@
* wbuf
* ====
*/
-static int wbuf_flush(struct json_write_buf *wbuf);
+static int wbuf_flush(struct json_write_buf *wbuf, int full);
static int wbuf_init(struct json_write_buf *wbuf, BIO *bio, size_t alloc)
{
@@ -58,7 +58,7 @@ static ossl_inline size_t wbuf_avail(struct json_write_buf *wbuf)
static ossl_inline int wbuf_write_char(struct json_write_buf *wbuf, char c)
{
if (wbuf_avail(wbuf) == 0) {
- if (!wbuf_flush(wbuf))
+ if (!wbuf_flush(wbuf, /*full=*/0))
return 0;
}
@@ -81,7 +81,7 @@ static int wbuf_write_str(struct json_write_buf *wbuf, const char *s)
}
/* Flush write buffer, returning 0 on I/O failure. */
-static int wbuf_flush(struct json_write_buf *wbuf)
+static int wbuf_flush(struct json_write_buf *wbuf, int full)
{
size_t written = 0, total_written = 0;
@@ -101,6 +101,10 @@ static int wbuf_flush(struct json_write_buf *wbuf)
}
wbuf->cur = 0;
+
+ if (full)
+ (void)BIO_flush(wbuf->bio); /* best effort */
+
return 1;
}
@@ -270,7 +274,7 @@ int ossl_json_reset(OSSL_JSON_ENC *json)
int ossl_json_flush(OSSL_JSON_ENC *json)
{
- return wbuf_flush(&json->wbuf);
+ return wbuf_flush(&json->wbuf, /*full=*/1);
}
int ossl_json_set0_sink(OSSL_JSON_ENC *json, BIO *bio)