Coverage Report

Created: 2025-07-23 06:43

/src/gnutls/fuzz/gnutls_pkcs12_key_parser_fuzzer.c
Line
Count
Source
1
/*
2
# Copyright 2016 Nikos Mavrogiannopoulos
3
#
4
# Licensed under the Apache License, Version 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
#
8
#      https://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
#
16
################################################################################
17
*/
18
19
#include <assert.h>
20
#include <stdint.h>
21
22
#include <gnutls/gnutls.h>
23
#include <gnutls/pkcs12.h>
24
25
#include "fuzzer.h"
26
27
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
28
9.73k
{
29
9.73k
  gnutls_datum_t raw = { (unsigned char *)data, (unsigned int)size };
30
9.73k
  gnutls_pkcs12_t p12;
31
9.73k
  gnutls_x509_privkey_t key;
32
9.73k
  gnutls_x509_crt_t *chain;
33
9.73k
  gnutls_x509_crt_t *extras;
34
9.73k
  gnutls_x509_crl_t crl;
35
9.73k
  unsigned int chain_len = 0, extras_len = 0;
36
9.73k
  int ret;
37
38
9.73k
  raw.data = (unsigned char *)data;
39
9.73k
  raw.size = size;
40
41
9.73k
  ret = gnutls_pkcs12_init(&p12);
42
9.73k
  assert(ret >= 0);
43
44
9.73k
  ret = gnutls_pkcs12_import(p12, &raw, GNUTLS_X509_FMT_DER, 0);
45
9.73k
  if (ret < 0) {
46
2.60k
    goto cleanup;
47
2.60k
  }
48
49
  /* catch crashes */
50
7.12k
  gnutls_pkcs12_verify_mac(p12, "1234");
51
52
7.12k
  ret = gnutls_pkcs12_simple_parse(p12, "1234", &key, &chain, &chain_len,
53
7.12k
           &extras, &extras_len, &crl, 0);
54
7.12k
  if (ret >= 0) {
55
40
    gnutls_x509_privkey_deinit(key);
56
40
    if (crl)
57
1
      gnutls_x509_crl_deinit(crl);
58
40
    if (extras_len > 0) {
59
99
      for (unsigned i = 0; i < extras_len; i++)
60
67
        gnutls_x509_crt_deinit(extras[i]);
61
32
      gnutls_free(extras);
62
32
    }
63
40
    if (chain_len > 0) {
64
80
      for (unsigned i = 0; i < chain_len; i++)
65
40
        gnutls_x509_crt_deinit(chain[i]);
66
40
      gnutls_free(chain);
67
40
    }
68
40
  }
69
70
9.73k
cleanup:
71
9.73k
  gnutls_pkcs12_deinit(p12);
72
9.73k
  return 0;
73
7.12k
}