LCOV - code coverage report
Current view: top level - builds/gnutls/coverage/gnutls-git/lib - errors.h (source / functions) Hit Total Coverage
Test: GnuTLS-3.6.14 Code Coverage Lines: 21 35 60.0 %
Date: 2020-10-30 04:50:48 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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() _gnutls_assert_log( "ASSERT: %s[%s]:%d\n", __FILE__,__func__,__LINE__);
      34             : #else
      35             : #define gnutls_assert()
      36             : #endif
      37             : #else                           /* __FILE__ not defined */
      38             : #define gnutls_assert()
      39             : #endif
      40             : 
      41             : inline static int _gnutls_asn2err(int asn_err) __GNUTLS_CONST__;
      42             : 
      43       36942 : inline static int _gnutls_asn2err(int asn_err)
      44             : {
      45       36942 :         switch (asn_err) {
      46             : #ifdef ASN1_TIME_ENCODING_ERROR
      47             :         case ASN1_TIME_ENCODING_ERROR:
      48             :                 return GNUTLS_E_ASN1_TIME_ERROR;
      49             : #endif
      50           0 :         case ASN1_FILE_NOT_FOUND:
      51           0 :                 return GNUTLS_E_FILE_ERROR;
      52       29712 :         case ASN1_ELEMENT_NOT_FOUND:
      53       29712 :                 return GNUTLS_E_ASN1_ELEMENT_NOT_FOUND;
      54           0 :         case ASN1_IDENTIFIER_NOT_FOUND:
      55           0 :                 return GNUTLS_E_ASN1_IDENTIFIER_NOT_FOUND;
      56        1263 :         case ASN1_DER_ERROR:
      57        1263 :                 return GNUTLS_E_ASN1_DER_ERROR;
      58         204 :         case ASN1_VALUE_NOT_FOUND:
      59         204 :                 return GNUTLS_E_ASN1_VALUE_NOT_FOUND;
      60           5 :         case ASN1_GENERIC_ERROR:
      61           5 :                 return GNUTLS_E_ASN1_GENERIC_ERROR;
      62           2 :         case ASN1_VALUE_NOT_VALID:
      63           2 :                 return GNUTLS_E_ASN1_VALUE_NOT_VALID;
      64        4849 :         case ASN1_TAG_ERROR:
      65        4849 :                 return GNUTLS_E_ASN1_TAG_ERROR;
      66           0 :         case ASN1_TAG_IMPLICIT:
      67           0 :                 return GNUTLS_E_ASN1_TAG_IMPLICIT;
      68           0 :         case ASN1_ERROR_TYPE_ANY:
      69           0 :                 return GNUTLS_E_ASN1_TYPE_ANY_ERROR;
      70           0 :         case ASN1_SYNTAX_ERROR:
      71           0 :                 return GNUTLS_E_ASN1_SYNTAX_ERROR;
      72          97 :         case ASN1_MEM_ERROR:
      73          97 :                 return GNUTLS_E_SHORT_MEMORY_BUFFER;
      74           0 :         case ASN1_MEM_ALLOC_ERROR:
      75           0 :                 return GNUTLS_E_MEMORY_ERROR;
      76           0 :         case ASN1_DER_OVERFLOW:
      77           0 :                 return GNUTLS_E_ASN1_DER_OVERFLOW;
      78          77 :         default:
      79          77 :                 return GNUTLS_E_ASN1_GENERIC_ERROR;
      80             :         }
      81             : }
      82             : 
      83             : void _gnutls_log(int, const char *fmt, ...)
      84             : #ifdef __GNUC__
      85             :     __attribute__ ((format(printf, 2, 3)));
      86             : #else
      87             : ;
      88             : #endif
      89             : 
      90             : void _gnutls_audit_log(gnutls_session_t, const char *fmt, ...)
      91             : #ifdef __GNUC__
      92             :     __attribute__ ((format(printf, 2, 3)));
      93             : #else
      94             : ;
      95             : #endif
      96             : 
      97             : void _gnutls_mpi_log(const char *prefix, bigint_t a);
      98             : 
      99             : #define _gnutls_cert_log(str, cert) \
     100             :         do { \
     101             :                 if (unlikely(_gnutls_log_level >= 3 && cert != NULL)) { \
     102             :                         gnutls_datum_t _cl_out; int _cl_ret; \
     103             :                         _cl_ret = gnutls_x509_crt_print(cert, GNUTLS_CRT_PRINT_ONELINE, &_cl_out); \
     104             :                         if (_cl_ret >= 0) { \
     105             :                                 _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \
     106             :                                 gnutls_free(_cl_out.data); \
     107             :                         } \
     108             :                 } \
     109             :         } while(0)
     110             : 
     111             : #define _gnutls_dn_log(str, dn) \
     112             :         do { \
     113             :                 if (unlikely(_gnutls_log_level >= 3)) { \
     114             :                         gnutls_datum_t _cl_out; int _cl_ret; \
     115             :                         _cl_ret = gnutls_x509_rdn_get2((dn), &_cl_out, 0); \
     116             :                         if (_cl_ret >= 0) { \
     117             :                                 _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \
     118             :                                 gnutls_free(_cl_out.data); \
     119             :                         } \
     120             :                 } \
     121             :         } while(0)
     122             : 
     123             : #define _gnutls_reason_log(str, status) \
     124             :         do { \
     125             :                 if (unlikely(_gnutls_log_level >= 3)) { \
     126             :                         gnutls_datum_t _cl_out; int _cl_ret; \
     127             :                         _cl_ret = gnutls_certificate_verification_status_print(status, GNUTLS_CRT_X509, &_cl_out, 0); \
     128             :                         if (_cl_ret >= 0) { \
     129             :                                 _gnutls_log( 3, "%s: %s\n", str, _cl_out.data); \
     130             :                                 gnutls_free(_cl_out.data); \
     131             :                         } \
     132             :                 } \
     133             :          } while(0)
     134             : 
     135             : #ifdef C99_MACROS
     136             : #define LEVEL(l, ...) do { if (unlikely(_gnutls_log_level >= l)) \
     137             :       _gnutls_log( l, __VA_ARGS__); } while(0)
     138             : 
     139             : #define _gnutls_debug_log(...) LEVEL(2, __VA_ARGS__)
     140             : #define _gnutls_assert_log(...) LEVEL(3, __VA_ARGS__)
     141             : #define _gnutls_handshake_log(...) LEVEL(4, __VA_ARGS__)
     142             : #define _gnutls_record_log(...) LEVEL(5, __VA_ARGS__)
     143             : #define _gnutls_dtls_log(...) LEVEL(6, __VA_ARGS__)
     144             : 
     145             : #define _gnutls_hard_log(...) LEVEL(9, __VA_ARGS__)
     146             : 
     147             : #define _gnutls_read_log(...) LEVEL(10, __VA_ARGS__)
     148             : #define _gnutls_write_log(...) LEVEL(11, __VA_ARGS__)
     149             : #define _gnutls_io_log(...) LEVEL(12, __VA_ARGS__)
     150             : #define _gnutls_buffers_log(...) LEVEL(13, __VA_ARGS__)
     151             : #define _gnutls_no_log(...) LEVEL(INT_MAX, __VA_ARGS__)
     152             : #else
     153             : #define _gnutls_debug_log _gnutls_null_log
     154             : #define _gnutls_assert_log _gnutls_null_log
     155             : #define _gnutls_handshake_log _gnutls_null_log
     156             : #define _gnutls_io_log _gnutls_null_log
     157             : #define _gnutls_buffers_log _gnutls_null_log
     158             : #define _gnutls_hard_log _gnutls_null_log
     159             : #define _gnutls_record_log _gnutls_null_log
     160             : #define _gnutls_dtls_log _gnutls_null_log
     161             : #define _gnutls_read_log _gnutls_null_log
     162             : #define _gnutls_write_log _gnutls_null_log
     163             : #define _gnutls_no_log _gnutle_null_log
     164             : 
     165             : void _gnutls_null_log(void *, ...);
     166             : 
     167             : #endif                          /* C99_MACROS */
     168             : 
     169             : /* GCC won't inline this by itself and results in a "fatal warning"
     170             :    otherwise. Making this a macro has been tried, but it interacts
     171             :    badly with the do..while in the expansion. Welcome to the dark
     172             :    side. */
     173             : static inline
     174             : #ifdef __GNUC__
     175             :     __attribute__ ((always_inline))
     176             : #endif
     177    49731934 : int gnutls_assert_val_int(int val, const char *file, const char *func, int line)
     178             : {
     179    49731934 :         _gnutls_assert_log( "ASSERT: %s[%s]:%d\n", file,func,line);
     180    49722909 :         return val;
     181             : }
     182             : 
     183             : #define gnutls_assert_val(x) gnutls_assert_val_int(x, __FILE__, __func__, __LINE__)
     184             : #define gnutls_assert_val_fatal(x) (((x)!=GNUTLS_E_AGAIN && (x)!=GNUTLS_E_INTERRUPTED)?gnutls_assert_val_int(x, __FILE__, __func__, __LINE__):(x))
     185             : 
     186             : #endif /* GNUTLS_LIB_ERRORS_H */

Generated by: LCOV version 1.14