Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/crypto/evp/bio_b64.c
Line
Count
Source
1
/*
2
 * Copyright 1995-2025 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
#include <stdio.h>
11
#include <errno.h>
12
#include "internal/cryptlib.h"
13
#include <openssl/buffer.h>
14
#include <openssl/evp.h>
15
#include "internal/bio.h"
16
17
static int b64_write(BIO *h, const char *buf, int num);
18
static int b64_read(BIO *h, char *buf, int size);
19
static int b64_puts(BIO *h, const char *str);
20
static long b64_ctrl(BIO *h, int cmd, long arg1, void *arg2);
21
static int b64_new(BIO *h);
22
static int b64_free(BIO *data);
23
static long b64_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
24
158k
#define B64_BLOCK_SIZE 1024
25
#define B64_BLOCK_SIZE2 768
26
9.71k
#define B64_NONE 0
27
2.07k
#define B64_ENCODE 1
28
2.44M
#define B64_DECODE 2
29
30
typedef struct b64_struct {
31
    /*
32
     * BIO *bio; moved to the BIO structure
33
     */
34
    int buf_len;
35
    int buf_off;
36
    int tmp_len; /* used to find the start when decoding */
37
    int tmp_nl; /* If true, scan until '\n' */
38
    int encode;
39
    int start; /* have we started decoding yet? */
40
    int cont; /* <= 0 when finished */
41
    EVP_ENCODE_CTX *base64;
42
    unsigned char buf[EVP_ENCODE_LENGTH(B64_BLOCK_SIZE) + 10];
43
    unsigned char tmp[B64_BLOCK_SIZE];
44
} BIO_B64_CTX;
45
46
static const BIO_METHOD methods_b64 = {
47
    BIO_TYPE_BASE64,
48
    "base64 encoding",
49
    bwrite_conv,
50
    b64_write,
51
    bread_conv,
52
    b64_read,
53
    b64_puts,
54
    NULL, /* b64_gets, */
55
    b64_ctrl,
56
    b64_new,
57
    b64_free,
58
    b64_callback_ctrl,
59
};
60
61
const BIO_METHOD *BIO_f_base64(void)
62
12.3k
{
63
12.3k
    return &methods_b64;
64
12.3k
}
65
66
static int b64_new(BIO *bi)
67
12.3k
{
68
12.3k
    BIO_B64_CTX *ctx;
69
70
12.3k
    if ((ctx = OPENSSL_zalloc(sizeof(*ctx))) == NULL)
71
0
        return 0;
72
73
12.3k
    ctx->cont = 1;
74
12.3k
    ctx->start = 1;
75
12.3k
    ctx->base64 = EVP_ENCODE_CTX_new();
76
12.3k
    if (ctx->base64 == NULL) {
77
0
        OPENSSL_free(ctx);
78
0
        return 0;
79
0
    }
80
81
12.3k
    BIO_set_data(bi, ctx);
82
12.3k
    BIO_set_init(bi, 1);
83
84
12.3k
    return 1;
85
12.3k
}
86
87
static int b64_free(BIO *a)
88
12.3k
{
89
12.3k
    BIO_B64_CTX *ctx;
90
91
12.3k
    if (a == NULL)
92
0
        return 0;
93
94
12.3k
    ctx = BIO_get_data(a);
95
12.3k
    if (ctx == NULL)
96
0
        return 0;
97
98
12.3k
    EVP_ENCODE_CTX_free(ctx->base64);
99
12.3k
    OPENSSL_free(ctx);
100
12.3k
    BIO_set_data(a, NULL);
101
12.3k
    BIO_set_init(a, 0);
102
103
12.3k
    return 1;
104
12.3k
}
105
106
/*
107
 * Unless `BIO_FLAGS_BASE64_NO_NL` is set, this BIO ignores leading lines that
108
 * aren't exclusively composed of valid Base64 characters (followed by <CRLF>
109
 * or <LF>).  Once a valid Base64 line is found, `ctx->start` is set to 0 and
110
 * lines are processed until EOF or the first line that contains invalid Base64
111
 * characters.  In a nod to PEM, lines that start with a '-' (hyphen) are
112
 * treated as a soft EOF, rather than an error.
113
 */
