summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/cms/cms_err.c
diff options
context:
space:
mode:
authortb <>2024-06-24 06:43:23 +0000
committertb <>2024-06-24 06:43:23 +0000
commit9bdf4013203aab2bc8161884feb7398faa560fa4 (patch)
tree5e01786fba8689c1ae97aaf149972572fbcd4015 /src/lib/libcrypto/cms/cms_err.c
parent8352adcf928da844a48a04816460acf0524fada9 (diff)
downloadopenbsd-9bdf4013203aab2bc8161884feb7398faa560fa4.tar.gz
openbsd-9bdf4013203aab2bc8161884feb7398faa560fa4.tar.bz2
openbsd-9bdf4013203aab2bc8161884feb7398faa560fa4.zip
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 'src/lib/libcrypto/cms/cms_err.c')
-rw-r--r--src/lib/libcrypto/cms/cms_err.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/lib/libcrypto/cms/cms_err.c b/src/lib/libcrypto/cms/cms_err.c
index 5758a26db5..5431ab4bb8 100644
--- a/src/lib/libcrypto/cms/cms_err.c
+++ b/src/lib/libcrypto/cms/cms_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: cms_err.c,v 1.14 2023/07/08 08:26:26 beck Exp $ */ 1/* $OpenBSD: cms_err.c,v 1.15 2024/06/24 06:43:22 tb Exp $ */
2/* 2/*
3 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. 3 * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
4 * 4 *
@@ -11,17 +11,19 @@
11#include <openssl/cms.h> 11#include <openssl/cms.h>
12#include <openssl/err.h> 12#include <openssl/err.h>
13 13
14#include "err_local.h"
15
14#ifndef OPENSSL_NO_ERR 16#ifndef OPENSSL_NO_ERR
15 17
16#define ERR_FUNC(func) ERR_PACK(ERR_LIB_CMS,func,0) 18#define ERR_FUNC(func) ERR_PACK(ERR_LIB_CMS,func,0)
17#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CMS,0,reason) 19#define ERR_REASON(reason) ERR_PACK(ERR_LIB_CMS,0,reason)
18 20
19static ERR_STRING_DATA CMS_str_functs[] = { 21static const ERR_STRING_DATA CMS_str_functs[] = {
20 {ERR_FUNC(0xfff), "CRYPTO_internal"}, 22 {ERR_FUNC(0xfff), "CRYPTO_internal"},
21 {0, NULL} 23 {0, NULL}
22}; 24};
23 25
24static ERR_STRING_DATA CMS_str_reasons[] = { 26static const ERR_STRING_DATA CMS_str_reasons[] = {
25 {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ADD_SIGNER_ERROR), "add signer error"}, 27 {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_ADD_SIGNER_ERROR), "add signer error"},
26 {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_ALREADY_PRESENT), 28 {ERR_PACK(ERR_LIB_CMS, 0, CMS_R_CERTIFICATE_ALREADY_PRESENT),
27 "certificate already present"}, 29 "certificate already present"},
@@ -155,8 +157,8 @@ ERR_load_CMS_strings(void)
155{ 157{
156#ifndef OPENSSL_NO_ERR 158#ifndef OPENSSL_NO_ERR
157 if (ERR_func_error_string(CMS_str_functs[0].error) == NULL) { 159 if (ERR_func_error_string(CMS_str_functs[0].error) == NULL) {
158 ERR_load_strings(ERR_LIB_CMS, CMS_str_functs); 160 ERR_load_const_strings(CMS_str_functs);
159 ERR_load_strings(ERR_LIB_CMS, CMS_str_reasons); 161 ERR_load_const_strings(CMS_str_reasons);
160 } 162 }
161#endif 163#endif
162 return 1; 164 return 1;