Coverage Report

Created: 2026-05-16 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
8.64k
{
29
8.64k
  gnutls_datum_t raw = { (unsigned char *)data, (unsigned int)size };
30
8.64k
  gnutls_pkcs12_t p12;
31
8.64k
  gnutls_x509_privkey_t key;
32
8.64k
  gnutls_x509_crt_t *chain;
33
8.64k
  gnutls_x509_crt_t *extras;
34
8.64k
  gnutls_x509_crl_t crl;
35
8.64k
  unsigned int chain_len = 0, extras_len = 0;
36
8.64k
  int ret;
37
38
8.64k
  raw.data = (unsigned char *)data;
39
8.64k
  raw.size = size;
40
41
8.64k
  ret = gnutls_pkcs12_init(&p12);
42
8.64k
  assert(ret >= 0);
43
44
8.64k
  ret = gnutls_pkcs12_import(p12, &raw, GNUTLS_X509_FMT_DER, 0);
45
8.64k
  if (ret < 0) {
46
2.35k
    goto cleanup;
47
2.35k
  }
48
49
  /* catch crashes */
50
6.29k
  gnutls_pkcs12_verify_mac(p12, "1234");
51
52
6.29k
  ret = gnutls_pkcs12_simple_parse(p12, "1234", &key, &chain, &chain_len,
53
6.29k
           &extras, &extras_len, &crl, 0);
54
6.29k
  if (ret >= 0) {
55
48
    gnutls_x509_privkey_deinit(key);
56
48
    if (crl)
57
1
      gnutls_x509_crl_deinit(crl);
58
48
    if (extras_len > 0) {
59
125
      for (unsigned i = 0; i < extras_len; i++)
60
87
        gnutls_x509_crt_deinit(extras[i]);
61
38
      gnutls_free(extras);
62
38
    }
63
48
    if (chain_len > 0) {
64
96
      for (unsigned i = 0; i < chain_len; i++)
65
48
        gnutls_x509_crt_deinit(chain[i]);
66
48
      gnutls_free(chain);
67
48
    }
68
48
  }
69
70
8.64k
cleanup:
71
8.64k
  gnutls_pkcs12_deinit(p12);
72
8.64k
  return 0;
73
6.29k
}