114
static int b64_read(BIO *b, char *out, int outl)
115
2.43M
{
116
2.43M
    int ret = 0, i, ii, j, k, x, n, num, ret_code;
117
2.43M
    BIO_B64_CTX *ctx;
118
2.43M
    unsigned char *p, *q;
119
2.43M
    BIO *next;
120
121
2.43M
    if (out == NULL)
122
0
        return 0;
123
2.43M
    ctx = (BIO_B64_CTX *)BIO_get_data(b);
124
125
2.43M
    next = BIO_next(b);
126
2.43M
    if (ctx == NULL || next == NULL)
127
0
        return 0;
128
129
2.43M
    BIO_clear_retry_flags(b);
130
131
2.43M
    if (ctx->encode != B64_DECODE) {
132
4.72k
        ctx->encode = B64_DECODE;
133
4.72k
        ctx->buf_len = 0;
134
4.72k
        ctx->buf_off = 0;
135
4.72k
        ctx->tmp_len = 0;
136
4.72k
        EVP_DecodeInit(ctx->base64);
137
4.72k
    }
138
139
    /* First check if there are buffered bytes already decoded */
140
2.43M
    if (ctx->buf_len > 0) {
141
2.42M
        if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
142
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
143
0
            return -1;
144
0
        }
145
2.42M
        i = ctx->buf_len - ctx->buf_off;
146
2.42M
        if (i > outl)
147
2.39M
            i = outl;
148
2.42M
        if (!ossl_assert(ctx->buf_off + i < (int)sizeof(ctx->buf))) {
149
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
150
0
            return -1;
151
0
        }
152
2.42M
        memcpy(out, &(ctx->buf[ctx->buf_off]), i);
153
2.42M
        ret = i;
154
2.42M
        out += i;
155
2.42M
        outl -= i;
156
2.42M
        ctx->buf_off += i;
157
2.42M
        if (ctx->buf_len == ctx->buf_off) {
158
27.9k
            ctx->buf_len = 0;
159
27.9k
            ctx->buf_off = 0;
160
27.9k
        }
161
2.42M
    }
162
163
    /* Restore any non-retriable error condition (ctx->cont < 0) */
164
2.43M
    ret_code = ctx->cont < 0 ? ctx->cont : 0;
165
166
    /*
167
     * At this point, we have room of outl bytes and an either an empty buffer,
168
     * or outl == 0, so we'll attempt to read in some more.
169
     */
