Coverage Report

Created: 2024-02-25 06:27

/src/gnutls/lib/errors.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (C) 2000-2012 Free Software Foundation, Inc.
3
 *
4
 * Author: Nikos Mavrogiannopoulos
5
 *
6
 * This file is part of GnuTLS.
7
 *
8
 * The GnuTLS is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public License
10
 * as published by the Free Software Foundation; either version 2.1 of
11
 * the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful, but
14
 * WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>
20
 *
21
 */
22
23
#ifndef GNUTLS_LIB_ERRORS_H
24
#define GNUTLS_LIB_ERRORS_H
25
26
#include "gnutls_int.h"
27
#include "global.h"
28
#include "mpi.h"
29
#include <gnutls/x509.h>
30
31
#ifdef __FILE__
32
#ifdef __LINE__
33
#define gnutls_assert() \
34
0
  _gnutls_assert_log("ASSERT: %s[%s]:%d\n", __FILE__, __func__, __LINE__);
35
#else
36
#define gnutls_assert()
37
#endif
38
#else /* __FILE__ not defined */
39
#define gnutls_assert()
40
#endif
41
42
inline static int _gnutls_asn2err(int asn_err) __GNUTLS_CONST__;
43
44
inline static int _gnutls_asn2err(int asn_err)
45
0
{
46
0
  switch (asn_err) {
47
0
#ifdef ASN1_TIME_ENCODING_ERROR
48
0
  case ASN1_TIME_ENCODING_ERROR:
49
0
    return GNUTLS_E_ASN1_TIME_ERROR;
50
0
#endif
51
0
  case ASN1_FILE_NOT_FOUND:
52
0
    return GNUTLS_E_FILE_ERROR;
53
0
  case ASN1_ELEMENT_NOT_FOUND:
54
0
    return GNUTLS_E_ASN1_ELEMENT_NOT_FOUND;
55
0
  case ASN1_IDENTIFIER_NOT_FOUND:
56
0
    return GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND;
57
0
  case ASN1_DER_ERROR:
58
0
    return GNUTLS_E_ASN1_DER_ERROR;
59
0
  case ASN1_VALUE_NOT_FOUND:
60
0
    return GNUTLS_E_ASN1_VALUE_NOT_FOUND;
61
0
  case ASN1_GENERIC_ERROR:
62
0
    return GNUTLS_E_ASN1_GENERIC_ERROR;
63
0
  case ASN1_VALUE_NOT_VALID:
64
0
    return GNUTLS_E_ASN1_VALUE_NOT_VALID;
65
0
  case ASN1_TAG_ERROR:
66
0
    return GNUTLS_E_ASN1_TAG_ERROR;
67
0
  case ASN1_TAG_IMPLICIT:
68
0
    return GNUTLS_E_ASN1_TAG_IMPLICIT;
69
0
  case ASN1_ERROR_TYPE_ANY:
70
0
    return GNUTLS_E_ASN1_TYPE_ANY_ERROR;
71
0
  case ASN1_SYNTAX_ERROR:
72
0
    return GNUTLS_E_ASN1_SYNTAX_ERROR;
73
0
  case ASN1_MEM_ERROR:
74
0
    return GNUTLS_E_SHORT_MEMORY_BUFFER;
75
0
  case ASN1_MEM_ALLOC_ERROR:
76
0
    return GNUTLS_E_MEMORY_ERROR;
77
0
  case ASN1_DER_OVERFLOW:
78
0
    return GNUTLS_E_ASN1_DER_OVERFLOW;
79
0
  default:
80
0
    return GNUTLS_E_ASN1_GENERIC_ERROR;
81
0
  }
82
0
}
Unexecuted instantiation: ocsp.c:_gnutls_asn2err
Unexecuted instantiation: output.c:_gnutls_asn2err
Unexecuted instantiation: time.c:_gnutls_asn2err
Unexecuted instantiation: tls_features.c:_gnutls_asn2err
Unexecuted instantiation: verify-high.c:_gnutls_asn2err
Unexecuted instantiation: verify.c:_gnutls_asn2err
Unexecuted instantiation: virt-san.c:_gnutls_asn2err
Unexecuted instantiation: x509.c:_gnutls_asn2err
Unexecuted instantiation: x509_ext.c:_gnutls_asn2err
Unexecuted instantiation: sign.c:_gnutls_asn2err
Unexecuted instantiation: privkey.c:_gnutls_asn2err
Unexecuted instantiation: common.c:_gnutls_asn2err
Unexecuted instantiation: crl.c:_gnutls_asn2err
Unexecuted instantiation: crq.c:_gnutls_asn2err
Unexecuted instantiation: dn.c:_gnutls_asn2err
Unexecuted instantiation: email-verify.c:_gnutls_asn2err
Unexecuted instantiation: extensions.c:_gnutls_asn2err
Unexecuted instantiation: hostname-verify.c:_gnutls_asn2err
Unexecuted instantiation: ip.c:_gnutls_asn2err
Unexecuted instantiation: key_decode.c:_gnutls_asn2err
Unexecuted instantiation: key_encode.c:_gnutls_asn2err
Unexecuted instantiation: krb5.c:_gnutls_asn2err
Unexecuted instantiation: name_constraints.c:_gnutls_asn2err
Unexecuted instantiation: pkcs12.c:_gnutls_asn2err
Unexecuted instantiation: pkcs12_bag.c:_gnutls_asn2err
Unexecuted instantiation: pkcs12_encr.c:_gnutls_asn2err
Unexecuted instantiation: pkcs7-crypt.c:_gnutls_asn2err
Unexecuted instantiation: privkey_openssl.c:_gnutls_asn2err
Unexecuted instantiation: privkey_pkcs8.c:_gnutls_asn2err
Unexecuted instantiation: privkey_pkcs8_pbes1.c:_gnutls_asn2err
Unexecuted instantiation: prov-seed.c:_gnutls_asn2err
Unexecuted instantiation: verify-high2.c:_gnutls_asn2err
Unexecuted instantiation: x509_dn.c:_gnutls_asn2err
Unexecuted instantiation: x509_write.c:_gnutls_asn2err
Unexecuted instantiation: attributes.c:_gnutls_asn2err
83
84
void _gnutls_log(int, const char *fmt, ...)
85
#ifdef __GNUC__
86
  __attribute__((format(printf, 2, 3)));
