Coverage Report

Created: 2026-03-31 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/gnutls/fuzz/gnutls_server_fuzzer.c
Line
Count
Source
1
/*
2
# Copyright 2017 Red Hat, Inc.
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
#include <unistd.h>
22
#include <string.h>
23
#include <stdlib.h>
24
25
#include <gnutls/gnutls.h>
26
27
#include "certs.h"
28
#include "mem.h"
29
#include "fuzzer.h"
30
31
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
32
3.57k
{
33
3.57k
  int res;
34
3.57k
  gnutls_datum_t rsa_cert, rsa_key;
35
3.57k
  gnutls_datum_t ecdsa_cert, ecdsa_key;
36
3.57k
  gnutls_datum_t ed25519_cert, ed25519_key;
37
3.57k
  gnutls_datum_t ed448_cert, ed448_key;
38
3.57k
  gnutls_session_t session;
39
3.57k
  gnutls_certificate_credentials_t xcred;
40
3.57k
  struct mem_st memdata;
41
42
3.57k
  res = gnutls_init(&session, GNUTLS_SERVER);
43
3.57k
  assert(res >= 0);
44
45
3.57k
  res = gnutls_certificate_allocate_credentials(&xcred);
46
3.57k
  assert(res >= 0);
47
48
3.57k
  rsa_cert.data = (unsigned char *)kRSACertificateDER;
49
3.57k
  rsa_cert.size = sizeof(kRSACertificateDER);
50
3.57k
  rsa_key.data = (unsigned char *)kRSAPrivateKeyDER;
51
3.57k
  rsa_key.size = sizeof(kRSAPrivateKeyDER);
52
53
3.57k
  ecdsa_cert.data = (unsigned char *)kECDSACertificateDER;
54
3.57k
  ecdsa_cert.size = sizeof(kECDSACertificateDER);
55
3.57k
  ecdsa_key.data = (unsigned char *)kECDSAPrivateKeyDER;
56
3.57k
  ecdsa_key.size = sizeof(kECDSAPrivateKeyDER);
57
58
3.57k
  ed25519_cert.data = (unsigned char *)kEd25519CertificateDER;
59
3.57k
  ed25519_cert.size = sizeof(kEd25519CertificateDER);
60
3.57k
  ed25519_key.data = (unsigned char *)kEd25519PrivateKeyDER;
61
3.57k
  ed25519_key.size = sizeof(kEd25519PrivateKeyDER);
62
63
3.57k
  ed448_cert.data = (unsigned char *)kEd448CertificateDER;
64
3.57k
  ed448_cert.size = sizeof(kEd448CertificateDER);
65
3.57k
  ed448_key.data = (unsigned char *)kEd448PrivateKeyDER;
66
3.57k
  ed448_key.size = sizeof(kEd448PrivateKeyDER);
67
68
3.57k
  res = gnutls_certificate_set_x509_key_mem(xcred, &rsa_cert, &rsa_key,
69
3.57k
              GNUTLS_X509_FMT_DER);
70
3.57k
  assert(res >= 0);
71
72
3.57k
  res = gnutls_certificate_set_x509_key_mem(
73
3.57k
    xcred, &ecdsa_cert, &ecdsa_key, GNUTLS_X509_FMT_DER);
74
3.57k
  assert(res >= 0);
75
76
3.57k
  res = gnutls_certificate_set_x509_key_mem(
77
3.57k
    xcred, &ed25519_cert, &ed25519_key, GNUTLS_X509_FMT_DER);
78
3.57k
  assert(res >= 0);
79
80
3.57k
  res = gnutls_certificate_set_x509_key_mem(
81
3.57k
    xcred, &ed448_cert, &ed448_key, GNUTLS_X509_FMT_DER);
82
3.57k
  assert(res >= 0);
83
84
3.57k
  gnutls_certificate_set_known_dh_params(xcred, GNUTLS_SEC_PARAM_MEDIUM);
85
86
3.57k
  res = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred);
87
3.57k
  assert(res >= 0);
88
89
  /*res = gnutls_set_default_priority(session); */
90
3.57k
  res = gnutls_priority_set_direct(
91
3.57k
    session, "NORMAL:+SIGN-EDDSA-ED448:" VERS_STR, NULL);
92
3.57k
  assert(res >= 0);
93
94
3.57k
  memdata.data = data;
95
3.57k
  memdata.size = size;
96
97
3.57k
  gnutls_transport_set_push_function(session, mem_push);
98
3.57k
  gnutls_transport_set_pull_function(session, mem_pull);
99
3.57k
  gnutls_transport_set_pull_timeout_function(session, mem_pull_timeout);
100
3.57k
  gnutls_transport_set_ptr(session, &memdata);
101
102
210k
  do {
103
210k
    res = gnutls_handshake(session);
104
210k
  } while (res < 0 && gnutls_error_is_fatal(res) == 0);
105
3.57k
  if (res >= 0) {
106
0
    for (;;) {
107
0
      char buf[16384];
108
0
      res = gnutls_record_recv(session, buf, sizeof(buf));
109
0
      if (res <= 0) {
110
0
        break;
111
0
      }
112
0
    }
113
0
  }
114
115
3.57k
  gnutls_deinit(session);
116
3.57k
  gnutls_certificate_free_credentials(xcred);
117
3.57k
  return 0;
118
3.57k
}