Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/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
5.51k
{
32
5.51k
    PKCS12 *p12;
33
5.51k
    BIO *in;
34
5.51k
    EVP_PKEY *pkey = NULL;
35
5.51k
    X509 *cert = NULL;
36
5.51k
    STACK_OF(X509) *ca = NULL;
37
38
5.51k
    if (len == 0 || len > INT_MAX)
39
0
        return 0;
40
41
5.51k
    in = BIO_new(BIO_s_mem());
42
5.51k
    if (in == NULL) {
43
0
        ERR_clear_error();
44
0
        return 0;
45
0
    }
46
5.51k
    if ((size_t)BIO_write(in, buf, (int)len) != len) {
47
0
        BIO_free(in);
48
0
        ERR_clear_error();
49
0
        return 0;
50
0
    }
51
5.51k
    p12 = d2i_PKCS12_bio(in, NULL);
52
5.51k
    if (p12 != NULL) {
53
1.18k
        PKCS12_verify_mac(p12, NULL, 0);
54
1.18k
        PKCS12_verify_mac(p12, "", 0);
55
56
1.18k
        PKCS12_parse(p12, NULL, &pkey, &cert, &ca);
57
1.18k
        EVP_PKEY_free(pkey);
58
1.18k
        X509_free(cert);
59
1.18k
        OSSL_STACK_OF_X509_free(ca);
60
61
1.18k
        pkey = NULL;
62
1.18k
        cert = NULL;
63
1.18k
        ca = NULL;
64
1.18k
        PKCS12_parse(p12, "", &pkey, &cert, &ca);
65
1.18k
        EVP_PKEY_free(pkey);
66
1.18k
        X509_free(cert);
67
1.18k
        OSSL_STACK_OF_X509_free(ca);
68
69
1.18k
        PKCS12_free(p12);
70
1.18k
    }
71
72
5.51k
    BIO_free(in);
73
5.51k
    ERR_clear_error();
74
75
5.51k
    return 0;
76
5.51k
}
77
78
void FuzzerCleanup(void)
79
0
{
80
0
}