170
2.49M
    while (outl > 0) {
171
60.3k
        int again = ctx->cont;
172
173
60.3k
        if (again <= 0)
174
1.65k
            break;
175
176
58.7k
        i = BIO_read(next, &(ctx->tmp[ctx->tmp_len]),
177
58.7k
            B64_BLOCK_SIZE - ctx->tmp_len);
178
179
58.7k
        if (i <= 0) {
180
3.22k
            ret_code = i;
181
182
            /* Should we continue next time we are called? */
183
3.22k
            if (!BIO_should_retry(next)) {
184
                /* Incomplete final Base64 chunk in the decoder is an error */
185
3.22k
                if (ctx->tmp_len == 0) {
186
1.21k
                    if (EVP_DecodeFinal(ctx->base64, NULL, &num) < 0)
187
236
                        ret_code = -1;
188
1.21k
                    EVP_DecodeInit(ctx->base64);
189
1.21k
                }
190
3.22k
                ctx->cont = ret_code;
191
3.22k
            }
192
3.22k
            if (ctx->tmp_len == 0)
193
1.21k
                break;
194
            /* Fall through and process what we have */
195
2.01k
            i = 0;
196
            /* But don't loop to top-up even if the buffer is not full! */
197
2.01k
            again = 0;
198
2.01k
        }
199
200
57.5k
        i += ctx->tmp_len;
201
57.5k
        ctx->tmp_len = i;
202
203
        /*
204
         * We need to scan, a line at a time until we have a valid line if we
205
         * are starting.
206
         */
207
57.5k
        if (ctx->start && (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) != 0) {
208
0
            ctx->tmp_len = 0;
209
57.5k
        } else if (ctx->start) {
210
8.24k
            q = p = ctx->tmp;
211
8.24k
            num = 0;
212
3.75M
            for (j = 0; j < i; j++) {
213
3.74M
                if (*(q++) != '\n')
214
3.53M
                    continue;
215
216
                /*
217
                 * due to a previous very long line, we need to keep on
218
                 * scanning for a '\n' before we even start looking for
219
                 * base64 encoded stuff.
220
                 */
221
210k
                if (ctx->tmp_nl) {
222
975
                    p = q;
223
975
                    ctx->tmp_nl = 0;
224
975
                    continue;
225
975
                }
226
227
209k
                k = EVP_DecodeUpdate(ctx->base64, ctx->buf, &num, p, (int)(q - p));
228
209k
                EVP_DecodeInit(ctx->base64);
229
209k
                if (k <= 0 && num == 0) {
230
204k
                    p = q;
231
204k
                    continue;
232
204k
                }
233
234
4.46k
                ctx->start = 0;
235
4.46k
                if (p != ctx->tmp) {
236
551
                    i -= (int)(p - ctx->tmp);
237
411k
                    for (x = 0; x < i; x++)
238
411k
                        ctx->tmp[x] = p[x];
239
551
                }
240
4.46k
                break;
241
209k
            }
242
243
            /* we fell off the end without starting */
244
8.24k
            if (ctx->start) {
245
                /*
246
                 * Is this is one long chunk?, if so, keep on reading until a
247
                 * new line.
248
                 */
249
3.78k
                if (p == ctx->tmp) {
250
                    /* Check buffer full */
251
1.60k
                    if (i == B64_BLOCK_SIZE) {
252
1.39k
                        ctx->tmp_nl = 1;
253
1.39k
                        ctx->tmp_len = 0;
254
1.39k
                    }
255
2.17k
                } else if (p != q) {
256
                    /* Retain partial line at end of buffer */
257
1.63k
                    n = (int)(q - p);
258
1.17M
                    for (ii = 0; ii < n; ii++)
259
1.17M
                        ctx->tmp[ii] = p[ii];
260
1.63k
                    ctx->tmp_len = n;
261
1.63k
                } else {
262
                    /* All we have is newline terminated non-start data */
263
540
                    ctx->tmp_len = 0;
264
540
                }
265
                /*
266
                 * Try to read more if possible, otherwise we can't make
267
                 * progress unless the underlying BIO is retriable and may
268
                 * produce more data next time we're called.
269
                 */
270
3.78k
                if (again > 0)
271
3.64k
                    continue;
272
135
                else
273
135
                    break;
274
4.46k
            } else {
275
4.46k
                ctx->tmp_len = 0;
276
4.46k
            }
277
49.2k
        } else if (i < B64_BLOCK_SIZE && again > 0) {
278
            /*
279
             * If buffer isn't full and we can retry then restart to read in
280
             * more data.
281
             */
282
1.87k
            continue;
283
1.87k
        }
284
285
51.8k
        i = EVP_DecodeUpdate(ctx->base64, ctx->buf, &ctx->buf_len,
286
51.8k
            ctx->tmp, i);
287
51.8k
        ctx->tmp_len = 0;
288
        /*
289
         * If eof or an error was signalled, then the condition
290
         * 'ctx->cont <= 0' will prevent b64_read() from reading
291
         * more data on subsequent calls. This assignment was
292
         * deleted accidentally in commit 5562cfaca4f3.
293
         */
294
51.8k
        ctx->cont = i;
295
296
51.8k
        ctx->buf_off = 0;
297
51.8k
        if (i < 0) {
298
157
            ret_code = ctx->start ? 0 : i;
299
157
            ctx->buf_len = 0;
300
157
            break;
301
157
        }
302
303
51.6k
        if (ctx->buf_len <= outl)
304
21.5k
            i = ctx->buf_len;
305
30.1k
        else
306
30.1k
            i = outl;
307
308
51.6k
        memcpy(out, ctx->buf, i);
309
51.6k
        ret += i;
310
51.6k
        ctx->buf_off = i;
311
51.6k
        if (ctx->buf_off == ctx->buf_len) {
312
21.5k
            ctx->buf_len = 0;
313
21.5k
            ctx->buf_off = 0;
314
21.5k
        }
315
51.6k
        outl -= i;
316
51.6k
        out += i;
317
51.6k
    }
