Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/fuzz/pem.c
Line
Count
Source
1
/*
2
 * Copyright 2022-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 * https://www.openssl.org/source/license.html
8
 * or in the file LICENSE in the source distribution.
9
 */
10
11
#include <openssl/pem.h>
12
#include <openssl/err.h>
13
#include "fuzzer.h"
14
15
int FuzzerInitialize(int *argc, char ***argv)
16
229
{
17
229
    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
18
229
    ERR_clear_error();
19
229
    CRYPTO_free_ex_index(0, -1);
20
229
    return 1;
21
229
}
22
23
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
24
1.18k
{
25
1.18k
    BIO *in;
26
1.18k
    char *name = NULL, *header = NULL;
27
1.18k
    unsigned char *data = NULL;
28
1.18k
    long outlen;
29
30
1.18k
    if (len <= 1 || len > INT_MAX)
31
1
        return 0;
32
33
1.18k
    in = BIO_new(BIO_s_mem());
34
1.18k
    if (in == NULL) {
35
0
        ERR_clear_error();
36
0
        return 0;
37
0
    }
38
1.18k
    if ((size_t)BIO_write(in, buf + 1, (int)(len - 1)) != len - 1) {
39
0
        BIO_free(in);
40
0
        ERR_clear_error();
41
0
        return 0;
42
0
    }
43
1.18k
    if (PEM_read_bio_ex(in, &name, &header, &data, &outlen, buf[0]) == 1) {
44
        /* Try to read all the data we get to see if allocated properly. */
45
145
        BIO_write(in, name, (int)strlen(name));
46
145
        BIO_write(in, header, (int)strlen(header));
47
145
        BIO_write(in, data, outlen);
48
145
    }
49
1.18k
    if (buf[0] & PEM_FLAG_SECURE) {
50
467
        OPENSSL_secure_free(name);
51
467
        OPENSSL_secure_free(header);
52
467
        OPENSSL_secure_free(data);
53
719
    } else {
54
719
        OPENSSL_free(name);
55
719
        OPENSSL_free(header);
56
719
        OPENSSL_free(data);
57
719
    }
58
59
1.18k
    BIO_free(in);
60
1.18k
    ERR_clear_error();
61
62
1.18k
    return 0;
63
1.18k
}
64
65
void FuzzerCleanup(void)
66
0
{
67
0
}