2016-05-18 03:38:09 +08:00
|
|
|
/*
|
2018-02-13 20:51:29 +08:00
|
|
|
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
|
2000-03-04 09:36:53 +08:00
|
|
|
*
|
2018-12-06 20:39:21 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 03:38:09 +08:00
|
|
|
* this file except in compliance with the License. You can obtain a copy
|
|
|
|
* in the file LICENSE in the source distribution or at
|
|
|
|
* https://www.openssl.org/source/license.html
|
2000-03-04 09:36:53 +08:00
|
|
|
*/
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-07-26 03:57:48 +08:00
|
|
|
/* TODO: When ERR_STATE becomes opaque, this musts be removed */
|
|
|
|
#define OSSL_FORCE_ERR_STATE
|
|
|
|
|
1998-12-21 18:52:47 +08:00
|
|
|
#include <stdio.h>
|
1999-05-05 20:35:27 +08:00
|
|
|
#include <stdarg.h>
|
2000-03-04 09:36:53 +08:00
|
|
|
#include <string.h>
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/cryptlib.h"
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/err.h"
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/err.h"
|
2017-06-08 03:12:03 +08:00
|
|
|
#include <openssl/err.h>
|
1999-04-24 06:13:45 +08:00
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/buffer.h>
|
2000-04-15 07:36:15 +08:00
|
|
|
#include <openssl/bio.h>
|
2016-01-05 12:00:33 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
2017-08-22 20:35:43 +08:00
|
|
|
#include "internal/thread_once.h"
|
2019-09-28 06:45:33 +08:00
|
|
|
#include "crypto/ctype.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "internal/constant_time.h"
|
2018-11-21 19:44:42 +08:00
|
|
|
#include "e_os.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "err_local.h"
|
2008-05-26 19:24:29 +08:00
|
|
|
|
2019-07-26 03:57:48 +08:00
|
|
|
/* Forward declaration in case it's not published because of configuration */
|
|
|
|
ERR_STATE *ERR_get_state(void);
|
|
|
|
|
2017-06-08 03:12:03 +08:00
|
|
|
static int err_load_strings(const ERR_STRING_DATA *str);
|
2001-09-04 19:49:14 +08:00
|
|
|
|
1998-12-21 18:56:39 +08:00
|
|
|
static void ERR_STATE_free(ERR_STATE *s);
|
2001-02-20 00:06:34 +08:00
|
|
|
#ifndef OPENSSL_NO_ERR
|
2015-01-22 11:40:55 +08:00
|
|
|
static ERR_STRING_DATA ERR_str_libraries[] = {
|
|
|
|
{ERR_PACK(ERR_LIB_NONE, 0, 0), "unknown library"},
|
|
|
|
{ERR_PACK(ERR_LIB_SYS, 0, 0), "system library"},
|
|
|
|
{ERR_PACK(ERR_LIB_BN, 0, 0), "bignum routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_RSA, 0, 0), "rsa routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_DH, 0, 0), "Diffie-Hellman routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_EVP, 0, 0), "digital envelope routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_BUF, 0, 0), "memory buffer routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_OBJ, 0, 0), "object identifier routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_PEM, 0, 0), "PEM routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_DSA, 0, 0), "dsa routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_X509, 0, 0), "x509 certificate routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_ASN1, 0, 0), "asn1 encoding routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_CONF, 0, 0), "configuration file routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_CRYPTO, 0, 0), "common libcrypto routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_EC, 0, 0), "elliptic curve routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_ECDSA, 0, 0), "ECDSA routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_ECDH, 0, 0), "ECDH routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_SSL, 0, 0), "SSL routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_BIO, 0, 0), "BIO routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_PKCS7, 0, 0), "PKCS7 routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_X509V3, 0, 0), "X509 V3 routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_PKCS12, 0, 0), "PKCS12 routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_RAND, 0, 0), "random number generator"},
|
|
|
|
{ERR_PACK(ERR_LIB_DSO, 0, 0), "DSO support routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_TS, 0, 0), "time stamp routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_ENGINE, 0, 0), "engine routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_OCSP, 0, 0), "OCSP routines"},
|
2016-12-08 18:16:37 +08:00
|
|
|
{ERR_PACK(ERR_LIB_UI, 0, 0), "UI routines"},
|
2015-01-22 11:40:55 +08:00
|
|
|
{ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"},
|
|
|
|
{ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"},
|
2018-11-16 21:05:31 +08:00
|
|
|
{ERR_PACK(ERR_LIB_CRMF, 0, 0), "CRMF routines"},
|
2019-04-02 17:16:53 +08:00
|
|
|
{ERR_PACK(ERR_LIB_CMP, 0, 0), "CMP routines"},
|
2015-01-22 11:40:55 +08:00
|
|
|
{ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"},
|
2016-02-26 02:11:16 +08:00
|
|
|
{ERR_PACK(ERR_LIB_CT, 0, 0), "CT routines"},
|
2015-10-06 21:47:00 +08:00
|
|
|
{ERR_PACK(ERR_LIB_ASYNC, 0, 0), "ASYNC routines"},
|
2019-11-10 12:16:36 +08:00
|
|
|
{ERR_PACK(ERR_LIB_KDF, 0, 0), "KDF routines"},
|
2016-12-08 22:51:31 +08:00
|
|
|
{ERR_PACK(ERR_LIB_OSSL_STORE, 0, 0), "STORE routines"},
|
2018-01-25 00:56:02 +08:00
|
|
|
{ERR_PACK(ERR_LIB_SM2, 0, 0), "SM2 routines"},
|
2018-12-13 06:08:49 +08:00
|
|
|
{ERR_PACK(ERR_LIB_ESS, 0, 0), "ESS routines"},
|
2019-04-19 00:43:05 +08:00
|
|
|
{ERR_PACK(ERR_LIB_PROV, 0, 0), "Provider routines"},
|
SERIALIZER: New API for serialization of objects through providers
Serialization is needed to be able to take a provider object (such as
the provider side key data) and output it in PEM form, DER form, text
form (for display), and possibly other future forms (XML? JSON? JWK?)
The idea is that a serializer should be able to handle objects it has
intimate knowledge of, as well as object data in OSSL_PARAM form. The
latter will allow libcrypto to serialize some object with a different
provider than the one holding the data, if exporting of that data is
allowed and there is a serializer that can handle it.
We will provide serializers for the types of objects we know about,
which should be useful together with any other provider that provides
implementations of the same type of object.
Serializers are selected by method name and a couple of additional
properties:
- format used to tell what format the output should be in.
Possibilities could include "format=text",
"format=pem", "format=der", "format=pem-pkcs1"
(traditional), "format=der-pkcs1" (traditional)
- type used to tell exactly what type of data should be
output, for example "type=public" (the public part of
a key), "type=private" (the private part of a key),
"type=domainparams" (domain parameters).
This also adds a passphrase callback function type,
OSSL_PASSPHRASE_CALLBACK, which is a bit like OSSL_CALLBACK, but it
takes a few extra arguments to place the result in.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10394)
2019-11-18 08:29:06 +08:00
|
|
|
{ERR_PACK(ERR_LIB_OSSL_SERIALIZER, 0, 0), "SERIALIZER routines"},
|
2019-10-31 06:39:35 +08:00
|
|
|
{ERR_PACK(ERR_LIB_HTTP, 0, 0), "HTTP routines"},
|
2015-01-22 11:40:55 +08:00
|
|
|
{0, NULL},
|
|
|
|
};
|
|
|
|
|
|
|
|
static ERR_STRING_DATA ERR_str_reasons[] = {
|
|
|
|
{ERR_R_SYS_LIB, "system lib"},
|
|
|
|
{ERR_R_BN_LIB, "BN lib"},
|
|
|
|
{ERR_R_RSA_LIB, "RSA lib"},
|
|
|
|
{ERR_R_DH_LIB, "DH lib"},
|
|
|
|
{ERR_R_EVP_LIB, "EVP lib"},
|
|
|
|
{ERR_R_BUF_LIB, "BUF lib"},
|
|
|
|
{ERR_R_OBJ_LIB, "OBJ lib"},
|
|
|
|
{ERR_R_PEM_LIB, "PEM lib"},
|
|
|
|
{ERR_R_DSA_LIB, "DSA lib"},
|
|
|
|
{ERR_R_X509_LIB, "X509 lib"},
|
|
|
|
{ERR_R_ASN1_LIB, "ASN1 lib"},
|
|
|
|
{ERR_R_EC_LIB, "EC lib"},
|
|
|
|
{ERR_R_BIO_LIB, "BIO lib"},
|
|
|
|
{ERR_R_PKCS7_LIB, "PKCS7 lib"},
|
|
|
|
{ERR_R_X509V3_LIB, "X509V3 lib"},
|
|
|
|
{ERR_R_ENGINE_LIB, "ENGINE lib"},
|
2016-12-06 11:29:08 +08:00
|
|
|
{ERR_R_UI_LIB, "UI lib"},
|
2016-12-08 22:51:31 +08:00
|
|
|
{ERR_R_OSSL_STORE_LIB, "STORE lib"},
|
2015-01-22 11:40:55 +08:00
|
|
|
{ERR_R_ECDSA_LIB, "ECDSA lib"},
|
|
|
|
|
|
|
|
{ERR_R_NESTED_ASN1_ERROR, "nested asn1 error"},
|
|
|
|
{ERR_R_MISSING_ASN1_EOS, "missing asn1 eos"},
|
|
|
|
|
|
|
|
{ERR_R_FATAL, "fatal"},
|
|
|
|
{ERR_R_MALLOC_FAILURE, "malloc failure"},
|
|
|
|
{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED,
|
|
|
|
"called a function you should not call"},
|
|
|
|
{ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"},
|
|
|
|
{ERR_R_INTERNAL_ERROR, "internal error"},
|
|
|
|
{ERR_R_DISABLED, "called a function that was disabled at compile-time"},
|
2016-02-10 23:16:06 +08:00
|
|
|
{ERR_R_INIT_FAIL, "init fail"},
|
2017-06-27 22:05:12 +08:00
|
|
|
{ERR_R_OPERATION_FAIL, "operation fail"},
|
SERIALIZER: New API for serialization of objects through providers
Serialization is needed to be able to take a provider object (such as
the provider side key data) and output it in PEM form, DER form, text
form (for display), and possibly other future forms (XML? JSON? JWK?)
The idea is that a serializer should be able to handle objects it has
intimate knowledge of, as well as object data in OSSL_PARAM form. The
latter will allow libcrypto to serialize some object with a different
provider than the one holding the data, if exporting of that data is
allowed and there is a serializer that can handle it.
We will provide serializers for the types of objects we know about,
which should be useful together with any other provider that provides
implementations of the same type of object.
Serializers are selected by method name and a couple of additional
properties:
- format used to tell what format the output should be in.
Possibilities could include "format=text",
"format=pem", "format=der", "format=pem-pkcs1"
(traditional), "format=der-pkcs1" (traditional)
- type used to tell exactly what type of data should be
output, for example "type=public" (the public part of
a key), "type=private" (the private part of a key),
"type=domainparams" (domain parameters).
This also adds a passphrase callback function type,
OSSL_PASSPHRASE_CALLBACK, which is a bit like OSSL_CALLBACK, but it
takes a few extra arguments to place the result in.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10394)
2019-11-18 08:29:06 +08:00
|
|
|
{ERR_R_INVALID_PROVIDER_FUNCTIONS, "invalid provider functions"},
|
2019-11-18 08:34:26 +08:00
|
|
|
{ERR_R_INTERRUPTED_OR_CANCELLED, "interrupted or cancelled"},
|
2015-01-22 11:40:55 +08:00
|
|
|
|
|
|
|
{0, NULL},
|
|
|
|
};
|
1998-12-21 18:52:47 +08:00
|
|
|
#endif
|
2000-03-04 09:36:53 +08:00
|
|
|
|
2016-03-03 01:36:17 +08:00
|
|
|
static CRYPTO_ONCE err_init = CRYPTO_ONCE_STATIC_INIT;
|
2017-06-01 00:14:55 +08:00
|
|
|
static int set_err_thread_local;
|
2016-03-03 01:36:17 +08:00
|
|
|
static CRYPTO_THREAD_LOCAL err_thread_local;
|
|
|
|
|
2016-03-06 05:31:43 +08:00
|
|
|
static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT;
|
|
|
|
static CRYPTO_RWLOCK *err_string_lock;
|
|
|
|
|
2001-08-26 01:51:59 +08:00
|
|
|
static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *);
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
2015-04-28 22:50:54 +08:00
|
|
|
* The internal state
|
2015-01-22 11:40:55 +08:00
|
|
|
*/
|
2016-01-31 01:04:25 +08:00
|
|
|
|
2008-05-26 19:24:29 +08:00
|
|
|
static LHASH_OF(ERR_STRING_DATA) *int_error_hash = NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
static int int_err_library_number = ERR_LIB_USER;
|
2001-08-26 01:51:59 +08:00
|
|
|
|
2019-09-13 01:06:04 +08:00
|
|
|
typedef enum ERR_GET_ACTION_e {
|
|
|
|
EV_POP, EV_PEEK, EV_PEEK_LAST
|
|
|
|
} ERR_GET_ACTION;
|
|
|
|
|
|
|
|
static unsigned long get_error_values(ERR_GET_ACTION g,
|
|
|
|
const char **file, int *line,
|
|
|
|
const char **func, const char **data,
|
|
|
|
int *flags);
|
2001-08-26 01:51:59 +08:00
|
|
|
|
2008-05-26 19:24:29 +08:00
|
|
|
static unsigned long err_string_data_hash(const ERR_STRING_DATA *a)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
unsigned long ret, l;
|
|
|
|
|
|
|
|
l = a->error;
|
2019-06-01 01:52:45 +08:00
|
|
|
ret = l ^ ERR_GET_LIB(l);
|
2015-01-22 11:40:55 +08:00
|
|
|
return (ret ^ ret % 19 * 13);
|
|
|
|
}
|
2008-05-26 19:24:29 +08:00
|
|
|
|
|
|
|
static int err_string_data_cmp(const ERR_STRING_DATA *a,
|
2015-01-22 11:40:55 +08:00
|
|
|
const ERR_STRING_DATA *b)
|
|
|
|
{
|
2017-07-09 00:43:55 +08:00
|
|
|
if (a->error == b->error)
|
|
|
|
return 0;
|
|
|
|
return a->error > b->error ? 1 : -1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2001-08-26 01:51:59 +08:00
|
|
|
static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2015-04-28 22:50:54 +08:00
|
|
|
ERR_STRING_DATA *p = NULL;
|
2001-09-06 20:37:36 +08:00
|
|
|
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_read_lock(err_string_lock);
|
2017-06-08 03:12:03 +08:00
|
|
|
p = lh_ERR_STRING_DATA_retrieve(int_error_hash, d);
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
2001-09-06 20:37:36 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
return p;
|
|
|
|
}
|
2001-09-04 19:15:55 +08:00
|
|
|
|
2003-02-18 20:14:57 +08:00
|
|
|
#ifndef OPENSSL_NO_ERR
|
2019-06-04 19:24:59 +08:00
|
|
|
/* 2019-05-21: Russian and Ukrainian locales on Linux require more than 6,5 kB */
|
|
|
|
# define SPACE_SYS_STR_REASONS 8 * 1024
|
2015-01-22 11:40:55 +08:00
|
|
|
# define NUM_SYS_STR_REASONS 127
|
2000-03-04 09:36:53 +08:00
|
|
|
|
|
|
|
static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* SYS_str_reasons is filled with copies of strerror() results at
|
|
|
|
* initialization. 'errno' values up to 127 should cover all usual errors,
|
|
|
|
* others will be displayed numerically by ERR_error_string. It is crucial
|
|
|
|
* that we have something for each reason code that occurs in
|
|
|
|
* ERR_str_reasons, or bogus reason strings will be returned for SYSerr(),
|
|
|
|
* which always gets an errno value and never one of those 'standard' reason
|
|
|
|
* codes.
|
|
|
|
*/
|
2000-03-04 09:36:53 +08:00
|
|
|
|
2005-03-31 17:26:39 +08:00
|
|
|
static void build_SYS_str_reasons(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
/* OPENSSL_malloc cannot be used here, use static storage instead */
|
2018-11-22 01:25:53 +08:00
|
|
|
static char strerror_pool[SPACE_SYS_STR_REASONS];
|
|
|
|
char *cur = strerror_pool;
|
|
|
|
size_t cnt = 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
static int init = 1;
|
2015-04-28 22:50:54 +08:00
|
|
|
int i;
|
2018-11-21 19:44:42 +08:00
|
|
|
int saveerrno = get_last_sys_error();
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_write_lock(err_string_lock);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (!init) {
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
2015-01-22 11:40:55 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 1; i <= NUM_SYS_STR_REASONS; i++) {
|
|
|
|
ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
|
|
|
|
|
2017-06-08 03:12:03 +08:00
|
|
|
str->error = ERR_PACK(ERR_LIB_SYS, 0, i);
|
2019-06-04 19:24:59 +08:00
|
|
|
/*
|
|
|
|
* If we have used up all the space in strerror_pool,
|
|
|
|
* there's no point in calling openssl_strerror_r()
|
|
|
|
*/
|
|
|
|
if (str->string == NULL && cnt < sizeof(strerror_pool)) {
|
2018-11-22 01:25:53 +08:00
|
|
|
if (openssl_strerror_r(i, cur, sizeof(strerror_pool) - cnt)) {
|
2018-11-24 20:08:56 +08:00
|
|
|
size_t l = strlen(cur);
|
2018-11-22 01:25:53 +08:00
|
|
|
|
|
|
|
str->string = cur;
|
|
|
|
cnt += l;
|
|
|
|
cur += l;
|
2018-11-24 20:08:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* VMS has an unusual quirk of adding spaces at the end of
|
2019-06-04 19:24:59 +08:00
|
|
|
* some (most? all?) messages. Lets trim them off.
|
2018-11-24 20:08:56 +08:00
|
|
|
*/
|
2019-06-04 19:24:59 +08:00
|
|
|
while (cur > strerror_pool && ossl_isspace(cur[-1])) {
|
2018-11-24 20:08:56 +08:00
|
|
|
cur--;
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
*cur++ = '\0';
|
|
|
|
cnt++;
|
2018-11-22 01:25:53 +08:00
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
if (str->string == NULL)
|
|
|
|
str->string = "unknown";
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, as
|
|
|
|
* required by ERR_load_strings.
|
|
|
|
*/
|
|
|
|
|
|
|
|
init = 0;
|
|
|
|
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
2018-11-21 19:44:42 +08:00
|
|
|
/* openssl_strerror_r could change errno, but we want to preserve it */
|
|
|
|
set_sys_error(saveerrno);
|
2017-06-08 03:12:03 +08:00
|
|
|
err_load_strings(SYS_str_reasons);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
static void ERR_STATE_free(ERR_STATE *s)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int i;
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2018-03-28 04:25:08 +08:00
|
|
|
if (s == NULL)
|
|
|
|
return;
|
2015-01-22 11:40:55 +08:00
|
|
|
for (i = 0; i < ERR_NUM_ERRORS; i++) {
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear_data(s, i, 1);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
OPENSSL_free(s);
|
|
|
|
}
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
|
2016-03-06 05:31:43 +08:00
|
|
|
{
|
2018-04-20 21:45:06 +08:00
|
|
|
if (!OPENSSL_init_crypto(0, NULL))
|
|
|
|
return 0;
|
Revert the crypto "global lock" implementation
Conceptually, this is a squashed version of:
Revert "Address feedback"
This reverts commit 75551e07bd2339dfea06ef1d31d69929e13a4495.
and
Revert "Add CRYPTO_thread_glock_new"
This reverts commit ed6b2c7938ec6f07b15745d4183afc276e74c6dd.
But there were some intervening commits that made neither revert apply
cleanly, so instead do it all as one shot.
The crypto global locks were an attempt to cope with the awkward
POSIX semantics for pthread_atfork(); its documentation (the "RATIONALE"
section) indicates that the expected usage is to have the prefork handler
lock all "global" locks, and the parent and child handlers release those
locks, to ensure that forking happens with a consistent (lock) state.
However, the set of functions available in the child process is limited
to async-signal-safe functions, and pthread_mutex_unlock() is not on
the list of async-signal-safe functions! The only synchronization
primitives that are async-signal-safe are the semaphore primitives,
which are not really appropriate for general-purpose usage.
However, the state consistency problem that the global locks were
attempting to solve is not actually a serious problem, particularly for
OpenSSL. That is, we can consider four cases of forking application
that might use OpenSSL:
(1) Single-threaded, does not call into OpenSSL in the child (e.g.,
the child calls exec() immediately)
For this class of process, no locking is needed at all, since there is
only ever a single thread of execution and the only reentrancy is due to
signal handlers (which are themselves limited to async-signal-safe
operation and should not be doing much work at all).
(2) Single-threaded, calls into OpenSSL after fork()
The application must ensure that it does not fork() with an unexpected
lock held (that is, one that would get unlocked in the parent but
accidentally remain locked in the child and cause deadlock). Since
OpenSSL does not expose any of its internal locks to the application
and the application is single-threaded, the OpenSSL internal locks
will be unlocked for the fork(), and the state will be consistent.
(OpenSSL will need to reseed its PRNG in the child, but that is
an orthogonal issue.) If the application makes use of locks from
libcrypto, proper handling for those locks is the responsibility of
the application, as for any other locking primitive that is available
for application programming.
(3) Multi-threaded, does not call into OpenSSL after fork()
As for (1), the OpenSSL state is only relevant in the parent, so
no particular fork()-related handling is needed. The internal locks
are relevant, but there is no interaction with the child to consider.
(4) Multi-threaded, calls into OpenSSL after fork()
This is the case where the pthread_atfork() hooks to ensure that all
global locks are in a known state across fork() would come into play,
per the above discussion. However, these "calls into OpenSSL after
fork()" are still subject to the restriction to async-signal-safe
functions. Since OpenSSL uses all sorts of locking and libc functions
that are not on the list of safe functions (e.g., malloc()), this
case is not currently usable and is unlikely to ever be usable,
independently of the locking situation. So, there is no need to
go through contortions to attempt to support this case in the one small
area of locking interaction with fork().
In light of the above analysis (thanks @davidben and @achernya), go
back to the simpler implementation that does not need to distinguish
"library-global" locks or to have complicated atfork handling for locks.
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/5089)
2018-01-16 23:49:54 +08:00
|
|
|
err_string_lock = CRYPTO_THREAD_lock_new();
|
2018-04-20 21:45:06 +08:00
|
|
|
if (err_string_lock == NULL)
|
|
|
|
return 0;
|
2017-06-08 03:12:03 +08:00
|
|
|
int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash,
|
|
|
|
err_string_data_cmp);
|
2018-04-20 21:45:06 +08:00
|
|
|
if (int_error_hash == NULL) {
|
|
|
|
CRYPTO_THREAD_lock_free(err_string_lock);
|
|
|
|
err_string_lock = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
2016-03-12 05:53:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void err_cleanup(void)
|
|
|
|
{
|
2017-06-01 00:14:55 +08:00
|
|
|
if (set_err_thread_local != 0)
|
|
|
|
CRYPTO_THREAD_cleanup_local(&err_thread_local);
|
2016-03-12 05:53:18 +08:00
|
|
|
CRYPTO_THREAD_lock_free(err_string_lock);
|
|
|
|
err_string_lock = NULL;
|
2017-06-08 03:12:03 +08:00
|
|
|
lh_ERR_STRING_DATA_free(int_error_hash);
|
|
|
|
int_error_hash = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Legacy; pack in the library.
|
|
|
|
*/
|
|
|
|
static void err_patch(int lib, ERR_STRING_DATA *str)
|
|
|
|
{
|
|
|
|
unsigned long plib = ERR_PACK(lib, 0, 0);
|
|
|
|
|
|
|
|
for (; str->error != 0; str++)
|
|
|
|
str->error |= plib;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Hash in |str| error strings. Assumes the URN_ONCE was done.
|
|
|
|
*/
|
|
|
|
static int err_load_strings(const ERR_STRING_DATA *str)
|
|
|
|
{
|
|
|
|
CRYPTO_THREAD_write_lock(err_string_lock);
|
|
|
|
for (; str->error; str++)
|
|
|
|
(void)lh_ERR_STRING_DATA_insert(int_error_hash,
|
|
|
|
(ERR_STRING_DATA *)str);
|
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
|
|
|
return 1;
|
2016-03-06 05:31:43 +08:00
|
|
|
}
|
|
|
|
|
2016-07-12 21:50:06 +08:00
|
|
|
int ERR_load_ERR_strings(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2001-02-20 00:06:34 +08:00
|
|
|
#ifndef OPENSSL_NO_ERR
|
2016-07-12 21:50:06 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init))
|
|
|
|
return 0;
|
2016-03-06 05:31:43 +08:00
|
|
|
|
2017-06-08 03:12:03 +08:00
|
|
|
err_load_strings(ERR_str_libraries);
|
|
|
|
err_load_strings(ERR_str_reasons);
|
2015-01-22 11:40:55 +08:00
|
|
|
build_SYS_str_reasons();
|
1998-12-21 18:52:47 +08:00
|
|
|
#endif
|
2016-07-12 21:50:06 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2017-06-08 03:12:03 +08:00
|
|
|
int ERR_load_strings(int lib, ERR_STRING_DATA *str)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-06-08 03:12:03 +08:00
|
|
|
if (ERR_load_ERR_strings() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_patch(lib, str);
|
|
|
|
err_load_strings(str);
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2017-06-08 03:12:03 +08:00
|
|
|
int ERR_load_strings_const(const ERR_STRING_DATA *str)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2016-07-12 21:50:06 +08:00
|
|
|
if (ERR_load_ERR_strings() == 0)
|
|
|
|
return 0;
|
2017-06-08 03:12:03 +08:00
|
|
|
err_load_strings(str);
|
2016-07-12 21:50:06 +08:00
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2001-09-04 19:49:14 +08:00
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
int ERR_unload_strings(int lib, ERR_STRING_DATA *str)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2016-07-20 01:42:11 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init))
|
|
|
|
return 0;
|
2016-03-06 05:31:43 +08:00
|
|
|
|
|
|
|
CRYPTO_THREAD_write_lock(err_string_lock);
|
2017-06-08 03:12:03 +08:00
|
|
|
/*
|
|
|
|
* We don't need to ERR_PACK the lib, since that was done (to
|
|
|
|
* the table) when it was loaded.
|
|
|
|
*/
|
|
|
|
for (; str->error; str++)
|
|
|
|
(void)lh_ERR_STRING_DATA_delete(int_error_hash, str);
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
2016-07-20 01:42:11 +08:00
|
|
|
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2001-09-04 02:24:56 +08:00
|
|
|
|
2016-04-12 19:20:16 +08:00
|
|
|
void err_free_strings_int(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2016-07-20 01:42:11 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init))
|
|
|
|
return;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1998-12-21 18:56:39 +08:00
|
|
|
/********************************************************/
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
void ERR_clear_error(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
ERR_STATE *es;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-06-14 01:00:35 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
for (i = 0; i < ERR_NUM_ERRORS; i++) {
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear(es, i, 0);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
es->top = es->bottom = 0;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
unsigned long ERR_get_error(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, NULL, NULL, NULL, NULL, NULL);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
unsigned long ERR_get_error_line(const char **file, int *line)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, file, line, NULL, NULL, NULL);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-09-05 04:04:08 +08:00
|
|
|
unsigned long ERR_get_error_func(const char **func)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, NULL, NULL, func, NULL, NULL);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_get_error_data(const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, NULL, NULL, NULL, data, flags);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_get_error_all(const char **file, int *line,
|
|
|
|
const char **func,
|
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, file, line, func, data, flags);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
2019-11-06 00:28:50 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
1999-04-20 05:31:43 +08:00
|
|
|
unsigned long ERR_get_error_line_data(const char **file, int *line,
|
2015-01-22 11:40:55 +08:00
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_POP, file, line, NULL, data, flags);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-09-05 04:04:08 +08:00
|
|
|
#endif
|
2002-01-25 01:17:33 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
unsigned long ERR_peek_error(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, NULL, NULL, NULL, NULL, NULL);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2002-01-25 00:16:43 +08:00
|
|
|
unsigned long ERR_peek_error_line(const char **file, int *line)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, file, line, NULL, NULL, NULL);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_error_func(const char **func)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, NULL, NULL, func, NULL, NULL);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_error_data(const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, NULL, NULL, NULL, data, flags);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_error_all(const char **file, int *line,
|
|
|
|
const char **func,
|
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, file, line, func, data, flags);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-01-23 06:29:58 +08:00
|
|
|
|
2019-11-06 00:28:50 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
1999-04-20 05:31:43 +08:00
|
|
|
unsigned long ERR_peek_error_line_data(const char **file, int *line,
|
2015-01-22 11:40:55 +08:00
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK, file, line, NULL, data, flags);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-09-05 04:04:08 +08:00
|
|
|
#endif
|
2002-01-25 01:17:33 +08:00
|
|
|
|
|
|
|
unsigned long ERR_peek_last_error(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, NULL, NULL, NULL, NULL, NULL);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-01-25 01:17:33 +08:00
|
|
|
|
|
|
|
unsigned long ERR_peek_last_error_line(const char **file, int *line)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, file, line, NULL, NULL, NULL);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_last_error_func(const char **func)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, NULL, NULL, func, NULL, NULL);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_last_error_data(const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, NULL, NULL, NULL, data, flags);
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long ERR_peek_last_error_all(const char **file, int *line,
|
|
|
|
const char **func,
|
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, file, line, func, data, flags);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2002-01-25 01:17:33 +08:00
|
|
|
|
2019-11-06 00:28:50 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
2002-01-25 00:16:43 +08:00
|
|
|
unsigned long ERR_peek_last_error_line_data(const char **file, int *line,
|
2015-01-22 11:40:55 +08:00
|
|
|
const char **data, int *flags)
|
|
|
|
{
|
2019-09-13 01:06:04 +08:00
|
|
|
return get_error_values(EV_PEEK_LAST, file, line, NULL, data, flags);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-09-05 04:04:08 +08:00
|
|
|
#endif
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2019-09-13 01:06:04 +08:00
|
|
|
static unsigned long get_error_values(ERR_GET_ACTION g,
|
|
|
|
const char **file, int *line,
|
|
|
|
const char **func,
|
2019-09-05 04:04:08 +08:00
|
|
|
const char **data, int *flags)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
ERR_STATE *es;
|
|
|
|
unsigned long ret;
|
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-06-14 01:00:35 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2019-09-13 01:06:04 +08:00
|
|
|
/*
|
|
|
|
* Clear anything that should have been cleared earlier. We do this
|
|
|
|
* here because this doesn't have constant-time issues.
|
|
|
|
*/
|
2019-03-21 03:01:12 +08:00
|
|
|
while (es->bottom != es->top) {
|
|
|
|
if (es->err_flags[es->top] & ERR_FLAG_CLEAR) {
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear(es, es->top, 0);
|
2019-03-21 03:01:12 +08:00
|
|
|
es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
i = (es->bottom + 1) % ERR_NUM_ERRORS;
|
|
|
|
if (es->err_flags[i] & ERR_FLAG_CLEAR) {
|
|
|
|
es->bottom = i;
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear(es, es->bottom, 0);
|
2019-03-21 03:01:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-13 01:06:04 +08:00
|
|
|
/* If everything has been cleared, the stack is empty. */
|
2015-01-22 11:40:55 +08:00
|
|
|
if (es->bottom == es->top)
|
|
|
|
return 0;
|
2019-03-21 03:01:12 +08:00
|
|
|
|
2019-09-13 01:06:04 +08:00
|
|
|
/* Which error, the top of stack (latest one) or the first one? */
|
|
|
|
if (g == EV_PEEK_LAST)
|
|
|
|
i = es->top;
|
2015-01-22 11:40:55 +08:00
|
|
|
else
|
2019-09-13 01:06:04 +08:00
|
|
|
i = (es->bottom + 1) % ERR_NUM_ERRORS;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
|
|
|
ret = es->err_buffer[i];
|
2019-09-13 01:06:04 +08:00
|
|
|
if (g == EV_POP) {
|
2015-01-22 11:40:55 +08:00
|
|
|
es->bottom = i;
|
|
|
|
es->err_buffer[i] = 0;
|
|
|
|
}
|
|
|
|
|
2019-09-19 21:02:50 +08:00
|
|
|
if (file != NULL) {
|
|
|
|
*file = es->err_file[i];
|
|
|
|
if (*file == NULL)
|
|
|
|
*file = "";
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-09-19 21:02:50 +08:00
|
|
|
if (line != NULL)
|
|
|
|
*line = es->err_line[i];
|
2019-09-05 04:04:08 +08:00
|
|
|
if (func != NULL) {
|
|
|
|
*func = es->err_func[i];
|
|
|
|
if (*func == NULL)
|
2019-09-19 21:02:50 +08:00
|
|
|
*func = "";
|
2019-09-05 04:04:08 +08:00
|
|
|
}
|
2019-09-19 21:02:50 +08:00
|
|
|
if (flags != NULL)
|
|
|
|
*flags = es->err_data_flags[i];
|
2015-01-22 11:40:55 +08:00
|
|
|
if (data == NULL) {
|
2019-09-13 01:06:04 +08:00
|
|
|
if (g == EV_POP) {
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear_data(es, i, 0);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-19 21:02:50 +08:00
|
|
|
*data = es->err_data[i];
|
|
|
|
if (*data == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
*data = "";
|
|
|
|
if (flags != NULL)
|
|
|
|
*flags = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2000-04-15 07:36:15 +08:00
|
|
|
void ERR_error_string_n(unsigned long e, char *buf, size_t len)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-06-01 01:52:45 +08:00
|
|
|
char lsbuf[64], rsbuf[64];
|
|
|
|
const char *ls, *rs;
|
|
|
|
unsigned long f = 0, l, r;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2016-10-12 23:43:03 +08:00
|
|
|
if (len == 0)
|
|
|
|
return;
|
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
l = ERR_GET_LIB(e);
|
|
|
|
ls = ERR_lib_error_string(e);
|
2017-10-06 23:06:12 +08:00
|
|
|
if (ls == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
BIO_snprintf(lsbuf, sizeof(lsbuf), "lib(%lu)", l);
|
2017-10-06 23:06:12 +08:00
|
|
|
ls = lsbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
rs = ERR_reason_error_string(e);
|
|
|
|
r = ERR_GET_REASON(e);
|
|
|
|
if (rs == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
BIO_snprintf(rsbuf, sizeof(rsbuf), "reason(%lu)", r);
|
2017-10-06 23:06:12 +08:00
|
|
|
rs = rsbuf;
|
|
|
|
}
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2019-06-01 01:52:45 +08:00
|
|
|
BIO_snprintf(buf, len, "error:%08lX:%s:%s:%s", e, ls, "", rs);
|
2015-01-22 11:40:55 +08:00
|
|
|
if (strlen(buf) == len - 1) {
|
2017-10-06 23:06:12 +08:00
|
|
|
/* Didn't fit; use a minimal format. */
|
|
|
|
BIO_snprintf(buf, len, "err:%lx:%lx:%lx:%lx", e, l, f, r);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
}
|
2000-04-15 07:36:15 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
/*
|
|
|
|
* ERR_error_string_n should be used instead for ret != NULL as
|
|
|
|
* ERR_error_string cannot know how large the buffer is
|
|
|
|
*/
|
2000-04-15 07:36:15 +08:00
|
|
|
char *ERR_error_string(unsigned long e, char *ret)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
static char buf[256];
|
2000-04-15 07:36:15 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (ret == NULL)
|
|
|
|
ret = buf;
|
2017-10-06 23:06:12 +08:00
|
|
|
ERR_error_string_n(e, ret, (int)sizeof(buf));
|
2015-01-22 11:40:55 +08:00
|
|
|
return ret;
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *ERR_lib_error_string(unsigned long e)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ERR_STRING_DATA d, *p;
|
|
|
|
unsigned long l;
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-03-06 05:31:43 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
l = ERR_GET_LIB(e);
|
|
|
|
d.error = ERR_PACK(l, 0, 0);
|
2015-04-28 22:50:54 +08:00
|
|
|
p = int_err_get_item(&d);
|
2015-01-22 11:40:55 +08:00
|
|
|
return ((p == NULL) ? NULL : p->string);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-11-06 00:28:50 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *ERR_func_error_string(unsigned long e)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-09-05 04:04:08 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-09-05 04:04:08 +08:00
|
|
|
#endif
|
1998-12-21 18:52:47 +08:00
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
const char *ERR_reason_error_string(unsigned long e)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ERR_STRING_DATA d, *p = NULL;
|
|
|
|
unsigned long l, r;
|
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-03-06 05:31:43 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
l = ERR_GET_LIB(e);
|
|
|
|
r = ERR_GET_REASON(e);
|
|
|
|
d.error = ERR_PACK(l, 0, r);
|
2015-04-28 22:50:54 +08:00
|
|
|
p = int_err_get_item(&d);
|
2019-09-17 03:28:57 +08:00
|
|
|
if (p == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
d.error = ERR_PACK(0, 0, r);
|
2015-04-28 22:50:54 +08:00
|
|
|
p = int_err_get_item(&d);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
return ((p == NULL) ? NULL : p->string);
|
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-05-27 23:31:27 +08:00
|
|
|
/* TODO(3.0): arg ignored for now */
|
|
|
|
static void err_delete_thread_state(void *arg)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2017-06-19 17:18:44 +08:00
|
|
|
ERR_STATE *state = CRYPTO_THREAD_get_local(&err_thread_local);
|
2016-03-03 01:36:17 +08:00
|
|
|
if (state == NULL)
|
|
|
|
return;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2016-03-03 01:36:17 +08:00
|
|
|
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
|
|
|
|
ERR_STATE_free(state);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-11-06 00:34:09 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_1_1_0
|
2016-05-08 23:01:09 +08:00
|
|
|
void ERR_remove_thread_state(void *dummy)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-11-06 00:34:09 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_1_0_0
|
2008-08-06 23:54:15 +08:00
|
|
|
void ERR_remove_state(unsigned long pid)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
}
|
2008-08-06 23:54:15 +08:00
|
|
|
#endif
|
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
DEFINE_RUN_ONCE_STATIC(err_do_init)
|
2016-03-03 01:36:17 +08:00
|
|
|
{
|
2017-06-01 00:14:55 +08:00
|
|
|
set_err_thread_local = 1;
|
2016-07-20 01:42:11 +08:00
|
|
|
return CRYPTO_THREAD_init_local(&err_thread_local, NULL);
|
2016-03-03 01:36:17 +08:00
|
|
|
}
|
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
ERR_STATE *err_get_state_int(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2018-04-20 21:45:06 +08:00
|
|
|
ERR_STATE *state;
|
2018-12-15 02:33:55 +08:00
|
|
|
int saveerrno = get_last_sys_error();
|
2018-04-20 21:45:06 +08:00
|
|
|
|
|
|
|
if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
|
|
|
|
return NULL;
|
2016-03-03 01:36:17 +08:00
|
|
|
|
2016-07-20 01:42:11 +08:00
|
|
|
if (!RUN_ONCE(&err_init, err_do_init))
|
|
|
|
return NULL;
|
2016-03-03 01:36:17 +08:00
|
|
|
|
|
|
|
state = CRYPTO_THREAD_get_local(&err_thread_local);
|
2018-04-04 05:47:10 +08:00
|
|
|
if (state == (ERR_STATE*)-1)
|
|
|
|
return NULL;
|
2016-03-03 01:36:17 +08:00
|
|
|
|
|
|
|
if (state == NULL) {
|
2018-04-04 05:47:10 +08:00
|
|
|
if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
|
|
|
|
return NULL;
|
|
|
|
|
2018-04-03 23:31:16 +08:00
|
|
|
if ((state = OPENSSL_zalloc(sizeof(*state))) == NULL) {
|
2018-04-04 05:47:10 +08:00
|
|
|
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
|
2016-03-03 01:36:17 +08:00
|
|
|
return NULL;
|
2018-04-03 23:31:16 +08:00
|
|
|
}
|
2016-03-03 01:36:17 +08:00
|
|
|
|
2019-06-19 01:37:38 +08:00
|
|
|
if (!ossl_init_thread_start(NULL, NULL, err_delete_thread_state)
|
2018-04-04 05:47:10 +08:00
|
|
|
|| !CRYPTO_THREAD_set_local(&err_thread_local, state)) {
|
2016-03-03 01:36:17 +08:00
|
|
|
ERR_STATE_free(state);
|
2018-04-04 05:47:10 +08:00
|
|
|
CRYPTO_THREAD_set_local(&err_thread_local, NULL);
|
2016-03-03 01:36:17 +08:00
|
|
|
return NULL;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2016-02-10 21:59:15 +08:00
|
|
|
|
|
|
|
/* Ignore failures from these */
|
2016-02-10 00:52:40 +08:00
|
|
|
OPENSSL_init_crypto(OPENSSL_INIT_LOAD_CRYPTO_STRINGS, NULL);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2016-03-03 01:36:17 +08:00
|
|
|
|
2018-12-15 02:33:55 +08:00
|
|
|
set_sys_error(saveerrno);
|
2016-03-03 01:36:17 +08:00
|
|
|
return state;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:52:47 +08:00
|
|
|
|
2019-11-06 00:28:50 +08:00
|
|
|
#ifndef OPENSSL_NO_DEPRECATED_3_0
|
2019-07-27 00:11:55 +08:00
|
|
|
ERR_STATE *ERR_get_state(void)
|
|
|
|
{
|
|
|
|
return err_get_state_int();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-04-20 21:45:06 +08:00
|
|
|
/*
|
|
|
|
* err_shelve_state returns the current thread local error state
|
|
|
|
* and freezes the error module until err_unshelve_state is called.
|
|
|
|
*/
|
|
|
|
int err_shelve_state(void **state)
|
|
|
|
{
|
2018-12-15 02:33:55 +08:00
|
|
|
int saveerrno = get_last_sys_error();
|
|
|
|
|
2019-01-01 15:53:24 +08:00
|
|
|
/*
|
|
|
|
* Note, at present our only caller is OPENSSL_init_crypto(), indirectly
|
|
|
|
* via ossl_init_load_crypto_nodelete(), by which point the requested
|
|
|
|
* "base" initialization has already been performed, so the below call is a
|
|
|
|
* NOOP, that re-enters OPENSSL_init_crypto() only to quickly return.
|
|
|
|
*
|
|
|
|
* If are no other valid callers of this function, the call below can be
|
|
|
|
* removed, avoiding the re-entry into OPENSSL_init_crypto(). If there are
|
|
|
|
* potential uses that are not from inside OPENSSL_init_crypto(), then this
|
|
|
|
* call is needed, but some care is required to make sure that the re-entry
|
|
|
|
* remains a NOOP.
|
|
|
|
*/
|
2018-04-20 21:45:06 +08:00
|
|
|
if (!OPENSSL_init_crypto(OPENSSL_INIT_BASE_ONLY, NULL))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!RUN_ONCE(&err_init, err_do_init))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*state = CRYPTO_THREAD_get_local(&err_thread_local);
|
|
|
|
if (!CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)-1))
|
|
|
|
return 0;
|
|
|
|
|
2018-12-15 02:33:55 +08:00
|
|
|
set_sys_error(saveerrno);
|
2018-04-20 21:45:06 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* err_unshelve_state restores the error state that was returned
|
|
|
|
* by err_shelve_state previously.
|
|
|
|
*/
|
|
|
|
void err_unshelve_state(void* state)
|
|
|
|
{
|
|
|
|
if (state != (void*)-1)
|
|
|
|
CRYPTO_THREAD_set_local(&err_thread_local, (ERR_STATE*)state);
|
|
|
|
}
|
|
|
|
|
1999-04-20 05:31:43 +08:00
|
|
|
int ERR_get_next_error_library(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2015-04-28 22:50:54 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-04-20 21:45:06 +08:00
|
|
|
if (!RUN_ONCE(&err_string_init, do_err_strings_init))
|
2016-07-20 01:42:11 +08:00
|
|
|
return 0;
|
2016-03-06 05:31:43 +08:00
|
|
|
|
|
|
|
CRYPTO_THREAD_write_lock(err_string_lock);
|
2015-04-28 22:50:54 +08:00
|
|
|
ret = int_err_library_number++;
|
2016-03-06 05:31:43 +08:00
|
|
|
CRYPTO_THREAD_unlock(err_string_lock);
|
2015-04-28 22:50:54 +08:00
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2019-07-25 23:51:30 +08:00
|
|
|
static int err_set_error_data_int(char *data, size_t size, int flags,
|
|
|
|
int deallocate)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ERR_STATE *es;
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-06-14 01:00:35 +08:00
|
|
|
if (es == NULL)
|
2019-01-29 01:17:59 +08:00
|
|
|
return 0;
|
1998-12-21 18:56:39 +08:00
|
|
|
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear_data(es, es->top, deallocate);
|
2019-07-24 18:56:58 +08:00
|
|
|
err_set_data(es, es->top, data, size, flags);
|
2019-01-29 01:17:59 +08:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ERR_set_error_data(char *data, int flags)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This function is void so we cannot propagate the error return. Since it
|
|
|
|
* is also in the public API we can't change the return type.
|
2019-07-25 23:51:30 +08:00
|
|
|
*
|
|
|
|
* We estimate the size of the data. If it's not flagged as allocated,
|
|
|
|
* then this is safe, and if it is flagged as allocated, then our size
|
|
|
|
* may be smaller than the actual allocation, but that doesn't matter
|
|
|
|
* too much, the buffer will remain untouched or will eventually be
|
|
|
|
* reallocated to a new size.
|
|
|
|
*
|
|
|
|
* callers should be advised that this function takes over ownership of
|
|
|
|
* the allocated memory, i.e. they can't count on the pointer to remain
|
|
|
|
* valid.
|
2019-01-29 01:17:59 +08:00
|
|
|
*/
|
2019-07-25 23:51:30 +08:00
|
|
|
err_set_error_data_int(data, strlen(data) + 1, flags, 1);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
1998-12-21 18:56:39 +08:00
|
|
|
|
1999-05-05 20:35:27 +08:00
|
|
|
void ERR_add_error_data(int num, ...)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, num);
|
|
|
|
ERR_add_error_vdata(num, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
2011-01-14 23:13:37 +08:00
|
|
|
|
|
|
|
void ERR_add_error_vdata(int num, va_list args)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2019-06-19 00:06:17 +08:00
|
|
|
int i, len, size;
|
2019-07-25 23:51:30 +08:00
|
|
|
int flags = ERR_TXT_MALLOCED | ERR_TXT_STRING;
|
|
|
|
char *str, *arg;
|
2019-06-19 00:06:17 +08:00
|
|
|
ERR_STATE *es;
|
|
|
|
|
|
|
|
/* Get the current error data; if an allocated string get it. */
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2019-06-19 00:06:17 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return;
|
|
|
|
i = es->top;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2019-07-25 23:51:30 +08:00
|
|
|
/*
|
|
|
|
* If err_data is allocated already, re-use the space.
|
|
|
|
* Otherwise, allocate a small new buffer.
|
|
|
|
*/
|
|
|
|
if ((es->err_data_flags[i] & flags) == flags) {
|
|
|
|
str = es->err_data[i];
|
|
|
|
size = es->err_data_size[i];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* To protect the string we just grabbed from tampering by other
|
|
|
|
* functions we may call, or to protect them from freeing a pointer
|
|
|
|
* that may no longer be valid at that point, we clear away the
|
|
|
|
* data pointer and the flags. We will set them again at the end
|
|
|
|
* of this function.
|
|
|
|
*/
|
|
|
|
es->err_data[i] = NULL;
|
|
|
|
es->err_data_flags[i] = 0;
|
|
|
|
} else if ((str = OPENSSL_malloc(size = 81)) == NULL) {
|
2015-01-22 11:40:55 +08:00
|
|
|
return;
|
2019-07-25 23:51:30 +08:00
|
|
|
} else {
|
|
|
|
str[0] = '\0';
|
2018-04-03 23:31:16 +08:00
|
|
|
}
|
2019-07-25 23:51:30 +08:00
|
|
|
len = strlen(str);
|
2019-06-19 00:06:17 +08:00
|
|
|
|
2019-08-09 04:30:38 +08:00
|
|
|
while (--num >= 0) {
|
2019-06-19 00:06:17 +08:00
|
|
|
arg = va_arg(args, char *);
|
|
|
|
if (arg == NULL)
|
|
|
|
arg = "<NULL>";
|
|
|
|
len += strlen(arg);
|
2019-07-31 15:27:05 +08:00
|
|
|
if (len >= size) {
|
2019-07-25 23:51:30 +08:00
|
|
|
char *p;
|
|
|
|
|
2019-06-19 00:06:17 +08:00
|
|
|
size = len + 20;
|
2019-07-31 15:27:05 +08:00
|
|
|
p = OPENSSL_realloc(str, size);
|
2017-06-15 01:54:04 +08:00
|
|
|
if (p == NULL) {
|
|
|
|
OPENSSL_free(str);
|
|
|
|
return;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2017-06-15 01:54:04 +08:00
|
|
|
str = p;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-07-31 15:27:05 +08:00
|
|
|
OPENSSL_strlcat(str, arg, (size_t)size);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2019-07-25 23:51:30 +08:00
|
|
|
if (!err_set_error_data_int(str, size, flags, 0))
|
2019-01-29 01:17:59 +08:00
|
|
|
OPENSSL_free(str);
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2003-06-12 04:49:58 +08:00
|
|
|
|
|
|
|
int ERR_set_mark(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ERR_STATE *es;
|
2003-06-12 04:49:58 +08:00
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-06-14 01:00:35 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return 0;
|
2003-06-12 04:49:58 +08:00
|
|
|
|
2015-01-22 11:40:55 +08:00
|
|
|
if (es->bottom == es->top)
|
|
|
|
return 0;
|
|
|
|
es->err_flags[es->top] |= ERR_FLAG_MARK;
|
|
|
|
return 1;
|
|
|
|
}
|
2003-06-12 04:49:58 +08:00
|
|
|
|
|
|
|
int ERR_pop_to_mark(void)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
|
|
|
ERR_STATE *es;
|
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-06-14 01:00:35 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
|
|
|
while (es->bottom != es->top
|
|
|
|
&& (es->err_flags[es->top] & ERR_FLAG_MARK) == 0) {
|
2019-07-25 23:51:30 +08:00
|
|
|
err_clear(es, es->top, 0);
|
2017-08-17 05:08:03 +08:00
|
|
|
es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (es->bottom == es->top)
|
|
|
|
return 0;
|
|
|
|
es->err_flags[es->top] &= ~ERR_FLAG_MARK;
|
|
|
|
return 1;
|
|
|
|
}
|
2017-08-06 03:47:00 +08:00
|
|
|
|
|
|
|
int ERR_clear_last_mark(void)
|
|
|
|
{
|
|
|
|
ERR_STATE *es;
|
|
|
|
int top;
|
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2017-08-06 03:47:00 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
top = es->top;
|
|
|
|
while (es->bottom != top
|
|
|
|
&& (es->err_flags[top] & ERR_FLAG_MARK) == 0) {
|
2017-08-17 05:08:03 +08:00
|
|
|
top = top > 0 ? top - 1 : ERR_NUM_ERRORS - 1;
|
2017-08-06 03:47:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (es->bottom == top)
|
|
|
|
return 0;
|
|
|
|
es->err_flags[top] &= ~ERR_FLAG_MARK;
|
|
|
|
return 1;
|
|
|
|
}
|
2018-09-01 18:19:30 +08:00
|
|
|
|
|
|
|
void err_clear_last_constant_time(int clear)
|
|
|
|
{
|
|
|
|
ERR_STATE *es;
|
|
|
|
int top;
|
|
|
|
|
2019-07-27 00:11:55 +08:00
|
|
|
es = err_get_state_int();
|
2018-09-01 18:19:30 +08:00
|
|
|
if (es == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
top = es->top;
|
|
|
|
|
2019-03-21 03:01:12 +08:00
|
|
|
/*
|
|
|
|
* Flag error as cleared but remove it elsewhere to avoid two errors
|
|
|
|
* accessing the same error stack location, revealing timing information.
|
|
|
|
*/
|
|
|
|
clear = constant_time_select_int(constant_time_eq_int(clear, 0),
|
|
|
|
0, ERR_FLAG_CLEAR);
|
|
|
|
es->err_flags[top] |= clear;
|
2018-09-01 18:19:30 +08:00
|
|
|
}
|