318
    /* BIO_clear_retry_flags(b); */
319
2.43M
    BIO_copy_next_retry(b);
320
2.43M
    return ret == 0 ? ret_code : ret;
321
2.43M
}
322
323
static int b64_write(BIO *b, const char *in, int inl)
324
1.03k
{
325
1.03k
    int ret = 0;
326
1.03k
    int n;
327
1.03k
    int i;
328
1.03k
    BIO_B64_CTX *ctx;
329
1.03k
    BIO *next;
330
331
1.03k
    ctx = (BIO_B64_CTX *)BIO_get_data(b);
332
1.03k
    next = BIO_next(b);
333
1.03k
    if (ctx == NULL || next == NULL)
334
0
        return 0;
335
336
1.03k
    BIO_clear_retry_flags(b);
337
338
1.03k
    if (ctx->encode != B64_ENCODE) {
339
1.03k
        ctx->encode = B64_ENCODE;
340
1.03k
        ctx->buf_len = 0;
341
1.03k
        ctx->buf_off = 0;
342
1.03k
        ctx->tmp_len = 0;
343
1.03k
        EVP_EncodeInit(ctx->base64);
344
1.03k
    }
345
1.03k
    if (!ossl_assert(ctx->buf_off < (int)sizeof(ctx->buf))) {
346
0
        ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
347
0
        return -1;
348
0
    }
349
1.03k
    if (!ossl_assert(ctx->buf_len <= (int)sizeof(ctx->buf))) {
350
0
        ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
351
0
        return -1;
352
0
    }
353
1.03k
    if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
354
0
        ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
355
0
        return -1;
356
0
    }
357
1.03k
    n = ctx->buf_len - ctx->buf_off;
358
1.03k
    while (n > 0) {
359
0
        i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
360
0
        if (i <= 0) {
361
0
            BIO_copy_next_retry(b);
362
0
            return i;
363
0
        }
364
0
        ctx->buf_off += i;
365
0
        if (!ossl_assert(ctx->buf_off <= (int)sizeof(ctx->buf))) {
366
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
367
0
            return -1;
368
0
        }
369
0
        if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
370
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
371
0
            return -1;
372
0
        }
373
0
        n -= i;
374
0
    }
375
    /* at this point all pending data has been written */
376
1.03k
    ctx->buf_off = 0;
377
1.03k
    ctx->buf_len = 0;
378
379
1.03k
    if (in == NULL || inl <= 0)
380
1.03k
        return 0;
