diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-06-24 06:43:24 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-06-24 06:43:24 +0000 |
commit | bc05b9fc92243f4a9182e52c91cc3a9a010329a5 (patch) | |
tree | 588ad56d3dc84700b721ae3f9ac66307c0d8a310 /lib/libcrypto/ts | |
parent | ddb479c10026e3245afb9e507f6d99771f5fcb67 (diff) |
libcrypto: constify most error string tables
These constitute the bulk of the remaining global mutable state in
libcrypto. This commit moves most of them into data.rel.ro, leaving
out ERR_str_{functs,libraries,reasons} (which require a slightly
different approach) and SYS_str_reasons which is populated on startup.
The main observation is that if ERR_load_strings() is called with a 0 lib
argument, the ERR_STRING_DATA argument is not actually modified. We could
use this fact to cast away const on the caller side and be done with it.
We can make this cleaner by adding a helper ERR_load_const_strings() which
explicitly avoids the assignment to str->error overriding the error code
already set in the table.
In order for this to work, we need to sprinkle some const in err/err.c.
CMS called ERR_load_strings() with non-0 lib argument, but this didn't
actually modify the error data since it ored in the value already stored
in the table.
Annoyingly, we need to cast const away once, namely in the call to
lh_insert() in int_err_set_item(). Fixing this would require changing
the public API and is going to be tricky since it requires that the
LHASH_DOALL_FN_* types adjust.
ok jsing
Diffstat (limited to 'lib/libcrypto/ts')
-rw-r--r-- | lib/libcrypto/ts/ts_err.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libcrypto/ts/ts_err.c b/lib/libcrypto/ts/ts_err.c index bb8209a85c2..c0dcc730990 100644 --- a/lib/libcrypto/ts/ts_err.c +++ b/lib/libcrypto/ts/ts_err.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ts_err.c,v 1.7 2023/07/07 07:25:21 beck Exp $ */ +/* $OpenBSD: ts_err.c,v 1.8 2024/06/24 06:43:22 tb Exp $ */ /* ==================================================================== * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. * @@ -60,17 +60,19 @@ #include <openssl/err.h> #include <openssl/ts.h> +#include "err_local.h" + #ifndef OPENSSL_NO_ERR #define ERR_FUNC(func) ERR_PACK(ERR_LIB_TS,func,0) #define ERR_REASON(reason) ERR_PACK(ERR_LIB_TS,0,reason) -static ERR_STRING_DATA TS_str_functs[] = { +static const ERR_STRING_DATA TS_str_functs[] = { {ERR_FUNC(0xfff), "CRYPTO_internal"}, {0, NULL} }; -static ERR_STRING_DATA TS_str_reasons[]= { +static const ERR_STRING_DATA TS_str_reasons[] = { {ERR_REASON(TS_R_BAD_PKCS7_TYPE) , "bad pkcs7 type"}, {ERR_REASON(TS_R_BAD_TYPE) , "bad type"}, {ERR_REASON(TS_R_CERTIFICATE_VERIFY_ERROR), "certificate verify error"}, @@ -116,8 +118,8 @@ ERR_load_TS_strings(void) { #ifndef OPENSSL_NO_ERR if (ERR_func_error_string(TS_str_functs[0].error) == NULL) { - ERR_load_strings(0, TS_str_functs); - ERR_load_strings(0, TS_str_reasons); + ERR_load_const_strings(TS_str_functs); + ERR_load_const_strings(TS_str_reasons); } #endif } |