]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
b64_ctrl(): Do not try to call EVP_Encode functions when not writing
authorTomas Mraz <tomas@openssl.org>
Mon, 5 Jan 2026 17:22:30 +0000 (18:22 +0100)
committerMatt Caswell <matt@openssl.org>
Mon, 19 Jan 2026 14:15:22 +0000 (14:15 +0000)
The BIO_CTRL_FLUSH should just forward the call to the underlying
BIOs when not writing.

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Paul Dale <paul.dale@oracle.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
MergeDate: Mon Jan 19 14:20:35 2026
(Merged from https://github.com/openssl/openssl/pull/29550)

crypto/evp/bio_b64.c

index 2eab67caba72b98b535d1ac6db36d17a3148c126..20cf570fe35b2615459b9cf65dcd9a83c564d7a4 100644 (file)
@@ -469,19 +469,20 @@ static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
             ret = BIO_ctrl(next, cmd, num, ptr);
         break;
     case BIO_CTRL_FLUSH:
-        /* do a final write */
-    again:
-        while (ctx->buf_len != ctx->buf_off) {
-            i = b64_write(b, NULL, 0);
-            if (i < 0)
-                return i;
-        }
-        if (ctx->encode != B64_NONE
-            && EVP_ENCODE_CTX_num(ctx->base64) != 0) {
-            ctx->buf_off = 0;
-            EVP_EncodeFinal(ctx->base64, ctx->buf, &(ctx->buf_len));
-            /* push out the bytes */
-            goto again;
+        if (ctx->encode == B64_ENCODE) {
+            /* do a final write */
+        again:
+            while (ctx->buf_len != ctx->buf_off) {
+                i = b64_write(b, NULL, 0);
+                if (i < 0)
+                    return i;
+            }
+            if (EVP_ENCODE_CTX_num(ctx->base64) != 0) {
+                ctx->buf_off = 0;
+                EVP_EncodeFinal(ctx->base64, ctx->buf, &(ctx->buf_len));
+                /* push out the bytes */
+                goto again;
+            }
         }
         /* Finally flush the underlying BIO */
         ret = BIO_ctrl(next, cmd, num, ptr);