381
382
0
    while (inl > 0) {
383
0
        n = inl > B64_BLOCK_SIZE ? B64_BLOCK_SIZE : inl;
384
385
0
        if ((BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) != 0) {
386
0
            if (ctx->tmp_len > 0) {
387
0
                if (!ossl_assert(ctx->tmp_len <= 3)) {
388
0
                    ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
389
0
                    return ret == 0 ? -1 : ret;
390
0
                }
391
0
                n = 3 - ctx->tmp_len;
392
                /*
393
                 * There's a theoretical possibility for this
394
                 */
395
0
                if (n > inl)
396
0
                    n = inl;
397
0
                memcpy(&(ctx->tmp[ctx->tmp_len]), in, n);
398
0
                ctx->tmp_len += n;
399
0
                ret += n;
400
0
                if (ctx->tmp_len < 3)
401
0
                    break;
402
0
                ctx->buf_len = EVP_EncodeBlock(ctx->buf, ctx->tmp, ctx->tmp_len);
403
0
                if (!ossl_assert(ctx->buf_len <= (int)sizeof(ctx->buf))) {
404
0
                    ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
405
0
                    return ret == 0 ? -1 : ret;
406
0
                }
407
0
                if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
408
0
                    ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
409
0
                    return ret == 0 ? -1 : ret;
410
0
                }
411
                /*
412
                 * Since we're now done using the temporary buffer, the
413
                 * length should be 0'd
414
                 */
415
0
                ctx->tmp_len = 0;
416
0
            } else {
417
0
                if (n < 3) {
418
0
                    memcpy(ctx->tmp, in, n);
419
0
                    ctx->tmp_len = n;
420
0
                    ret += n;
421
0
                    break;
422
0
                }
423
0
                n -= n % 3;
424
0
                ctx->buf_len = EVP_EncodeBlock(ctx->buf, (unsigned char *)in, n);
425
0
                if (!ossl_assert(ctx->buf_len <= (int)sizeof(ctx->buf))) {
426
0
                    ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
427
0
                    return ret == 0 ? -1 : ret;
428
0
                }
429
0
                if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
430
0
                    ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
431
0
                    return ret == 0 ? -1 : ret;
432
0
                }
433
0
                ret += n;
434
0
            }
435
0
        } else {
436
0
            if (!EVP_EncodeUpdate(ctx->base64, ctx->buf, &ctx->buf_len,
437
0
                    (unsigned char *)in, n))
438
0
                return ret == 0 ? -1 : ret;
439
0
            if (!ossl_assert(ctx->buf_len <= (int)sizeof(ctx->buf))) {
440
0
                ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
441
0
                return ret == 0 ? -1 : ret;
442
0
            }
443
0
            if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
444
0
                ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
445
0
                return ret == 0 ? -1 : ret;
446
0
            }
447
0
            ret += n;
448
0
        }
449
0
        inl -= n;
450
0
        in += n;
451
452
0
        ctx->buf_off = 0;
453
0
        n = ctx->buf_len;
454
0
        while (n > 0) {
455
0
            i = BIO_write(next, &(ctx->buf[ctx->buf_off]), n);
456
0
            if (i <= 0) {
457
0
                BIO_copy_next_retry(b);
458
0
                return ret == 0 ? i : ret;
459
0
            }
460
0
            n -= i;
461
0
            ctx->buf_off += i;
462
0
            if (!ossl_assert(ctx->buf_off <= (int)sizeof(ctx->buf))) {
463
0
                ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
464
0
                return ret == 0 ? -1 : ret;
465
0
            }
466
0
            if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
467
0
                ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
468
0
                return ret == 0 ? -1 : ret;
469
0
            }
470
0
        }
471
0
        ctx->buf_len = 0;
472
0
        ctx->buf_off = 0;
473
0
    }
474
0
    return ret;