87
#else
88
  ;
89
#endif
90
91
void _gnutls_audit_log(gnutls_session_t, const char *fmt, ...)
92
#ifdef __GNUC__
93
  __attribute__((format(printf, 2, 3)));
94
#else
95
  ;
96
#endif
97
98
void _gnutls_mpi_log(const char *prefix, bigint_t a);
99
100
#define _gnutls_cert_log(str, cert)                                            \
101
0
  do {                                                                   \
102
0
    if (unlikely(_gnutls_log_level >= 3)) {                        \
103
0
      gnutls_datum_t _cl_out;                                \
104
0
      int _cl_ret;                                           \
105
0
      _cl_ret = gnutls_x509_crt_print(                       \
106
0
        cert, GNUTLS_CRT_PRINT_ONELINE, &_cl_out);     \
107
0
      if (_cl_ret >= 0) {                                    \
108
0
        _gnutls_log(3, "%s: %s\n", str, _cl_out.data); \
109
0
        gnutls_free(_cl_out.data);                     \
110
0
      }                                                      \
111
0
    }                                                              \
112
0
  } while (0)
113
114
#define _gnutls_dn_log(str, dn)                                                \
115
  do {                                                                   \
116
    if (unlikely(_gnutls_log_level >= 3)) {                        \
117
      gnutls_datum_t _cl_out;                                \
118
      int _cl_ret;                                           \
119
      _cl_ret = gnutls_x509_rdn_get2((dn), &_cl_out, 0);     \
120
      if (_cl_ret >= 0) {                                    \
121
        _gnutls_log(3, "%s: %s\n", str, _cl_out.data); \
122
        gnutls_free(_cl_out.data);                     \
123
      }                                                      \
124
    }                                                              \
125
  } while (0)
126
127
#define _gnutls_reason_log(str, status)                                        \
128
0
  do {                                                                   \
129
0
    if (unlikely(_gnutls_log_level >= 3)) {                        \
130
0
      gnutls_datum_t _cl_out;                                \
131
0
      int _cl_ret;                                           \
132
0
      _cl_ret =                                              \
133
0
        gnutls_certificate_verification_status_print(  \
134
0
          status, GNUTLS_CRT_X509, &_cl_out, 0); \
135
0
      if (_cl_ret >= 0) {                                    \
136
0
        _gnutls_log(3, "%s: %s\n", str, _cl_out.data); \
137
0
        gnutls_free(_cl_out.data);                     \
138
0
      }                                                      \
139
0
    }                                                              \
140
0
  } while (0)
141
142
#ifdef C99_MACROS
143
#define LEVEL(l, ...)                                 \
144
0
  do {                                          \
145
0
    if (unlikely(_gnutls_log_level >= l)) \
146
0
      _gnutls_log(l, __VA_ARGS__);  \
147
0
  } while (0)
