Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl40/fuzz/pkcs12.c
Line
Count
Source
1
/*
2
 * Copyright 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
/*
12
 * Test PKCS12 parsing with fuzzed input.
13
 */
14
15
#include <openssl/bio.h>
16
#include <openssl/err.h>
17
#include <openssl/pkcs12.h>
18
#include <openssl/x509.h>
19
#include "fuzzer.h"
20
21
int FuzzerInitialize(int *argc, char ***argv)
22
229
{
23
229
    OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
24
229
    ERR_clear_error();
25
229
    CRYPTO_free_ex_index(0, -1);
26
27
229
    return 1;
28
229
}
29
30
int FuzzerTestOneInput(const uint8_t *buf, size_t len)
31
15.4k
{
32
15.4k
    PKCS12 *p12;
33
15.4k
    BIO *in;
34
15.4k
    EVP_PKEY *pkey = NULL;
35
15.4k
    X509 *cert = NULL;
36
15.4k
    STACK_OF(X509) *ca = NULL;
37
38
15.4k
    if (len == 0 || len > INT_MAX)
39
0
        return 0;
40
41
15.4k
    in = BIO_new(BIO_s_mem());
42
15.4k
    OPENSSL_assert((size_t)BIO_write(in, buf, (int)len) == len);
43
15.4k
    p12 = d2i_PKCS12_bio(in, NULL);
44
15.4k
    if (p12 != NULL) {
45
3.71k
        PKCS12_verify_mac(p12, NULL, 0);
46
3.71k
        PKCS12_verify_mac(p12, "", 0);
47
48
3.71k
        PKCS12_parse(p12, NULL, &pkey, &cert, &ca);
49
3.71k
        EVP_PKEY_free(pkey);
50
3.71k
        X509_free(cert);
51
3.71k
        OSSL_STACK_OF_X509_free(ca);
52
53
3.71k
        pkey = NULL;
54
3.71k
        cert = NULL;
55
3.71k
        ca = NULL;
56
3.71k
        PKCS12_parse(p12, "", &pkey, &cert, &ca);
57
3.71k
        EVP_PKEY_free(pkey);
58
3.71k
        X509_free(cert);
59
3.71k
        OSSL_STACK_OF_X509_free(ca);
60
61
3.71k
        PKCS12_free(p12);
62
3.71k
    }
63
64
15.4k
    BIO_free(in);
65
15.4k
    ERR_clear_error();
66
67
15.4k
    return 0;
68
15.4k
}
69
70
void FuzzerCleanup(void)
71
0
{
72
0
}