| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/err/err.c |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /* | - | ||||||||||||
| 2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||
| 3 | * | - | ||||||||||||
| 4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||
| 5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||
| 6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||
| 7 | * https://www.openssl.org/source/license.html | - | ||||||||||||
| 8 | */ | - | ||||||||||||
| 9 | - | |||||||||||||
| 10 | #include <stdio.h> | - | ||||||||||||
| 11 | #include <stdarg.h> | - | ||||||||||||
| 12 | #include <string.h> | - | ||||||||||||
| 13 | #include "internal/cryptlib_int.h" | - | ||||||||||||
| 14 | #include "internal/err.h" | - | ||||||||||||
| 15 | #include "internal/err_int.h" | - | ||||||||||||
| 16 | #include <openssl/err.h> | - | ||||||||||||
| 17 | #include <openssl/crypto.h> | - | ||||||||||||
| 18 | #include <openssl/buffer.h> | - | ||||||||||||
| 19 | #include <openssl/bio.h> | - | ||||||||||||
| 20 | #include <openssl/opensslconf.h> | - | ||||||||||||
| 21 | #include "internal/thread_once.h" | - | ||||||||||||
| 22 | - | |||||||||||||
| 23 | static int err_load_strings(const ERR_STRING_DATA *str); | - | ||||||||||||
| 24 | - | |||||||||||||
| 25 | static void ERR_STATE_free(ERR_STATE *s); | - | ||||||||||||
| 26 | #ifndef OPENSSL_NO_ERR | - | ||||||||||||
| 27 | static ERR_STRING_DATA ERR_str_libraries[] = { | - | ||||||||||||
| 28 | {ERR_PACK(ERR_LIB_NONE, 0, 0), "unknown library"}, | - | ||||||||||||
| 29 | {ERR_PACK(ERR_LIB_SYS, 0, 0), "system library"}, | - | ||||||||||||
| 30 | {ERR_PACK(ERR_LIB_BN, 0, 0), "bignum routines"}, | - | ||||||||||||
| 31 | {ERR_PACK(ERR_LIB_RSA, 0, 0), "rsa routines"}, | - | ||||||||||||
| 32 | {ERR_PACK(ERR_LIB_DH, 0, 0), "Diffie-Hellman routines"}, | - | ||||||||||||
| 33 | {ERR_PACK(ERR_LIB_EVP, 0, 0), "digital envelope routines"}, | - | ||||||||||||
| 34 | {ERR_PACK(ERR_LIB_BUF, 0, 0), "memory buffer routines"}, | - | ||||||||||||
| 35 | {ERR_PACK(ERR_LIB_OBJ, 0, 0), "object identifier routines"}, | - | ||||||||||||
| 36 | {ERR_PACK(ERR_LIB_PEM, 0, 0), "PEM routines"}, | - | ||||||||||||
| 37 | {ERR_PACK(ERR_LIB_DSA, 0, 0), "dsa routines"}, | - | ||||||||||||
| 38 | {ERR_PACK(ERR_LIB_X509, 0, 0), "x509 certificate routines"}, | - | ||||||||||||
| 39 | {ERR_PACK(ERR_LIB_ASN1, 0, 0), "asn1 encoding routines"}, | - | ||||||||||||
| 40 | {ERR_PACK(ERR_LIB_CONF, 0, 0), "configuration file routines"}, | - | ||||||||||||
| 41 | {ERR_PACK(ERR_LIB_CRYPTO, 0, 0), "common libcrypto routines"}, | - | ||||||||||||
| 42 | {ERR_PACK(ERR_LIB_EC, 0, 0), "elliptic curve routines"}, | - | ||||||||||||
| 43 | {ERR_PACK(ERR_LIB_ECDSA, 0, 0), "ECDSA routines"}, | - | ||||||||||||
| 44 | {ERR_PACK(ERR_LIB_ECDH, 0, 0), "ECDH routines"}, | - | ||||||||||||
| 45 | {ERR_PACK(ERR_LIB_SSL, 0, 0), "SSL routines"}, | - | ||||||||||||
| 46 | {ERR_PACK(ERR_LIB_BIO, 0, 0), "BIO routines"}, | - | ||||||||||||
| 47 | {ERR_PACK(ERR_LIB_PKCS7, 0, 0), "PKCS7 routines"}, | - | ||||||||||||
| 48 | {ERR_PACK(ERR_LIB_X509V3, 0, 0), "X509 V3 routines"}, | - | ||||||||||||
| 49 | {ERR_PACK(ERR_LIB_PKCS12, 0, 0), "PKCS12 routines"}, | - | ||||||||||||
| 50 | {ERR_PACK(ERR_LIB_RAND, 0, 0), "random number generator"}, | - | ||||||||||||
| 51 | {ERR_PACK(ERR_LIB_DSO, 0, 0), "DSO support routines"}, | - | ||||||||||||
| 52 | {ERR_PACK(ERR_LIB_TS, 0, 0), "time stamp routines"}, | - | ||||||||||||
| 53 | {ERR_PACK(ERR_LIB_ENGINE, 0, 0), "engine routines"}, | - | ||||||||||||
| 54 | {ERR_PACK(ERR_LIB_OCSP, 0, 0), "OCSP routines"}, | - | ||||||||||||
| 55 | {ERR_PACK(ERR_LIB_UI, 0, 0), "UI routines"}, | - | ||||||||||||
| 56 | {ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"}, | - | ||||||||||||
| 57 | {ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"}, | - | ||||||||||||
| 58 | {ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"}, | - | ||||||||||||
| 59 | {ERR_PACK(ERR_LIB_CT, 0, 0), "CT routines"}, | - | ||||||||||||
| 60 | {ERR_PACK(ERR_LIB_ASYNC, 0, 0), "ASYNC routines"}, | - | ||||||||||||
| 61 | {ERR_PACK(ERR_LIB_KDF, 0, 0), "KDF routines"}, | - | ||||||||||||
| 62 | {ERR_PACK(ERR_LIB_OSSL_STORE, 0, 0), "STORE routines"}, | - | ||||||||||||
| 63 | {ERR_PACK(ERR_LIB_SM2, 0, 0), "SM2 routines"}, | - | ||||||||||||
| 64 | {0, NULL}, | - | ||||||||||||
| 65 | }; | - | ||||||||||||
| 66 | - | |||||||||||||
| 67 | static ERR_STRING_DATA ERR_str_functs[] = { | - | ||||||||||||
| 68 | {ERR_PACK(0, SYS_F_FOPEN, 0), "fopen"}, | - | ||||||||||||
| 69 | {ERR_PACK(0, SYS_F_CONNECT, 0), "connect"}, | - | ||||||||||||
| 70 | {ERR_PACK(0, SYS_F_GETSERVBYNAME, 0), "getservbyname"}, | - | ||||||||||||
| 71 | {ERR_PACK(0, SYS_F_SOCKET, 0), "socket"}, | - | ||||||||||||
| 72 | {ERR_PACK(0, SYS_F_IOCTLSOCKET, 0), "ioctlsocket"}, | - | ||||||||||||
| 73 | {ERR_PACK(0, SYS_F_BIND, 0), "bind"}, | - | ||||||||||||
| 74 | {ERR_PACK(0, SYS_F_LISTEN, 0), "listen"}, | - | ||||||||||||
| 75 | {ERR_PACK(0, SYS_F_ACCEPT, 0), "accept"}, | - | ||||||||||||
| 76 | # ifdef OPENSSL_SYS_WINDOWS | - | ||||||||||||
| 77 | {ERR_PACK(0, SYS_F_WSASTARTUP, 0), "WSAstartup"}, | - | ||||||||||||
| 78 | # endif | - | ||||||||||||
| 79 | {ERR_PACK(0, SYS_F_OPENDIR, 0), "opendir"}, | - | ||||||||||||
| 80 | {ERR_PACK(0, SYS_F_FREAD, 0), "fread"}, | - | ||||||||||||
| 81 | {ERR_PACK(0, SYS_F_GETADDRINFO, 0), "getaddrinfo"}, | - | ||||||||||||
| 82 | {ERR_PACK(0, SYS_F_GETNAMEINFO, 0), "getnameinfo"}, | - | ||||||||||||
| 83 | {ERR_PACK(0, SYS_F_SETSOCKOPT, 0), "setsockopt"}, | - | ||||||||||||
| 84 | {ERR_PACK(0, SYS_F_GETSOCKOPT, 0), "getsockopt"}, | - | ||||||||||||
| 85 | {ERR_PACK(0, SYS_F_GETSOCKNAME, 0), "getsockname"}, | - | ||||||||||||
| 86 | {ERR_PACK(0, SYS_F_GETHOSTBYNAME, 0), "gethostbyname"}, | - | ||||||||||||
| 87 | {ERR_PACK(0, SYS_F_FFLUSH, 0), "fflush"}, | - | ||||||||||||
| 88 | {ERR_PACK(0, SYS_F_OPEN, 0), "open"}, | - | ||||||||||||
| 89 | {ERR_PACK(0, SYS_F_CLOSE, 0), "close"}, | - | ||||||||||||
| 90 | {ERR_PACK(0, SYS_F_IOCTL, 0), "ioctl"}, | - | ||||||||||||
| 91 | {ERR_PACK(0, SYS_F_STAT, 0), "stat"}, | - | ||||||||||||
| 92 | {ERR_PACK(0, SYS_F_FCNTL, 0), "fcntl"}, | - | ||||||||||||
| 93 | {ERR_PACK(0, SYS_F_FSTAT, 0), "fstat"}, | - | ||||||||||||
| 94 | {0, NULL}, | - | ||||||||||||
| 95 | }; | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | static ERR_STRING_DATA ERR_str_reasons[] = { | - | ||||||||||||
| 98 | {ERR_R_SYS_LIB, "system lib"}, | - | ||||||||||||
| 99 | {ERR_R_BN_LIB, "BN lib"}, | - | ||||||||||||
| 100 | {ERR_R_RSA_LIB, "RSA lib"}, | - | ||||||||||||
| 101 | {ERR_R_DH_LIB, "DH lib"}, | - | ||||||||||||
| 102 | {ERR_R_EVP_LIB, "EVP lib"}, | - | ||||||||||||
| 103 | {ERR_R_BUF_LIB, "BUF lib"}, | - | ||||||||||||
| 104 | {ERR_R_OBJ_LIB, "OBJ lib"}, | - | ||||||||||||
| 105 | {ERR_R_PEM_LIB, "PEM lib"}, | - | ||||||||||||
| 106 | {ERR_R_DSA_LIB, "DSA lib"}, | - | ||||||||||||
| 107 | {ERR_R_X509_LIB, "X509 lib"}, | - | ||||||||||||
| 108 | {ERR_R_ASN1_LIB, "ASN1 lib"}, | - | ||||||||||||
| 109 | {ERR_R_EC_LIB, "EC lib"}, | - | ||||||||||||
| 110 | {ERR_R_BIO_LIB, "BIO lib"}, | - | ||||||||||||
| 111 | {ERR_R_PKCS7_LIB, "PKCS7 lib"}, | - | ||||||||||||
| 112 | {ERR_R_X509V3_LIB, "X509V3 lib"}, | - | ||||||||||||
| 113 | {ERR_R_ENGINE_LIB, "ENGINE lib"}, | - | ||||||||||||
| 114 | {ERR_R_UI_LIB, "UI lib"}, | - | ||||||||||||
| 115 | {ERR_R_OSSL_STORE_LIB, "STORE lib"}, | - | ||||||||||||
| 116 | {ERR_R_ECDSA_LIB, "ECDSA lib"}, | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | {ERR_R_NESTED_ASN1_ERROR, "nested asn1 error"}, | - | ||||||||||||
| 119 | {ERR_R_MISSING_ASN1_EOS, "missing asn1 eos"}, | - | ||||||||||||
| 120 | - | |||||||||||||
| 121 | {ERR_R_FATAL, "fatal"}, | - | ||||||||||||
| 122 | {ERR_R_MALLOC_FAILURE, "malloc failure"}, | - | ||||||||||||
| 123 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, | - | ||||||||||||
| 124 | "called a function you should not call"}, | - | ||||||||||||
| 125 | {ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"}, | - | ||||||||||||
| 126 | {ERR_R_INTERNAL_ERROR, "internal error"}, | - | ||||||||||||
| 127 | {ERR_R_DISABLED, "called a function that was disabled at compile-time"}, | - | ||||||||||||
| 128 | {ERR_R_INIT_FAIL, "init fail"}, | - | ||||||||||||
| 129 | {ERR_R_OPERATION_FAIL, "operation fail"}, | - | ||||||||||||
| 130 | - | |||||||||||||
| 131 | {0, NULL}, | - | ||||||||||||
| 132 | }; | - | ||||||||||||
| 133 | #endif | - | ||||||||||||
| 134 | - | |||||||||||||
| 135 | static CRYPTO_ONCE err_init = CRYPTO_ONCE_STATIC_INIT; | - | ||||||||||||
| 136 | static int set_err_thread_local; | - | ||||||||||||
| 137 | static CRYPTO_THREAD_LOCAL err_thread_local; | - | ||||||||||||
| 138 | - | |||||||||||||
| 139 | static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT; | - | ||||||||||||
| 140 | static CRYPTO_RWLOCK *err_string_lock; | - | ||||||||||||
| 141 | - | |||||||||||||
| 142 | static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *); | - | ||||||||||||
| 143 | - | |||||||||||||
| 144 | /* | - | ||||||||||||
| 145 | * The internal state | - | ||||||||||||
| 146 | */ | - | ||||||||||||
| 147 | - | |||||||||||||
| 148 | static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL; | - | ||||||||||||
| 149 | static int int_err_library_number = ERR_LIB_USER; | - | ||||||||||||
| 150 | - | |||||||||||||
| 151 | static unsigned long get_error_values(int inc, int top, const char **file, | - | ||||||||||||
| 152 | int *line, const char **data, | - | ||||||||||||
| 153 | int *flags); | - | ||||||||||||
| 154 | - | |||||||||||||
| 155 | static unsigned long err_string_data_hash(const ERR_STRING_DATA *a) | - | ||||||||||||
| 156 | { | - | ||||||||||||
| 157 | unsigned long ret, l; | - | ||||||||||||
| 158 | - | |||||||||||||
| 159 | l = a->error; | - | ||||||||||||
| 160 | ret = l ^ ERR_GET_LIB(l) ^ ERR_GET_FUNC(l); | - | ||||||||||||
| 161 | return (ret ^ ret % 19 * 13); executed 16216750 times by 11 tests: return (ret ^ ret % 19 * 13);Executed by:
| 16216750 | ||||||||||||
| 162 | } | - | ||||||||||||
| 163 | - | |||||||||||||
| 164 | static int err_string_data_cmp(const ERR_STRING_DATA *a, | - | ||||||||||||
| 165 | const ERR_STRING_DATA *b) | - | ||||||||||||
| 166 | { | - | ||||||||||||
| 167 | if (a->error == b->error)
| 274668-10759803 | ||||||||||||
| 168 | return 0; executed 10759803 times by 11 tests: return 0;Executed by:
| 10759803 | ||||||||||||
| 169 | return a->error > b->error ? 1 : -1; executed 274668 times by 11 tests: return a->error > b->error ? 1 : -1;Executed by:
| 108973-274668 | ||||||||||||
| 170 | } | - | ||||||||||||
| 171 | - | |||||||||||||
| 172 | static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d) | - | ||||||||||||
| 173 | { | - | ||||||||||||
| 174 | ERR_STRING_DATA *p = NULL; | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | CRYPTO_THREAD_read_lock(err_string_lock); | - | ||||||||||||
| 177 | p = lh_ERR_STRING_DATA_retrieve(int_error_hash, d); | - | ||||||||||||
| 178 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 179 | - | |||||||||||||
| 180 | return p; executed 73868 times by 11 tests: return p;Executed by:
| 73868 | ||||||||||||
| 181 | } | - | ||||||||||||
| 182 | - | |||||||||||||
| 183 | #ifndef OPENSSL_NO_ERR | - | ||||||||||||
| 184 | # define NUM_SYS_STR_REASONS 127 | - | ||||||||||||
| 185 | # define LEN_SYS_STR_REASON 32 | - | ||||||||||||
| 186 | - | |||||||||||||
| 187 | static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; | - | ||||||||||||
| 188 | /* | - | ||||||||||||
| 189 | * SYS_str_reasons is filled with copies of strerror() results at | - | ||||||||||||
| 190 | * initialization. 'errno' values up to 127 should cover all usual errors, | - | ||||||||||||
| 191 | * others will be displayed numerically by ERR_error_string. It is crucial | - | ||||||||||||
| 192 | * that we have something for each reason code that occurs in | - | ||||||||||||
| 193 | * ERR_str_reasons, or bogus reason strings will be returned for SYSerr(), | - | ||||||||||||
| 194 | * which always gets an errno value and never one of those 'standard' reason | - | ||||||||||||
| 195 | * codes. | - | ||||||||||||
| 196 | */ | - | ||||||||||||
| 197 | - | |||||||||||||
| 198 | static void build_SYS_str_reasons(void) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | /* OPENSSL_malloc cannot be used here, use static storage instead */ | - | ||||||||||||
| 201 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; | - | ||||||||||||
| 202 | static int init = 1; | - | ||||||||||||
| 203 | int i; | - | ||||||||||||
| 204 | - | |||||||||||||
| 205 | CRYPTO_THREAD_write_lock(err_string_lock); | - | ||||||||||||
| 206 | if (!init) {
| 2074-122120 | ||||||||||||
| 207 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 208 | return; executed 122120 times by 11 tests: return;Executed by:
| 122120 | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) {
| 2074-263398 | ||||||||||||
| 212 | ERR_STRING_DATA *str = &SYS_str_reasons[i - 1]; | - | ||||||||||||
| 213 | - | |||||||||||||
| 214 | str->error = ERR_PACK(ERR_LIB_SYS, 0, i); | - | ||||||||||||
| 215 | if (str->string == NULL) {
| 0-263398 | ||||||||||||
| 216 | char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]); | - | ||||||||||||
| 217 | if (openssl_strerror_r(i, *dest, sizeof(*dest)))
| 39406-223992 | ||||||||||||
| 218 | str->string = *dest; executed 223992 times by 11 tests: str->string = *dest;Executed by:
| 223992 | ||||||||||||
| 219 | } executed 263398 times by 11 tests: end of blockExecuted by:
| 263398 | ||||||||||||
| 220 | if (str->string == NULL)
| 39406-223992 | ||||||||||||
| 221 | str->string = "unknown"; executed 39406 times by 11 tests: str->string = "unknown";Executed by:
| 39406 | ||||||||||||
| 222 | } executed 263398 times by 11 tests: end of blockExecuted by:
| 263398 | ||||||||||||
| 223 | - | |||||||||||||
| 224 | /* | - | ||||||||||||
| 225 | * Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, as | - | ||||||||||||
| 226 | * required by ERR_load_strings. | - | ||||||||||||
| 227 | */ | - | ||||||||||||
| 228 | - | |||||||||||||
| 229 | init = 0; | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 232 | err_load_strings(SYS_str_reasons); | - | ||||||||||||
| 233 | } executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 234 | #endif | - | ||||||||||||
| 235 | - | |||||||||||||
| 236 | #define err_clear_data(p, i) \ | - | ||||||||||||
| 237 | do { \ | - | ||||||||||||
| 238 | if ((p)->err_data_flags[i] & ERR_TXT_MALLOCED) {\ | - | ||||||||||||
| 239 | OPENSSL_free((p)->err_data[i]); \ | - | ||||||||||||
| 240 | (p)->err_data[i] = NULL; \ | - | ||||||||||||
| 241 | } \ | - | ||||||||||||
| 242 | (p)->err_data_flags[i] = 0; \ | - | ||||||||||||
| 243 | } while (0) | - | ||||||||||||
| 244 | - | |||||||||||||
| 245 | #define err_clear(p, i) \ | - | ||||||||||||
| 246 | do { \ | - | ||||||||||||
| 247 | err_clear_data(p, i); \ | - | ||||||||||||
| 248 | (p)->err_flags[i] = 0; \ | - | ||||||||||||
| 249 | (p)->err_buffer[i] = 0; \ | - | ||||||||||||
| 250 | (p)->err_file[i] = NULL; \ | - | ||||||||||||
| 251 | (p)->err_line[i] = -1; \ | - | ||||||||||||
| 252 | } while (0) | - | ||||||||||||
| 253 | - | |||||||||||||
| 254 | static void ERR_STATE_free(ERR_STATE *s) | - | ||||||||||||
| 255 | { | - | ||||||||||||
| 256 | int i; | - | ||||||||||||
| 257 | - | |||||||||||||
| 258 | if (s == NULL)
| 0-2074 | ||||||||||||
| 259 | return; never executed: return; | 0 | ||||||||||||
| 260 | for (i = 0; i < ERR_NUM_ERRORS; i++) {
| 2074-33184 | ||||||||||||
| 261 | err_clear_data(s, i); executed 83 times by 1 test: end of blockExecuted by:
| 83-33101 | ||||||||||||
| 262 | } executed 33184 times by 11 tests: end of blockExecuted by:
| 33184 | ||||||||||||
| 263 | OPENSSL_free(s); | - | ||||||||||||
| 264 | } executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 265 | - | |||||||||||||
| 266 | DEFINE_RUN_ONCE_STATIC(do_err_strings_init) executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 267 | { | - | ||||||||||||
| 268 | if (!OPENSSL_init_crypto(0, NULL))
| 0-2074 | ||||||||||||
| 269 | return 0; never executed: return 0; | 0 | ||||||||||||
| 270 | err_string_lock = CRYPTO_THREAD_lock_new(); | - | ||||||||||||
| 271 | if (err_string_lock == NULL)
| 0-2074 | ||||||||||||
| 272 | return 0; never executed: return 0; | 0 | ||||||||||||
| 273 | int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash, | - | ||||||||||||
| 274 | err_string_data_cmp); | - | ||||||||||||
| 275 | if (int_error_hash == NULL) {
| 0-2074 | ||||||||||||
| 276 | CRYPTO_THREAD_lock_free(err_string_lock); | - | ||||||||||||
| 277 | err_string_lock = NULL; | - | ||||||||||||
| 278 | return 0; never executed: return 0; | 0 | ||||||||||||
| 279 | } | - | ||||||||||||
| 280 | return 1; executed 2074 times by 11 tests: return 1;Executed by:
| 2074 | ||||||||||||
| 281 | } | - | ||||||||||||
| 282 | - | |||||||||||||
| 283 | void err_cleanup(void) | - | ||||||||||||
| 284 | { | - | ||||||||||||
| 285 | if (set_err_thread_local != 0)
| 2-2074 | ||||||||||||
| 286 | CRYPTO_THREAD_cleanup_local(&err_thread_local); executed 2074 times by 11 tests: CRYPTO_THREAD_cleanup_local(&err_thread_local);Executed by:
| 2074 | ||||||||||||
| 287 | CRYPTO_THREAD_lock_free(err_string_lock); | - | ||||||||||||
| 288 | err_string_lock = NULL; | - | ||||||||||||
| 289 | lh_ERR_STRING_DATA_free(int_error_hash); | - | ||||||||||||
| 290 | int_error_hash = NULL; | - | ||||||||||||
| 291 | } executed 2076 times by 12 tests: end of blockExecuted by:
| 2076 | ||||||||||||
| 292 | - | |||||||||||||
| 293 | /* | - | ||||||||||||
| 294 | * Legacy; pack in the library. | - | ||||||||||||
| 295 | */ | - | ||||||||||||
| 296 | static void err_patch(int lib, ERR_STRING_DATA *str) | - | ||||||||||||
| 297 | { | - | ||||||||||||
| 298 | unsigned long plib = ERR_PACK(lib, 0, 0); | - | ||||||||||||
| 299 | - | |||||||||||||
| 300 | for (; str->error != 0; str++)
| 124930-2857581 | ||||||||||||
| 301 | str->error |= plib; executed 2857581 times by 11 tests: str->error |= plib;Executed by:
| 2857581 | ||||||||||||
| 302 | } executed 124930 times by 11 tests: end of blockExecuted by:
| 124930 | ||||||||||||
| 303 | - | |||||||||||||
| 304 | /* | - | ||||||||||||
| 305 | * Hash in |str| error strings. Assumes the URN_ONCE was done. | - | ||||||||||||
| 306 | */ | - | ||||||||||||
| 307 | static int err_load_strings(const ERR_STRING_DATA *str) | - | ||||||||||||
| 308 | { | - | ||||||||||||
| 309 | CRYPTO_THREAD_write_lock(err_string_lock); | - | ||||||||||||
| 310 | for (; str->error; str++)
| 496776-16141763 | ||||||||||||
| 311 | (void)lh_ERR_STRING_DATA_insert(int_error_hash, executed 16141763 times by 11 tests: (void)lh_ERR_STRING_DATA_insert(int_error_hash, (ERR_STRING_DATA *)str);Executed by:
| 16141763 | ||||||||||||
| 312 | (ERR_STRING_DATA *)str); executed 16141763 times by 11 tests: (void)lh_ERR_STRING_DATA_insert(int_error_hash, (ERR_STRING_DATA *)str);Executed by:
| 16141763 | ||||||||||||
| 313 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 314 | return 1; executed 496776 times by 11 tests: return 1;Executed by:
| 496776 | ||||||||||||
| 315 | } | - | ||||||||||||
| 316 | - | |||||||||||||
| 317 | int ERR_load_ERR_strings(void) | - | ||||||||||||
| 318 | { | - | ||||||||||||
| 319 | #ifndef OPENSSL_NO_ERR | - | ||||||||||||
| 320 | if (!RUN_ONCE(&err_string_init, do_err_strings_init))
| 0-124194 | ||||||||||||
| 321 | return 0; never executed: return 0; | 0 | ||||||||||||
| 322 | - | |||||||||||||
| 323 | err_load_strings(ERR_str_libraries); | - | ||||||||||||
| 324 | err_load_strings(ERR_str_reasons); | - | ||||||||||||
| 325 | err_patch(ERR_LIB_SYS, ERR_str_functs); | - | ||||||||||||
| 326 | err_load_strings(ERR_str_functs); | - | ||||||||||||
| 327 | build_SYS_str_reasons(); | - | ||||||||||||
| 328 | #endif | - | ||||||||||||
| 329 | return 1; executed 124194 times by 11 tests: return 1;Executed by:
| 124194 | ||||||||||||
| 330 | } | - | ||||||||||||
| 331 | - | |||||||||||||
| 332 | int ERR_load_strings(int lib, ERR_STRING_DATA *str) | - | ||||||||||||
| 333 | { | - | ||||||||||||
| 334 | if (ERR_load_ERR_strings() == 0)
| 0-736 | ||||||||||||
| 335 | return 0; never executed: return 0; | 0 | ||||||||||||
| 336 | - | |||||||||||||
| 337 | err_patch(lib, str); | - | ||||||||||||
| 338 | err_load_strings(str); | - | ||||||||||||
| 339 | return 1; executed 736 times by 1 test: return 1;Executed by:
| 736 | ||||||||||||
| 340 | } | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | int ERR_load_strings_const(const ERR_STRING_DATA *str) | - | ||||||||||||
| 343 | { | - | ||||||||||||
| 344 | if (ERR_load_ERR_strings() == 0)
| 0-121384 | ||||||||||||
| 345 | return 0; never executed: return 0; | 0 | ||||||||||||
| 346 | err_load_strings(str); | - | ||||||||||||
| 347 | return 1; executed 121384 times by 11 tests: return 1;Executed by:
| 121384 | ||||||||||||
| 348 | } | - | ||||||||||||
| 349 | - | |||||||||||||
| 350 | int ERR_unload_strings(int lib, ERR_STRING_DATA *str) | - | ||||||||||||
| 351 | { | - | ||||||||||||
| 352 | if (!RUN_ONCE(&err_string_init, do_err_strings_init))
| 0-736 | ||||||||||||
| 353 | return 0; never executed: return 0; | 0 | ||||||||||||
| 354 | - | |||||||||||||
| 355 | CRYPTO_THREAD_write_lock(err_string_lock); | - | ||||||||||||
| 356 | /* | - | ||||||||||||
| 357 | * We don't need to ERR_PACK the lib, since that was done (to | - | ||||||||||||
| 358 | * the table) when it was loaded. | - | ||||||||||||
| 359 | */ | - | ||||||||||||
| 360 | for (; str->error; str++)
| 736-1119 | ||||||||||||
| 361 | (void)lh_ERR_STRING_DATA_delete(int_error_hash, str); executed 1119 times by 1 test: (void)lh_ERR_STRING_DATA_delete(int_error_hash, str);Executed by:
| 1119 | ||||||||||||
| 362 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 363 | - | |||||||||||||
| 364 | return 1; executed 736 times by 1 test: return 1;Executed by:
| 736 | ||||||||||||
| 365 | } | - | ||||||||||||
| 366 | - | |||||||||||||
| 367 | void err_free_strings_int(void) | - | ||||||||||||
| 368 | { | - | ||||||||||||
| 369 | if (!RUN_ONCE(&err_string_init, do_err_strings_init))
| 0-2620 | ||||||||||||
| 370 | return; never executed: return; | 0 | ||||||||||||
| 371 | } executed 2620 times by 11 tests: end of blockExecuted by:
| 2620 | ||||||||||||
| 372 | - | |||||||||||||
| 373 | /********************************************************/ | - | ||||||||||||
| 374 | - | |||||||||||||
| 375 | void ERR_put_error(int lib, int func, int reason, const char *file, int line) | - | ||||||||||||
| 376 | { | - | ||||||||||||
| 377 | ERR_STATE *es; | - | ||||||||||||
| 378 | - | |||||||||||||
| 379 | #ifdef _OSD_POSIX | - | ||||||||||||
| 380 | /* | - | ||||||||||||
| 381 | * In the BS2000-OSD POSIX subsystem, the compiler generates path names | - | ||||||||||||
| 382 | * in the form "*POSIX(/etc/passwd)". This dirty hack strips them to | - | ||||||||||||
| 383 | * something sensible. @@@ We shouldn't modify a const string, though. | - | ||||||||||||
| 384 | */ | - | ||||||||||||
| 385 | if (strncmp(file, "*POSIX(", sizeof("*POSIX(") - 1) == 0) { | - | ||||||||||||
| 386 | char *end; | - | ||||||||||||
| 387 | - | |||||||||||||
| 388 | /* Skip the "*POSIX(" prefix */ | - | ||||||||||||
| 389 | file += sizeof("*POSIX(") - 1; | - | ||||||||||||
| 390 | end = &file[strlen(file) - 1]; | - | ||||||||||||
| 391 | if (*end == ')') | - | ||||||||||||
| 392 | *end = '\0'; | - | ||||||||||||
| 393 | /* Optional: use the basename of the path only. */ | - | ||||||||||||
| 394 | if ((end = strrchr(file, '/')) != NULL) | - | ||||||||||||
| 395 | file = &end[1]; | - | ||||||||||||
| 396 | } | - | ||||||||||||
| 397 | #endif | - | ||||||||||||
| 398 | es = ERR_get_state(); | - | ||||||||||||
| 399 | if (es == NULL)
| 0-1802120 | ||||||||||||
| 400 | return; never executed: return; | 0 | ||||||||||||
| 401 | - | |||||||||||||
| 402 | es->top = (es->top + 1) % ERR_NUM_ERRORS; | - | ||||||||||||
| 403 | if (es->top == es->bottom)
| 226501-1575619 | ||||||||||||
| 404 | es->bottom = (es->bottom + 1) % ERR_NUM_ERRORS; executed 1575619 times by 1 test: es->bottom = (es->bottom + 1) % 16;Executed by:
| 1575619 | ||||||||||||
| 405 | es->err_flags[es->top] = 0; | - | ||||||||||||
| 406 | es->err_buffer[es->top] = ERR_PACK(lib, func, reason); | - | ||||||||||||
| 407 | es->err_file[es->top] = file; | - | ||||||||||||
| 408 | es->err_line[es->top] = line; | - | ||||||||||||
| 409 | err_clear_data(es, es->top); executed 582688 times by 1 test: end of blockExecuted by:
| 582688-1219432 | ||||||||||||
| 410 | } executed 1802120 times by 1 test: end of blockExecuted by:
| 1802120 | ||||||||||||
| 411 | - | |||||||||||||
| 412 | void ERR_clear_error(void) | - | ||||||||||||
| 413 | { | - | ||||||||||||
| 414 | int i; | - | ||||||||||||
| 415 | ERR_STATE *es; | - | ||||||||||||
| 416 | - | |||||||||||||
| 417 | es = ERR_get_state(); | - | ||||||||||||
| 418 | if (es == NULL)
| 0-1135407 | ||||||||||||
| 419 | return; never executed: return; | 0 | ||||||||||||
| 420 | - | |||||||||||||
| 421 | for (i = 0; i < ERR_NUM_ERRORS; i++) {
| 1135407-18166512 | ||||||||||||
| 422 | err_clear(es, i); executed 41604 times by 1 test: end of blockExecuted by:
| 41604-18124908 | ||||||||||||
| 423 | } executed 18166512 times by 11 tests: end of blockExecuted by:
| 18166512 | ||||||||||||
| 424 | es->top = es->bottom = 0; | - | ||||||||||||
| 425 | } executed 1135407 times by 11 tests: end of blockExecuted by:
| 1135407 | ||||||||||||
| 426 | - | |||||||||||||
| 427 | unsigned long ERR_get_error(void) | - | ||||||||||||
| 428 | { | - | ||||||||||||
| 429 | return get_error_values(1, 0, NULL, NULL, NULL, NULL); executed 9 times by 1 test: return get_error_values(1, 0, ((void *)0) , ((void *)0) , ((void *)0) , ((void *)0) );Executed by:
| 9 | ||||||||||||
| 430 | } | - | ||||||||||||
| 431 | - | |||||||||||||
| 432 | unsigned long ERR_get_error_line(const char **file, int *line) | - | ||||||||||||
| 433 | { | - | ||||||||||||
| 434 | return get_error_values(1, 0, file, line, NULL, NULL); never executed: return get_error_values(1, 0, file, line, ((void *)0) , ((void *)0) ); | 0 | ||||||||||||
| 435 | } | - | ||||||||||||
| 436 | - | |||||||||||||
| 437 | unsigned long ERR_get_error_line_data(const char **file, int *line, | - | ||||||||||||
| 438 | const char **data, int *flags) | - | ||||||||||||
| 439 | { | - | ||||||||||||
| 440 | return get_error_values(1, 0, file, line, data, flags); executed 9895 times by 1 test: return get_error_values(1, 0, file, line, data, flags);Executed by:
| 9895 | ||||||||||||
| 441 | } | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | unsigned long ERR_peek_error(void) | - | ||||||||||||
| 444 | { | - | ||||||||||||
| 445 | return get_error_values(0, 0, NULL, NULL, NULL, NULL); executed 70029 times by 1 test: return get_error_values(0, 0, ((void *)0) , ((void *)0) , ((void *)0) , ((void *)0) );Executed by:
| 70029 | ||||||||||||
| 446 | } | - | ||||||||||||
| 447 | - | |||||||||||||
| 448 | unsigned long ERR_peek_error_line(const char **file, int *line) | - | ||||||||||||
| 449 | { | - | ||||||||||||
| 450 | return get_error_values(0, 0, file, line, NULL, NULL); never executed: return get_error_values(0, 0, file, line, ((void *)0) , ((void *)0) ); | 0 | ||||||||||||
| 451 | } | - | ||||||||||||
| 452 | - | |||||||||||||
| 453 | unsigned long ERR_peek_error_line_data(const char **file, int *line, | - | ||||||||||||
| 454 | const char **data, int *flags) | - | ||||||||||||
| 455 | { | - | ||||||||||||
| 456 | return get_error_values(0, 0, file, line, data, flags); never executed: return get_error_values(0, 0, file, line, data, flags); | 0 | ||||||||||||
| 457 | } | - | ||||||||||||
| 458 | - | |||||||||||||
| 459 | unsigned long ERR_peek_last_error(void) | - | ||||||||||||
| 460 | { | - | ||||||||||||
| 461 | return get_error_values(0, 1, NULL, NULL, NULL, NULL); executed 11467 times by 1 test: return get_error_values(0, 1, ((void *)0) , ((void *)0) , ((void *)0) , ((void *)0) );Executed by:
| 11467 | ||||||||||||
| 462 | } | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | unsigned long ERR_peek_last_error_line(const char **file, int *line) | - | ||||||||||||
| 465 | { | - | ||||||||||||
| 466 | return get_error_values(0, 1, file, line, NULL, NULL); never executed: return get_error_values(0, 1, file, line, ((void *)0) , ((void *)0) ); | 0 | ||||||||||||
| 467 | } | - | ||||||||||||
| 468 | - | |||||||||||||
| 469 | unsigned long ERR_peek_last_error_line_data(const char **file, int *line, | - | ||||||||||||
| 470 | const char **data, int *flags) | - | ||||||||||||
| 471 | { | - | ||||||||||||
| 472 | return get_error_values(0, 1, file, line, data, flags); never executed: return get_error_values(0, 1, file, line, data, flags); | 0 | ||||||||||||
| 473 | } | - | ||||||||||||
| 474 | - | |||||||||||||
| 475 | static unsigned long get_error_values(int inc, int top, const char **file, | - | ||||||||||||
| 476 | int *line, const char **data, | - | ||||||||||||
| 477 | int *flags) | - | ||||||||||||
| 478 | { | - | ||||||||||||
| 479 | int i = 0; | - | ||||||||||||
| 480 | ERR_STATE *es; | - | ||||||||||||
| 481 | unsigned long ret; | - | ||||||||||||
| 482 | - | |||||||||||||
| 483 | es = ERR_get_state(); | - | ||||||||||||
| 484 | if (es == NULL)
| 0-91400 | ||||||||||||
| 485 | return 0; never executed: return 0; | 0 | ||||||||||||
| 486 | - | |||||||||||||
| 487 | if (inc && top) {
| 0-81496 | ||||||||||||
| 488 | if (file)
| 0 | ||||||||||||
| 489 | *file = ""; never executed: *file = ""; | 0 | ||||||||||||
| 490 | if (line)
| 0 | ||||||||||||
| 491 | *line = 0; never executed: *line = 0; | 0 | ||||||||||||
| 492 | if (data)
| 0 | ||||||||||||
| 493 | *data = ""; never executed: *data = ""; | 0 | ||||||||||||
| 494 | if (flags)
| 0 | ||||||||||||
| 495 | *flags = 0; never executed: *flags = 0; | 0 | ||||||||||||
| 496 | - | |||||||||||||
| 497 | return ERR_R_INTERNAL_ERROR; never executed: return (4|64); | 0 | ||||||||||||
| 498 | } | - | ||||||||||||
| 499 | - | |||||||||||||
| 500 | if (es->bottom == es->top)
| 38446-52954 | ||||||||||||
| 501 | return 0; executed 38446 times by 1 test: return 0;Executed by:
| 38446 | ||||||||||||
| 502 | if (top)
| 11467-41487 | ||||||||||||
| 503 | i = es->top; /* last error */ executed 11467 times by 1 test: i = es->top;Executed by:
| 11467 | ||||||||||||
| 504 | else | - | ||||||||||||
| 505 | i = (es->bottom + 1) % ERR_NUM_ERRORS; /* first error */ executed 41487 times by 1 test: i = (es->bottom + 1) % 16;Executed by:
| 41487 | ||||||||||||
| 506 | - | |||||||||||||
| 507 | ret = es->err_buffer[i]; | - | ||||||||||||
| 508 | if (inc) {
| 3982-48972 | ||||||||||||
| 509 | es->bottom = i; | - | ||||||||||||
| 510 | es->err_buffer[i] = 0; | - | ||||||||||||
| 511 | } executed 3982 times by 1 test: end of blockExecuted by:
| 3982 | ||||||||||||
| 512 | - | |||||||||||||
| 513 | if (file != NULL && line != NULL) {
| 0-48976 | ||||||||||||
| 514 | if (es->err_file[i] == NULL) {
| 0-3978 | ||||||||||||
| 515 | *file = "NA"; | - | ||||||||||||
| 516 | *line = 0; | - | ||||||||||||
| 517 | } else { never executed: end of block | 0 | ||||||||||||
| 518 | *file = es->err_file[i]; | - | ||||||||||||
| 519 | *line = es->err_line[i]; | - | ||||||||||||
| 520 | } executed 3978 times by 1 test: end of blockExecuted by:
| 3978 | ||||||||||||
| 521 | } | - | ||||||||||||
| 522 | - | |||||||||||||
| 523 | if (data == NULL) {
| 3978-48976 | ||||||||||||
| 524 | if (inc) {
| 4-48972 | ||||||||||||
| 525 | err_clear_data(es, i); never executed: end of block
| 0-4 | ||||||||||||
| 526 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||
| 527 | } else { executed 48976 times by 1 test: end of blockExecuted by:
| 48976 | ||||||||||||
| 528 | if (es->err_data[i] == NULL) {
| 490-3488 | ||||||||||||
| 529 | *data = ""; | - | ||||||||||||
| 530 | if (flags != NULL)
| 0-3488 | ||||||||||||
| 531 | *flags = 0; executed 3488 times by 1 test: *flags = 0;Executed by:
| 3488 | ||||||||||||
| 532 | } else { executed 3488 times by 1 test: end of blockExecuted by:
| 3488 | ||||||||||||
| 533 | *data = es->err_data[i]; | - | ||||||||||||
| 534 | if (flags != NULL)
| 0-490 | ||||||||||||
| 535 | *flags = es->err_data_flags[i]; executed 490 times by 1 test: *flags = es->err_data_flags[i];Executed by:
| 490 | ||||||||||||
| 536 | } executed 490 times by 1 test: end of blockExecuted by:
| 490 | ||||||||||||
| 537 | } | - | ||||||||||||
| 538 | return ret; executed 52954 times by 1 test: return ret;Executed by:
| 52954 | ||||||||||||
| 539 | } | - | ||||||||||||
| 540 | - | |||||||||||||
| 541 | void ERR_error_string_n(unsigned long e, char *buf, size_t len) | - | ||||||||||||
| 542 | { | - | ||||||||||||
| 543 | char lsbuf[64], fsbuf[64], rsbuf[64]; | - | ||||||||||||
| 544 | const char *ls, *fs, *rs; | - | ||||||||||||
| 545 | unsigned long l, f, r; | - | ||||||||||||
| 546 | - | |||||||||||||
| 547 | if (len == 0)
| 0-3978 | ||||||||||||
| 548 | return; never executed: return; | 0 | ||||||||||||
| 549 | - | |||||||||||||
| 550 | l = ERR_GET_LIB(e); | - | ||||||||||||
| 551 | ls = ERR_lib_error_string(e); | - | ||||||||||||
| 552 | if (ls == NULL) {
| 0-3978 | ||||||||||||
| 553 | BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l); | - | ||||||||||||
| 554 | ls = lsbuf; | - | ||||||||||||
| 555 | } never executed: end of block | 0 | ||||||||||||
| 556 | - | |||||||||||||
| 557 | fs = ERR_func_error_string(e); | - | ||||||||||||
| 558 | f = ERR_GET_FUNC(e); | - | ||||||||||||
| 559 | if (fs == NULL) {
| 0-3978 | ||||||||||||
| 560 | BIO_snprintf(fsbuf, sizeof(fsbuf), "func(%lu)", f); | - | ||||||||||||
| 561 | fs = fsbuf; | - | ||||||||||||
| 562 | } never executed: end of block | 0 | ||||||||||||
| 563 | - | |||||||||||||
| 564 | rs = ERR_reason_error_string(e); | - | ||||||||||||
| 565 | r = ERR_GET_REASON(e); | - | ||||||||||||
| 566 | if (rs == NULL) {
| 0-3978 | ||||||||||||
| 567 | BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r); | - | ||||||||||||
| 568 | rs = rsbuf; | - | ||||||||||||
| 569 | } never executed: end of block | 0 | ||||||||||||
| 570 | - | |||||||||||||
| 571 | BIO_snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, fs, rs); | - | ||||||||||||
| 572 | if (strlen(buf) == len - 1) {
| 0-3978 | ||||||||||||
| 573 | /* Didn't fit; use a minimal format. */ | - | ||||||||||||
| 574 | BIO_snprintf(buf, len, "err:%lx:%lx:%lx:%lx", e, l, f, r); | - | ||||||||||||
| 575 | } never executed: end of block | 0 | ||||||||||||
| 576 | } executed 3978 times by 1 test: end of blockExecuted by:
| 3978 | ||||||||||||
| 577 | - | |||||||||||||
| 578 | /* | - | ||||||||||||
| 579 | * ERR_error_string_n should be used instead for ret != NULL as | - | ||||||||||||
| 580 | * ERR_error_string cannot know how large the buffer is | - | ||||||||||||
| 581 | */ | - | ||||||||||||
| 582 | char *ERR_error_string(unsigned long e, char *ret) | - | ||||||||||||
| 583 | { | - | ||||||||||||
| 584 | static char buf[256]; | - | ||||||||||||
| 585 | - | |||||||||||||
| 586 | if (ret == NULL)
| 0 | ||||||||||||
| 587 | ret = buf; never executed: ret = buf; | 0 | ||||||||||||
| 588 | ERR_error_string_n(e, ret, (int)sizeof(buf)); | - | ||||||||||||
| 589 | return ret; never executed: return ret; | 0 | ||||||||||||
| 590 | } | - | ||||||||||||
| 591 | - | |||||||||||||
| 592 | const char *ERR_lib_error_string(unsigned long e) | - | ||||||||||||
| 593 | { | - | ||||||||||||
| 594 | ERR_STRING_DATA d, *p; | - | ||||||||||||
| 595 | unsigned long l; | - | ||||||||||||
| 596 | - | |||||||||||||
| 597 | if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
| 0-3978 | ||||||||||||
| 598 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 599 | } | - | ||||||||||||
| 600 | - | |||||||||||||
| 601 | l = ERR_GET_LIB(e); | - | ||||||||||||
| 602 | d.error = ERR_PACK(l, 0, 0); | - | ||||||||||||
| 603 | p = int_err_get_item(&d); | - | ||||||||||||
| 604 | return ((p == NULL) ? NULL : p->string); executed 3978 times by 1 test: return ((p == ((void *)0) ) ? ((void *)0) : p->string);Executed by:
| 0-3978 | ||||||||||||
| 605 | } | - | ||||||||||||
| 606 | - | |||||||||||||
| 607 | const char *ERR_func_error_string(unsigned long e) | - | ||||||||||||
| 608 | { | - | ||||||||||||
| 609 | ERR_STRING_DATA d, *p; | - | ||||||||||||
| 610 | unsigned long l, f; | - | ||||||||||||
| 611 | - | |||||||||||||
| 612 | if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
| 0-64765 | ||||||||||||
| 613 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 614 | } | - | ||||||||||||
| 615 | - | |||||||||||||
| 616 | l = ERR_GET_LIB(e); | - | ||||||||||||
| 617 | f = ERR_GET_FUNC(e); | - | ||||||||||||
| 618 | d.error = ERR_PACK(l, f, 0); | - | ||||||||||||
| 619 | p = int_err_get_item(&d); | - | ||||||||||||
| 620 | return ((p == NULL) ? NULL : p->string); executed 64765 times by 11 tests: return ((p == ((void *)0) ) ? ((void *)0) : p->string);Executed by:
| 4073-64765 | ||||||||||||
| 621 | } | - | ||||||||||||
| 622 | - | |||||||||||||
| 623 | const char *ERR_reason_error_string(unsigned long e) | - | ||||||||||||
| 624 | { | - | ||||||||||||
| 625 | ERR_STRING_DATA d, *p = NULL; | - | ||||||||||||
| 626 | unsigned long l, r; | - | ||||||||||||
| 627 | - | |||||||||||||
| 628 | if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
| 0-4073 | ||||||||||||
| 629 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 630 | } | - | ||||||||||||
| 631 | - | |||||||||||||
| 632 | l = ERR_GET_LIB(e); | - | ||||||||||||
| 633 | r = ERR_GET_REASON(e); | - | ||||||||||||
| 634 | d.error = ERR_PACK(l, 0, r); | - | ||||||||||||
| 635 | p = int_err_get_item(&d); | - | ||||||||||||
| 636 | if (!p) {
| 1052-3021 | ||||||||||||
| 637 | d.error = ERR_PACK(0, 0, r); | - | ||||||||||||
| 638 | p = int_err_get_item(&d); | - | ||||||||||||
| 639 | } executed 1052 times by 1 test: end of blockExecuted by:
| 1052 | ||||||||||||
| 640 | return ((p == NULL) ? NULL : p->string); executed 4073 times by 1 test: return ((p == ((void *)0) ) ? ((void *)0) : p->string);Executed by:
| 0-4073 | ||||||||||||
| 641 | } | - | ||||||||||||
| 642 | - | |||||||||||||
| 643 | void err_delete_thread_state(void) | - | ||||||||||||
| 644 | { | - | ||||||||||||
| 645 | ERR_STATE *state = CRYPTO_THREAD_get_local(&err_thread_local); | - | ||||||||||||
| 646 | if (state == NULL)
| 0-2074 | ||||||||||||
| 647 | return; never executed: return; | 0 | ||||||||||||
| 648 | - | |||||||||||||
| 649 | CRYPTO_THREAD_set_local(&err_thread_local, NULL); | - | ||||||||||||
| 650 | ERR_STATE_free(state); | - | ||||||||||||
| 651 | } executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 652 | - | |||||||||||||
| 653 | #if OPENSSL_API_COMPAT < 0x10100000L | - | ||||||||||||
| 654 | void ERR_remove_thread_state(void *dummy) | - | ||||||||||||
| 655 | { | - | ||||||||||||
| 656 | } | - | ||||||||||||
| 657 | #endif | - | ||||||||||||
| 658 | - | |||||||||||||
| 659 | #if OPENSSL_API_COMPAT < 0x10000000L | - | ||||||||||||
| 660 | void ERR_remove_state(unsigned long pid) | - | ||||||||||||
| 661 | { | - | ||||||||||||
| 662 | } | - | ||||||||||||
| 663 | #endif | - | ||||||||||||
| 664 | - | |||||||||||||
| 665 | DEFINE_RUN_ONCE_STATIC(err_do_init) executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 666 | { | - | ||||||||||||
| 667 | set_err_thread_local = 1; | - | ||||||||||||
| 668 | return CRYPTO_THREAD_init_local(&err_thread_local, NULL); executed 2074 times by 11 tests: return CRYPTO_THREAD_init_local(&err_thread_local, ((void *)0) );Executed by:
| 2074 | ||||||||||||
| 669 | } | - | ||||||||||||
| 670 | - | |||||||||||||
| 671 | ERR_STATE *ERR_get_state(void) | - | ||||||||||||
| 672 | { | - | ||||||||||||
| 673 | ERR_STATE *state; | - | ||||||||||||
| 674 | - | |||||||||||||
| 675 | if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
| 0-3790084 | ||||||||||||
| 676 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 677 | - | |||||||||||||
| 678 | if (!RUN_ONCE(&err_init, err_do_init))
| 0-3790084 | ||||||||||||
| 679 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 680 | - | |||||||||||||
| 681 | state = CRYPTO_THREAD_get_local(&err_thread_local); | - | ||||||||||||
| 682 | if (state == (ERR_STATE*)-1)
| 0-3790084 | ||||||||||||
| 683 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 684 | - | |||||||||||||
| 685 | if (state == NULL) {
| 2074-3788010 | ||||||||||||
| 686 | if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
| 0-2074 | ||||||||||||
| 687 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 688 | - | |||||||||||||
| 689 | if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) {
| 0-2074 | ||||||||||||
| 690 | CRYPTO_THREAD_set_local(&err_thread_local, NULL); | - | ||||||||||||
| 691 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 692 | } | - | ||||||||||||
| 693 | - | |||||||||||||
| 694 | if (!ossl_init_thread_start(OPENSSL_INIT_THREAD_ERR_STATE)
| 0-2074 | ||||||||||||
| 695 | || !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
| 0-2074 | ||||||||||||
| 696 | ERR_STATE_free(state); | - | ||||||||||||
| 697 | CRYPTO_THREAD_set_local(&err_thread_local, NULL); | - | ||||||||||||
| 698 | return NULL; never executed: return ((void *)0) ; | 0 | ||||||||||||
| 699 | } | - | ||||||||||||
| 700 | - | |||||||||||||
| 701 | /* Ignore failures from these */ | - | ||||||||||||
| 702 | OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL); | - | ||||||||||||
| 703 | } executed 2074 times by 11 tests: end of blockExecuted by:
| 2074 | ||||||||||||
| 704 | - | |||||||||||||
| 705 | return state; executed 3790084 times by 11 tests: return state;Executed by:
| 3790084 | ||||||||||||
| 706 | } | - | ||||||||||||
| 707 | - | |||||||||||||
| 708 | /* | - | ||||||||||||
| 709 | * err_shelve_state returns the current thread local error state | - | ||||||||||||
| 710 | * and freezes the error module until err_unshelve_state is called. | - | ||||||||||||
| 711 | */ | - | ||||||||||||
| 712 | int err_shelve_state(void **state) | - | ||||||||||||
| 713 | { | - | ||||||||||||
| 714 | if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
| 0 | ||||||||||||
| 715 | return 0; never executed: return 0; | 0 | ||||||||||||
| 716 | - | |||||||||||||
| 717 | if (!RUN_ONCE(&err_init, err_do_init))
| 0 | ||||||||||||
| 718 | return 0; never executed: return 0; | 0 | ||||||||||||
| 719 | - | |||||||||||||
| 720 | *state = CRYPTO_THREAD_get_local(&err_thread_local); | - | ||||||||||||
| 721 | if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
| 0 | ||||||||||||
| 722 | return 0; never executed: return 0; | 0 | ||||||||||||
| 723 | - | |||||||||||||
| 724 | return 1; never executed: return 1; | 0 | ||||||||||||
| 725 | } | - | ||||||||||||
| 726 | - | |||||||||||||
| 727 | /* | - | ||||||||||||
| 728 | * err_unshelve_state restores the error state that was returned | - | ||||||||||||
| 729 | * by err_shelve_state previously. | - | ||||||||||||
| 730 | */ | - | ||||||||||||
| 731 | void err_unshelve_state(void* state) | - | ||||||||||||
| 732 | { | - | ||||||||||||
| 733 | if (state != (void*)-1)
| 0 | ||||||||||||
| 734 | CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)state); never executed: CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)state); | 0 | ||||||||||||
| 735 | } never executed: end of block | 0 | ||||||||||||
| 736 | - | |||||||||||||
| 737 | int ERR_get_next_error_library(void) | - | ||||||||||||
| 738 | { | - | ||||||||||||
| 739 | int ret; | - | ||||||||||||
| 740 | - | |||||||||||||
| 741 | if (!RUN_ONCE(&err_string_init, do_err_strings_init))
| 0-368 | ||||||||||||
| 742 | return 0; never executed: return 0; | 0 | ||||||||||||
| 743 | - | |||||||||||||
| 744 | CRYPTO_THREAD_write_lock(err_string_lock); | - | ||||||||||||
| 745 | ret = int_err_library_number++; | - | ||||||||||||
| 746 | CRYPTO_THREAD_unlock(err_string_lock); | - | ||||||||||||
| 747 | return ret; executed 368 times by 1 test: return ret;Executed by:
| 368 | ||||||||||||
| 748 | } | - | ||||||||||||
| 749 | - | |||||||||||||
| 750 | void ERR_set_error_data(char *data, int flags) | - | ||||||||||||
| 751 | { | - | ||||||||||||
| 752 | ERR_STATE *es; | - | ||||||||||||
| 753 | int i; | - | ||||||||||||
| 754 | - | |||||||||||||
| 755 | es = ERR_get_state(); | - | ||||||||||||
| 756 | if (es == NULL)
| 0-631004 | ||||||||||||
| 757 | return; never executed: return; | 0 | ||||||||||||
| 758 | - | |||||||||||||
| 759 | i = es->top; | - | ||||||||||||
| 760 | - | |||||||||||||
| 761 | err_clear_data(es, i); never executed: end of block
| 0-631004 | ||||||||||||
| 762 | es->err_data[i] = data; | - | ||||||||||||
| 763 | es->err_data_flags[i] = flags; | - | ||||||||||||
| 764 | } executed 631004 times by 1 test: end of blockExecuted by:
| 631004 | ||||||||||||
| 765 | - | |||||||||||||
| 766 | void ERR_add_error_data(int num, ...) | - | ||||||||||||
| 767 | { | - | ||||||||||||
| 768 | va_list args; | - | ||||||||||||
| 769 | va_start(args, num); | - | ||||||||||||
| 770 | ERR_add_error_vdata(num, args); | - | ||||||||||||
| 771 | va_end(args); | - | ||||||||||||
| 772 | } executed 631004 times by 1 test: end of blockExecuted by:
| 631004 | ||||||||||||
| 773 | - | |||||||||||||
| 774 | void ERR_add_error_vdata(int num, va_list args) | - | ||||||||||||
| 775 | { | - | ||||||||||||
| 776 | int i, n, s; | - | ||||||||||||
| 777 | char *str, *p, *a; | - | ||||||||||||
| 778 | - | |||||||||||||
| 779 | s = 80; | - | ||||||||||||
| 780 | if ((str = OPENSSL_malloc(s + 1)) == NULL) {
| 0-631004 | ||||||||||||
| 781 | /* ERRerr(ERR_F_ERR_ADD_ERROR_VDATA, ERR_R_MALLOC_FAILURE); */ | - | ||||||||||||
| 782 | return; never executed: return; | 0 | ||||||||||||
| 783 | } | - | ||||||||||||
| 784 | str[0] = '\0'; | - | ||||||||||||
| 785 | - | |||||||||||||
| 786 | n = 0; | - | ||||||||||||
| 787 | for (i = 0; i < num; i++) {
| 631004-2128056 | ||||||||||||
| 788 | a = va_arg(args, char *); | - | ||||||||||||
| 789 | if (a == NULL)
| 73-2127983 | ||||||||||||
| 790 | a = "<NULL>"; executed 73 times by 1 test: a = "<NULL>";Executed by:
| 73 | ||||||||||||
| 791 | n += strlen(a); | - | ||||||||||||
| 792 | if (n > s) {
| 218-2127838 | ||||||||||||
| 793 | s = n + 20; | - | ||||||||||||
| 794 | p = OPENSSL_realloc(str, s + 1); | - | ||||||||||||
| 795 | if (p == NULL) {
| 0-218 | ||||||||||||
| 796 | OPENSSL_free(str); | - | ||||||||||||
| 797 | return; never executed: return; | 0 | ||||||||||||
| 798 | } | - | ||||||||||||
| 799 | str = p; | - | ||||||||||||
| 800 | } executed 218 times by 1 test: end of blockExecuted by:
| 218 | ||||||||||||
| 801 | OPENSSL_strlcat(str, a, (size_t)s + 1); | - | ||||||||||||
| 802 | } executed 2128056 times by 1 test: end of blockExecuted by:
| 2128056 | ||||||||||||
| 803 | ERR_set_error_data(str, ERR_TXT_MALLOCED | ERR_TXT_STRING); | - | ||||||||||||
| 804 | } executed 631004 times by 1 test: end of blockExecuted by:
| 631004 | ||||||||||||
| 805 | - | |||||||||||||
| 806 | int ERR_set_mark(void) | - | ||||||||||||
| 807 | { | - | ||||||||||||
| 808 | ERR_STATE *es; | - | ||||||||||||
| 809 | - | |||||||||||||
| 810 | es = ERR_get_state(); | - | ||||||||||||
| 811 | if (es == NULL)
| 0-65103 | ||||||||||||
| 812 | return 0; never executed: return 0; | 0 | ||||||||||||
| 813 | - | |||||||||||||
| 814 | if (es->bottom == es->top)
| 9043-56060 | ||||||||||||
| 815 | return 0; executed 56060 times by 1 test: return 0;Executed by:
| 56060 | ||||||||||||
| 816 | es->err_flags[es->top] |= ERR_FLAG_MARK; | - | ||||||||||||
| 817 | return 1; executed 9043 times by 1 test: return 1;Executed by:
| 9043 | ||||||||||||
| 818 | } | - | ||||||||||||
| 819 | - | |||||||||||||
| 820 | int ERR_pop_to_mark(void) | - | ||||||||||||
| 821 | { | - | ||||||||||||
| 822 | ERR_STATE *es; | - | ||||||||||||
| 823 | - | |||||||||||||
| 824 | es = ERR_get_state(); | - | ||||||||||||
| 825 | if (es == NULL)
| 0-65039 | ||||||||||||
| 826 | return 0; never executed: return 0; | 0 | ||||||||||||
| 827 | - | |||||||||||||
| 828 | while (es->bottom != es->top
| 56373-79617 | ||||||||||||
| 829 | && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {
| 8666-70951 | ||||||||||||
| 830 | err_clear(es, es->top); executed 6629 times by 1 test: end of blockExecuted by:
| 6629-64322 | ||||||||||||
| 831 | es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
| 808-70143 | ||||||||||||
| 832 | } executed 70951 times by 1 test: end of blockExecuted by:
| 70951 | ||||||||||||
| 833 | - | |||||||||||||
| 834 | if (es->bottom == es->top)
| 8666-56373 | ||||||||||||
| 835 | return 0; executed 56373 times by 1 test: return 0;Executed by:
| 56373 | ||||||||||||
| 836 | es->err_flags[es->top] &= ~ERR_FLAG_MARK; | - | ||||||||||||
| 837 | return 1; executed 8666 times by 1 test: return 1;Executed by:
| 8666 | ||||||||||||
| 838 | } | - | ||||||||||||
| 839 | - | |||||||||||||
| 840 | int ERR_clear_last_mark(void) | - | ||||||||||||
| 841 | { | - | ||||||||||||
| 842 | ERR_STATE *es; | - | ||||||||||||
| 843 | int top; | - | ||||||||||||
| 844 | - | |||||||||||||
| 845 | es = ERR_get_state(); | - | ||||||||||||
| 846 | if (es == NULL)
| 0 | ||||||||||||
| 847 | return 0; never executed: return 0; | 0 | ||||||||||||
| 848 | - | |||||||||||||
| 849 | top = es->top; | - | ||||||||||||
| 850 | while (es->bottom != top
| 0 | ||||||||||||
| 851 | && (es->err_flags[top] & ERR_FLAG_MARK) == 0) {
| 0 | ||||||||||||
| 852 | top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
| 0 | ||||||||||||
| 853 | } never executed: end of block | 0 | ||||||||||||
| 854 | - | |||||||||||||
| 855 | if (es->bottom == top)
| 0 | ||||||||||||
| 856 | return 0; never executed: return 0; | 0 | ||||||||||||
| 857 | es->err_flags[top] &= ~ERR_FLAG_MARK; | - | ||||||||||||
| 858 | return 1; never executed: return 1; | 0 | ||||||||||||
| 859 | } | - | ||||||||||||
| Source code | Switch to Preprocessed file |