diff options
| author | jsing <> | 2024-10-11 12:40:25 +0000 |
|---|---|---|
| committer | jsing <> | 2024-10-11 12:40:25 +0000 |
| commit | b82588e1fe514eeb47cd772278ef0695046460d0 (patch) | |
| tree | 1665d006560a9457f07c8ba682882817a206adb7 /src | |
| parent | 08a0fc6106e3b865865a17f29840c44004535ce3 (diff) | |
| download | openbsd-b82588e1fe514eeb47cd772278ef0695046460d0.tar.gz openbsd-b82588e1fe514eeb47cd772278ef0695046460d0.tar.bz2 openbsd-b82588e1fe514eeb47cd772278ef0695046460d0.zip | |
Apply some style(9) and tidy some comments.
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libcrypto/err/err.c | 135 |
1 files changed, 73 insertions, 62 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index d7b1728bac..0d0500a004 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: err.c,v 1.71 2024/10/11 12:27:24 jsing Exp $ */ | 1 | /* $OpenBSD: err.c,v 1.72 2024/10/11 12:40:25 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -140,49 +140,49 @@ typedef struct err_state_st { | |||
| 140 | 140 | ||
| 141 | #ifndef OPENSSL_NO_ERR | 141 | #ifndef OPENSSL_NO_ERR |
| 142 | static const ERR_STRING_DATA ERR_str_libraries[] = { | 142 | static const ERR_STRING_DATA ERR_str_libraries[] = { |
| 143 | {ERR_PACK(ERR_LIB_NONE,0,0), "unknown library"}, | 143 | {ERR_PACK(ERR_LIB_NONE, 0, 0), "unknown library"}, |
| 144 | {ERR_PACK(ERR_LIB_SYS,0,0), "system library"}, | 144 | {ERR_PACK(ERR_LIB_SYS, 0, 0), "system library"}, |
| 145 | {ERR_PACK(ERR_LIB_BN,0,0), "bignum routines"}, | 145 | {ERR_PACK(ERR_LIB_BN, 0, 0), "bignum routines"}, |
| 146 | {ERR_PACK(ERR_LIB_RSA,0,0), "rsa routines"}, | 146 | {ERR_PACK(ERR_LIB_RSA, 0, 0), "rsa routines"}, |
| 147 | {ERR_PACK(ERR_LIB_DH,0,0), "Diffie-Hellman routines"}, | 147 | {ERR_PACK(ERR_LIB_DH, 0, 0), "Diffie-Hellman routines"}, |
| 148 | {ERR_PACK(ERR_LIB_EVP,0,0), "digital envelope routines"}, | 148 | {ERR_PACK(ERR_LIB_EVP, 0, 0), "digital envelope routines"}, |
| 149 | {ERR_PACK(ERR_LIB_BUF,0,0), "memory buffer routines"}, | 149 | {ERR_PACK(ERR_LIB_BUF, 0, 0), "memory buffer routines"}, |
| 150 | {ERR_PACK(ERR_LIB_OBJ,0,0), "object identifier routines"}, | 150 | {ERR_PACK(ERR_LIB_OBJ, 0, 0), "object identifier routines"}, |
| 151 | {ERR_PACK(ERR_LIB_PEM,0,0), "PEM routines"}, | 151 | {ERR_PACK(ERR_LIB_PEM, 0, 0), "PEM routines"}, |
| 152 | {ERR_PACK(ERR_LIB_DSA,0,0), "dsa routines"}, | 152 | {ERR_PACK(ERR_LIB_DSA, 0, 0), "dsa routines"}, |
| 153 | {ERR_PACK(ERR_LIB_X509,0,0), "x509 certificate routines"}, | 153 | {ERR_PACK(ERR_LIB_X509, 0, 0), "x509 certificate routines"}, |
| 154 | {ERR_PACK(ERR_LIB_ASN1,0,0), "asn1 encoding routines"}, | 154 | {ERR_PACK(ERR_LIB_ASN1, 0, 0), "asn1 encoding routines"}, |
| 155 | {ERR_PACK(ERR_LIB_CONF,0,0), "configuration file routines"}, | 155 | {ERR_PACK(ERR_LIB_CONF, 0, 0), "configuration file routines"}, |
| 156 | {ERR_PACK(ERR_LIB_CRYPTO,0,0), "common libcrypto routines"}, | 156 | {ERR_PACK(ERR_LIB_CRYPTO, 0, 0), "common libcrypto routines"}, |
| 157 | {ERR_PACK(ERR_LIB_EC,0,0), "elliptic curve routines"}, | 157 | {ERR_PACK(ERR_LIB_EC, 0, 0), "elliptic curve routines"}, |
| 158 | {ERR_PACK(ERR_LIB_SSL,0,0), "SSL routines"}, | 158 | {ERR_PACK(ERR_LIB_SSL, 0, 0), "SSL routines"}, |
| 159 | {ERR_PACK(ERR_LIB_BIO,0,0), "BIO routines"}, | 159 | {ERR_PACK(ERR_LIB_BIO, 0, 0), "BIO routines"}, |
| 160 | {ERR_PACK(ERR_LIB_PKCS7,0,0), "PKCS7 routines"}, | 160 | {ERR_PACK(ERR_LIB_PKCS7, 0, 0), "PKCS7 routines"}, |
| 161 | {ERR_PACK(ERR_LIB_X509V3,0,0), "X509 V3 routines"}, | 161 | {ERR_PACK(ERR_LIB_X509V3, 0, 0), "X509 V3 routines"}, |
| 162 | {ERR_PACK(ERR_LIB_PKCS12,0,0), "PKCS12 routines"}, | 162 | {ERR_PACK(ERR_LIB_PKCS12, 0, 0), "PKCS12 routines"}, |
| 163 | {ERR_PACK(ERR_LIB_RAND,0,0), "random number generator"}, | 163 | {ERR_PACK(ERR_LIB_RAND, 0, 0), "random number generator"}, |
| 164 | {ERR_PACK(ERR_LIB_DSO,0,0), "DSO support routines"}, | 164 | {ERR_PACK(ERR_LIB_DSO, 0, 0), "DSO support routines"}, |
| 165 | {ERR_PACK(ERR_LIB_TS,0,0), "time stamp routines"}, | 165 | {ERR_PACK(ERR_LIB_TS, 0, 0), "time stamp routines"}, |
| 166 | {ERR_PACK(ERR_LIB_ENGINE,0,0), "engine routines"}, | 166 | {ERR_PACK(ERR_LIB_ENGINE, 0, 0), "engine routines"}, |
| 167 | {ERR_PACK(ERR_LIB_OCSP,0,0), "OCSP routines"}, | 167 | {ERR_PACK(ERR_LIB_OCSP, 0, 0), "OCSP routines"}, |
| 168 | {ERR_PACK(ERR_LIB_FIPS,0,0), "FIPS routines"}, | 168 | {ERR_PACK(ERR_LIB_FIPS, 0, 0), "FIPS routines"}, |
| 169 | {ERR_PACK(ERR_LIB_CMS,0,0), "CMS routines"}, | 169 | {ERR_PACK(ERR_LIB_CMS, 0, 0), "CMS routines"}, |
| 170 | {ERR_PACK(ERR_LIB_HMAC,0,0), "HMAC routines"}, | 170 | {ERR_PACK(ERR_LIB_HMAC, 0, 0), "HMAC routines"}, |
| 171 | {ERR_PACK(ERR_LIB_GOST,0,0), "GOST routines"}, | 171 | {ERR_PACK(ERR_LIB_GOST, 0, 0), "GOST routines"}, |
| 172 | {0, NULL}, | 172 | {0, NULL}, |
| 173 | }; | 173 | }; |
| 174 | 174 | ||
| 175 | static const ERR_STRING_DATA ERR_str_functs[] = { | 175 | static const ERR_STRING_DATA ERR_str_functs[] = { |
| 176 | {ERR_PACK(ERR_LIB_SYS,SYS_F_FOPEN, 0), "fopen"}, | 176 | {ERR_PACK(ERR_LIB_SYS, SYS_F_FOPEN, 0), "fopen"}, |
| 177 | {ERR_PACK(ERR_LIB_SYS,SYS_F_CONNECT, 0), "connect"}, | 177 | {ERR_PACK(ERR_LIB_SYS, SYS_F_CONNECT, 0), "connect"}, |
| 178 | {ERR_PACK(ERR_LIB_SYS,SYS_F_GETSERVBYNAME, 0), "getservbyname"}, | 178 | {ERR_PACK(ERR_LIB_SYS, SYS_F_GETSERVBYNAME, 0), "getservbyname"}, |
| 179 | {ERR_PACK(ERR_LIB_SYS,SYS_F_SOCKET, 0), "socket"}, | 179 | {ERR_PACK(ERR_LIB_SYS, SYS_F_SOCKET, 0), "socket"}, |
| 180 | {ERR_PACK(ERR_LIB_SYS,SYS_F_IOCTLSOCKET, 0), "ioctl"}, | 180 | {ERR_PACK(ERR_LIB_SYS, SYS_F_IOCTLSOCKET, 0), "ioctl"}, |
| 181 | {ERR_PACK(ERR_LIB_SYS,SYS_F_BIND, 0), "bind"}, | 181 | {ERR_PACK(ERR_LIB_SYS, SYS_F_BIND, 0), "bind"}, |
| 182 | {ERR_PACK(ERR_LIB_SYS,SYS_F_LISTEN, 0), "listen"}, | 182 | {ERR_PACK(ERR_LIB_SYS, SYS_F_LISTEN, 0), "listen"}, |
| 183 | {ERR_PACK(ERR_LIB_SYS,SYS_F_ACCEPT, 0), "accept"}, | 183 | {ERR_PACK(ERR_LIB_SYS, SYS_F_ACCEPT, 0), "accept"}, |
| 184 | {ERR_PACK(ERR_LIB_SYS,SYS_F_OPENDIR, 0), "opendir"}, | 184 | {ERR_PACK(ERR_LIB_SYS, SYS_F_OPENDIR, 0), "opendir"}, |
| 185 | {ERR_PACK(ERR_LIB_SYS,SYS_F_FREAD, 0), "fread"}, | 185 | {ERR_PACK(ERR_LIB_SYS, SYS_F_FREAD, 0), "fread"}, |
| 186 | {0, NULL}, | 186 | {0, NULL}, |
| 187 | }; | 187 | }; |
| 188 | 188 | ||
| @@ -224,7 +224,7 @@ static const ERR_STRING_DATA ERR_str_reasons[] = { | |||
| 224 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, "called a function you should not call"}, | 224 | {ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED, "called a function you should not call"}, |
| 225 | {ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"}, | 225 | {ERR_R_PASSED_NULL_PARAMETER, "passed a null parameter"}, |
| 226 | {ERR_R_INTERNAL_ERROR, "internal error"}, | 226 | {ERR_R_INTERNAL_ERROR, "internal error"}, |
| 227 | {ERR_R_DISABLED , "called a function that was disabled at compile-time"}, | 227 | {ERR_R_DISABLED, "called a function that was disabled at compile-time"}, |
| 228 | {ERR_R_INIT_FAIL, "initialization failure"}, | 228 | {ERR_R_INIT_FAIL, "initialization failure"}, |
| 229 | 229 | ||
| 230 | {0, NULL}, | 230 | {0, NULL}, |
| @@ -252,8 +252,6 @@ static pthread_t err_init_thread; | |||
| 252 | * internal to the "err_defaults" implementation. | 252 | * internal to the "err_defaults" implementation. |
| 253 | */ | 253 | */ |
| 254 | 254 | ||
| 255 | /* The internal functions used in the "err_defaults" implementation */ | ||
| 256 | |||
| 257 | static unsigned long | 255 | static unsigned long |
| 258 | err_string_data_hash(const ERR_STRING_DATA *a) | 256 | err_string_data_hash(const ERR_STRING_DATA *a) |
| 259 | { | 257 | { |
| @@ -473,14 +471,15 @@ err_get_next_lib(void) | |||
| 473 | #define LEN_SYS_STR_REASON 32 | 471 | #define LEN_SYS_STR_REASON 32 |
| 474 | 472 | ||
| 475 | static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; | 473 | static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1]; |
| 476 | /* SYS_str_reasons is filled with copies of strerror() results at | 474 | |
| 477 | * initialization. | 475 | /* |
| 478 | * 'errno' values up to 127 should cover all usual errors, | 476 | * SYS_str_reasons is filled with copies of strerror() results at |
| 479 | * others will be displayed numerically by ERR_error_string. | 477 | * initialization. 'errno' values up to 127 should cover all usual errors, |
| 480 | * It is crucial that we have something for each reason code | 478 | * others will be displayed numerically by ERR_error_string. It is crucial that |
| 481 | * that occurs in ERR_str_reasons, or bogus reason strings | 479 | * we have something for each reason code that occurs in ERR_str_reasons, or |
| 482 | * will be returned for SYSerror(which always gets an errno | 480 | * bogus reason strings will be returned for SYSerror(), which always gets an |
| 483 | * value and never one of those 'standard' reason codes. */ | 481 | * errno value and never one of those 'standard' reason codes. |
| 482 | */ | ||
| 484 | 483 | ||
| 485 | static void | 484 | static void |
| 486 | err_build_SYS_str_reasons(void) | 485 | err_build_SYS_str_reasons(void) |
| @@ -510,8 +509,10 @@ err_build_SYS_str_reasons(void) | |||
| 510 | } | 509 | } |
| 511 | errno = save_errno; | 510 | errno = save_errno; |
| 512 | 511 | ||
| 513 | /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, | 512 | /* |
| 514 | * as required by ERR_load_strings. */ | 513 | * Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, |
| 514 | * as required by ERR_load_strings. | ||
| 515 | */ | ||
| 515 | } | 516 | } |
| 516 | #endif | 517 | #endif |
| 517 | 518 | ||
| @@ -580,8 +581,10 @@ ERR_get_state(void) | |||
| 580 | ERR_STATE_free(ret); /* could not insert it */ | 581 | ERR_STATE_free(ret); /* could not insert it */ |
| 581 | return (&fallback); | 582 | return (&fallback); |
| 582 | } | 583 | } |
| 583 | /* If a race occurred in this function and we came second, tmpp | 584 | /* |
| 584 | * is the first one that we just replaced. */ | 585 | * If a race occurred in this function and we came second, |
| 586 | * tmpp is the first one that we just replaced. | ||
| 587 | */ | ||
| 585 | if (tmpp) | 588 | if (tmpp) |
| 586 | ERR_STATE_free(tmpp); | 589 | ERR_STATE_free(tmpp); |
| 587 | } | 590 | } |
| @@ -758,8 +761,11 @@ ERR_remove_thread_state(const CRYPTO_THREADID *id) | |||
| 758 | CRYPTO_THREADID_cpy(&tmp.tid, id); | 761 | CRYPTO_THREADID_cpy(&tmp.tid, id); |
| 759 | else | 762 | else |
| 760 | CRYPTO_THREADID_current(&tmp.tid); | 763 | CRYPTO_THREADID_current(&tmp.tid); |
| 761 | /* err_thread_del_item automatically destroys the LHASH if the number of | 764 | |
| 762 | * items reaches zero. */ | 765 | /* |
| 766 | * err_thread_del_item automatically destroys the LHASH if the number of | ||
| 767 | * items reaches zero. | ||
| 768 | */ | ||
| 763 | err_thread_del_item(&tmp); | 769 | err_thread_del_item(&tmp); |
| 764 | } | 770 | } |
| 765 | LCRYPTO_ALIAS(ERR_remove_thread_state); | 771 | LCRYPTO_ALIAS(ERR_remove_thread_state); |
| @@ -1047,8 +1053,10 @@ ERR_error_string_n(unsigned long e, char *buf, size_t len) | |||
| 1047 | if (ret == -1) | 1053 | if (ret == -1) |
| 1048 | return; /* can't happen, and can't do better if it does */ | 1054 | return; /* can't happen, and can't do better if it does */ |
| 1049 | if (ret >= len) { | 1055 | if (ret >= len) { |
| 1050 | /* output may be truncated; make sure we always have 5 | 1056 | /* |
| 1051 | * colon-separated fields, i.e. 4 colons ... */ | 1057 | * output may be truncated; make sure we always have 5 |
| 1058 | * colon-separated fields, i.e. 4 colons ... | ||
| 1059 | */ | ||
| 1052 | #define NUM_COLONS 4 | 1060 | #define NUM_COLONS 4 |
| 1053 | if (len > NUM_COLONS) /* ... if possible */ | 1061 | if (len > NUM_COLONS) /* ... if possible */ |
| 1054 | { | 1062 | { |
| @@ -1071,9 +1079,12 @@ ERR_error_string_n(unsigned long e, char *buf, size_t len) | |||
| 1071 | } | 1079 | } |
| 1072 | LCRYPTO_ALIAS(ERR_error_string_n); | 1080 | LCRYPTO_ALIAS(ERR_error_string_n); |
| 1073 | 1081 | ||
| 1074 | /* BAD for multi-threading: uses a local buffer if ret == NULL */ | 1082 | /* |
| 1075 | /* ERR_error_string_n should be used instead for ret != NULL | 1083 | * ERR_error_string_n should be used instead for ret != NULL |
| 1076 | * as ERR_error_string cannot know how large the buffer is */ | 1084 | * as ERR_error_string cannot know how large the buffer is. |
| 1085 | * | ||
| 1086 | * BAD for multi-threading: uses a local buffer if ret == NULL. | ||
| 1087 | */ | ||
| 1077 | char * | 1088 | char * |
| 1078 | ERR_error_string(unsigned long e, char *ret) | 1089 | ERR_error_string(unsigned long e, char *ret) |
| 1079 | { | 1090 | { |