475
0
}
476
477
static long b64_ctrl(BIO *b, int cmd, long num, void *ptr)
478
14.1k
{
479
14.1k
    BIO_B64_CTX *ctx;
480
14.1k
    long ret = 1;
481
14.1k
    int i;
482
14.1k
    BIO *next;
483
484
14.1k
    ctx = (BIO_B64_CTX *)BIO_get_data(b);
485
14.1k
    next = BIO_next(b);
486
14.1k
    if (ctx == NULL || next == NULL)
487
0
        return 0;
488
489
14.1k
    switch (cmd) {
490
0
    case BIO_CTRL_RESET:
491
0
        ctx->cont = 1;
492
0
        ctx->start = 1;
493
0
        ctx->encode = B64_NONE;
494
0
        ret = BIO_ctrl(next, cmd, num, ptr);
495
0
        break;
496
0
    case BIO_CTRL_EOF: /* More to read */
497
0
        if (ctx->cont <= 0)
498
0
            ret = 1;
499
0
        else
500
0
            ret = BIO_ctrl(next, cmd, num, ptr);
501
0
        break;
502
0
    case BIO_CTRL_WPENDING: /* More to write in buffer */
503
0
        if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
504
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
505
0
            return -1;
506
0
        }
507
0
        ret = ctx->buf_len - ctx->buf_off;
508
0
        if (ret == 0 && ctx->encode != B64_NONE
509
0
            && EVP_ENCODE_CTX_num(ctx->base64) != 0)
510
0
            ret = 1;
511
0
        else if (ret <= 0)
512
0
            ret = BIO_ctrl(next, cmd, num, ptr);
513
0
        break;
514
0
    case BIO_CTRL_PENDING: /* More to read in buffer */
515
0
        if (!ossl_assert(ctx->buf_len >= ctx->buf_off)) {
516
0
            ERR_raise(ERR_LIB_BIO, ERR_R_INTERNAL_ERROR);
517
0
            return -1;
518
0
        }
519
0
        ret = ctx->buf_len - ctx->buf_off;
520
0
        if (ret <= 0)
521
0
            ret = BIO_ctrl(next, cmd, num, ptr);
522
0
        break;
523
4.72k
    case BIO_CTRL_FLUSH:
524
        /* do a final write */
525
4.85k
    again:
526
7.13k
        while (ctx->buf_len != ctx->buf_off) {
527
2.28k
            i = b64_write(b, NULL, 0);
528
2.28k
            if (i < 0)
529
0
                return i;
530
2.28k
        }
531
4.85k
        if (BIO_get_flags(b) & BIO_FLAGS_BASE64_NO_NL) {
532
0
            if (ctx->tmp_len != 0) {
533
0
                ctx->buf_len = EVP_EncodeBlock(ctx->buf,
534
0
                    ctx->tmp, ctx->tmp_len);
535
0
                ctx->buf_off = 0;
536
0
                ctx->tmp_len = 0;
537
0
                goto again;
538
0
            }
539
4.85k
        } else if (ctx->encode != B64_NONE
540
4.85k
            && EVP_ENCODE_CTX_num(ctx->base64) != 0) {
541
131
            ctx->buf_off = 0;
542
131
            EVP_EncodeFinal(ctx->base64, ctx->buf, &(ctx->buf_len));
543
            /* push out the bytes */
544
131
            goto again;
545
131
        }
546
        /* Finally flush the underlying BIO */
547
4.72k
        ret = BIO_ctrl(next, cmd, num, ptr);
548
4.72k
        BIO_copy_next_retry(b);
549
4.72k
        break;
550
551
0
    case BIO_C_DO_STATE_MACHINE:
552
0
        BIO_clear_retry_flags(b);
553
0
        ret = BIO_ctrl(next, cmd, num, ptr);
554
0
        BIO_copy_next_retry(b);
555
0
        break;
556
557
0
    case BIO_CTRL_DUP:
558
0
        break;
559
0
    case BIO_CTRL_INFO:
560
0
    case BIO_CTRL_GET:
561
0
    case BIO_CTRL_SET:
562
9.44k
    default:
563
9.44k
        ret = BIO_ctrl(next, cmd, num, ptr);
564
9.44k
        break;
565
14.1k
    }
566
14.1k
    return ret;
567
14.1k
}
568
569
static long b64_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
570
0
{
571
0
    BIO *next = BIO_next(b);
572
573
0
    if (next == NULL)
574
0
        return 0;
575
576
0
    return BIO_callback_ctrl(next, cmd, fp);
577
0
}
578
579
static int b64_puts(BIO *b, const char *str)
580
0
{
581
0
    size_t len = strlen(str);
582
583
0
    if (len > INT_MAX)
584
0
        return -1;
585
0
    return b64_write(b, str, (int)len);
586
0
}