148
149
0
#define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__)
150
0
#define _gnutls_assert_log(...) LEVEL(3, __VA_ARGS__)
151
#define _gnutls_handshake_log(...) LEVEL(4, __VA_ARGS__)
152
#define _gnutls_record_log(...) LEVEL(5, __VA_ARGS__)
153
#define _gnutls_dtls_log(...) LEVEL(6, __VA_ARGS__)
154
155
0
#define _gnutls_hard_log(...) LEVEL(9, __VA_ARGS__)
156
157
#define _gnutls_read_log(...) LEVEL(10, __VA_ARGS__)
158
#define _gnutls_write_log(...) LEVEL(11, __VA_ARGS__)
159
#define _gnutls_io_log(...) LEVEL(12, __VA_ARGS__)
160
#define _gnutls_buffers_log(...) LEVEL(13, __VA_ARGS__)
161
#define _gnutls_no_log(...) LEVEL(INT_MAX, __VA_ARGS__)
162
#else
163
#define _gnutls_debug_log _gnutls_null_log
164
#define _gnutls_assert_log _gnutls_null_log
165
#define _gnutls_handshake_log _gnutls_null_log
166
#define _gnutls_io_log _gnutls_null_log
167
#define _gnutls_buffers_log _gnutls_null_log
168
#define _gnutls_hard_log _gnutls_null_log
169
#define _gnutls_record_log _gnutls_null_log
170
#define _gnutls_dtls_log _gnutls_null_log
171
#define _gnutls_read_log _gnutls_null_log
172
#define _gnutls_write_log _gnutls_null_log
173
#define _gnutls_no_log _gnutle_null_log
174
175
void _gnutls_null_log(void *, ...);
176
177
#endif /* C99_MACROS */
178
179
/* GCC won't inline this by itself and results in a "fatal warning"
180
   otherwise. Making this a macro has been tried, but it interacts
181
   badly with the do..while in the expansion. Welcome to the dark
182
   side. */
183
static inline
184
#ifdef __GNUC__
185
  __attribute__((always_inline))
186
#endif
187
  int
188
  gnutls_assert_val_int(int val, const char *file, const char *func,
189
            int line)
190
0
{
191
0
  _gnutls_assert_log("ASSERT: %s[%s]:%d\n", file, func, line);
192
0
  return val;
193
0
}
Unexecuted instantiation: ocsp.c:gnutls_assert_val_int
Unexecuted instantiation: output.c:gnutls_assert_val_int
Unexecuted instantiation: time.c:gnutls_assert_val_int
Unexecuted instantiation: tls_features.c:gnutls_assert_val_int
Unexecuted instantiation: verify-high.c:gnutls_assert_val_int
Unexecuted instantiation: verify.c:gnutls_assert_val_int
Unexecuted instantiation: virt-san.c:gnutls_assert_val_int
Unexecuted instantiation: x509.c:gnutls_assert_val_int
Unexecuted instantiation: x509_ext.c:gnutls_assert_val_int
Unexecuted instantiation: common.c:gnutls_assert_val_int
Unexecuted instantiation: crl.c:gnutls_assert_val_int
Unexecuted instantiation: crq.c:gnutls_assert_val_int
Unexecuted instantiation: dn.c:gnutls_assert_val_int
Unexecuted instantiation: email-verify.c:gnutls_assert_val_int
Unexecuted instantiation: extensions.c:gnutls_assert_val_int
Unexecuted instantiation: hostname-verify.c:gnutls_assert_val_int
Unexecuted instantiation: ip.c:gnutls_assert_val_int
Unexecuted instantiation: key_decode.c:gnutls_assert_val_int
Unexecuted instantiation: key_encode.c:gnutls_assert_val_int
Unexecuted instantiation: krb5.c:gnutls_assert_val_int
Unexecuted instantiation: name_constraints.c:gnutls_assert_val_int
Unexecuted instantiation: pkcs12.c:gnutls_assert_val_int
Unexecuted instantiation: pkcs12_bag.c:gnutls_assert_val_int
Unexecuted instantiation: pkcs12_encr.c:gnutls_assert_val_int
Unexecuted instantiation: pkcs7-crypt.c:gnutls_assert_val_int
Unexecuted instantiation: privkey_openssl.c:gnutls_assert_val_int
Unexecuted instantiation: privkey_pkcs8.c:gnutls_assert_val_int
Unexecuted instantiation: privkey_pkcs8_pbes1.c:gnutls_assert_val_int
Unexecuted instantiation: prov-seed.c:gnutls_assert_val_int
Unexecuted instantiation: verify-high2.c:gnutls_assert_val_int
Unexecuted instantiation: x509_dn.c:gnutls_assert_val_int
Unexecuted instantiation: x509_write.c:gnutls_assert_val_int
Unexecuted instantiation: attributes.c:gnutls_assert_val_int
194
195
#define gnutls_assert_val(x) \
196
0
  gnutls_assert_val_int(x, __FILE__, __func__, __LINE__)
197
#define gnutls_assert_val_fatal(x)                                        \
198
  (((x) != GNUTLS_E_AGAIN && (x) != GNUTLS_E_INTERRUPTED) ?         \
199
     gnutls_assert_val_int(x, __FILE__, __func__, __LINE__) : \
200
     (x))
201
202
#endif /* GNUTLS_LIB_ERRORS_H */