summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/x509/x509_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/x509/x509_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/x509/x509_err.c')
-rw-r--r--src/lib/libcrypto/x509/x509_err.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
index 2cbd349350..cff045b105 100644
--- a/src/lib/libcrypto/x509/x509_err.c
+++ b/src/lib/libcrypto/x509/x509_err.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: x509_err.c,v 1.22 2023/05/14 17:20:26 tb Exp $ */ 1/* $OpenBSD: x509_err.c,v 1.23 2024/06/24 06:43:23 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -61,17 +61,19 @@
61#include <openssl/x509.h> 61#include <openssl/x509.h>
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63 63
64#include "err_local.h"
65
64#ifndef OPENSSL_NO_ERR 66#ifndef OPENSSL_NO_ERR
65 67
66#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509,func,0) 68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509,func,0)
67#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason) 69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509,0,reason)
68 70
69static ERR_STRING_DATA X509_str_functs[] = { 71static const ERR_STRING_DATA X509_str_functs[] = {
70 {ERR_FUNC(0xfff), "CRYPTO_internal"}, 72 {ERR_FUNC(0xfff), "CRYPTO_internal"},
71 {0, NULL} 73 {0, NULL}
72}; 74};
73 75
74static ERR_STRING_DATA X509_str_reasons[] = { 76static const ERR_STRING_DATA X509_str_reasons[] = {
75 {ERR_REASON(X509_R_BAD_X509_FILETYPE) , "bad x509 filetype"}, 77 {ERR_REASON(X509_R_BAD_X509_FILETYPE) , "bad x509 filetype"},
76 {ERR_REASON(X509_R_BASE64_DECODE_ERROR) , "base64 decode error"}, 78 {ERR_REASON(X509_R_BASE64_DECODE_ERROR) , "base64 decode error"},
77 {ERR_REASON(X509_R_CANT_CHECK_DH_KEY) , "cant check dh key"}, 79 {ERR_REASON(X509_R_CANT_CHECK_DH_KEY) , "cant check dh key"},
@@ -108,12 +110,12 @@ static ERR_STRING_DATA X509_str_reasons[] = {
108#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509V3,func,0) 110#define ERR_FUNC(func) ERR_PACK(ERR_LIB_X509V3,func,0)
109#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509V3,0,reason) 111#define ERR_REASON(reason) ERR_PACK(ERR_LIB_X509V3,0,reason)
110 112
111static ERR_STRING_DATA X509V3_str_functs[] = { 113static const ERR_STRING_DATA X509V3_str_functs[] = {
112 {ERR_FUNC(0xfff), "CRYPTO_internal"}, 114 {ERR_FUNC(0xfff), "CRYPTO_internal"},
113 {0, NULL} 115 {0, NULL}
114}; 116};
115 117
116static ERR_STRING_DATA X509V3_str_reasons[] = { 118static const ERR_STRING_DATA X509V3_str_reasons[] = {
117 {ERR_REASON(X509V3_R_BAD_IP_ADDRESS) , "bad ip address"}, 119 {ERR_REASON(X509V3_R_BAD_IP_ADDRESS) , "bad ip address"},
118 {ERR_REASON(X509V3_R_BAD_OBJECT) , "bad object"}, 120 {ERR_REASON(X509V3_R_BAD_OBJECT) , "bad object"},
119 {ERR_REASON(X509V3_R_BN_DEC2BN_ERROR) , "bn dec2bn error"}, 121 {ERR_REASON(X509V3_R_BN_DEC2BN_ERROR) , "bn dec2bn error"},
@@ -192,8 +194,8 @@ ERR_load_X509_strings(void)
192{ 194{
193#ifndef OPENSSL_NO_ERR 195#ifndef OPENSSL_NO_ERR
194 if (ERR_func_error_string(X509_str_functs[0].error) == NULL) { 196 if (ERR_func_error_string(X509_str_functs[0].error) == NULL) {
195 ERR_load_strings(0, X509_str_functs); 197 ERR_load_const_strings(X509_str_functs);
196 ERR_load_strings(0, X509_str_reasons); 198 ERR_load_const_strings(X509_str_reasons);
197 } 199 }
198#endif 200#endif
199} 201}
@@ -205,8 +207,8 @@ ERR_load_X509V3_strings(void)
205{ 207{
206#ifndef OPENSSL_NO_ERR 208#ifndef OPENSSL_NO_ERR
207 if (ERR_func_error_string(X509V3_str_functs[0].error) == NULL) { 209 if (ERR_func_error_string(X509V3_str_functs[0].error) == NULL) {
208 ERR_load_strings(0, X509V3_str_functs); 210 ERR_load_const_strings(X509V3_str_functs);
209 ERR_load_strings(0, X509V3_str_reasons); 211 ERR_load_const_strings(X509V3_str_reasons);
210 } 212 }
211#endif 213#endif
212} 214}