Coverage Report

Created: 2025-12-31 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl36/fuzz/pem.c
Line
Count
Source
1
/*
2
 * Copyright 2022-2025 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
214
{
17
214
    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
18
214
    ERR_clear_error();
19
214
    CRYPTO_free_ex_index(0, -1);
20
214
    return 1;
21
214
}
22
23
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
24
2.40k
{
25
2.40k
    BIO *in;
26
2.40k
    char *name = NULL, *header = NULL;
27
2.40k
    unsigned char *data = NULL;
28
2.40k
    long outlen;
29
30
2.40k
    if (len <= 1 || len > INT_MAX)
31
2
        return 0;
32
33
2.40k
    in = BIO_new(BIO_s_mem());
34
2.40k
    OPENSSL_assert((size_t)BIO_write(in, buf + 1, (int)(len - 1)) == len - 1);
35
2.40k
    if (PEM_read_bio_ex(in, &name, &header, &data, &outlen, buf[0]) == 1) {
36
        /* Try to read all the data we get to see if allocated properly. */
37
330
        BIO_write(in, name, (int)strlen(name));
38
330
        BIO_write(in, header, (int)strlen(header));
39
330
        BIO_write(in, data, outlen);
40
330
    }
41
2.40k
    if (buf[0] & PEM_FLAG_SECURE) {
42
991
        OPENSSL_secure_free(name);
43
991
        OPENSSL_secure_free(header);
44
991
        OPENSSL_secure_free(data);
45
1.40k
    } else {
46
1.40k
        OPENSSL_free(name);
47
1.40k
        OPENSSL_free(header);
48
1.40k
        OPENSSL_free(data);
49
1.40k
    }
50
51
2.40k
    BIO_free(in);
52
2.40k
    ERR_clear_error();
53
54
2.40k
    return 0;
55
2.40k
}
56
57
void FuzzerCleanup(void)
58
0
{
59
0
}