1
1
/*
2
- * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
2
+ * Copyright 1995-2022 The OpenSSL Project Authors. All Rights Reserved.
3
3
*
4
4
* Licensed under the OpenSSL license (the "License"). You may not use
5
5
* this file except in compliance with the License. You can obtain a copy
23
23
#include "internal/constant_time.h"
24
24
#include "e_os.h"
25
25
26
+ #ifndef OPENSSL_NO_ERR
26
27
static int err_load_strings (const ERR_STRING_DATA * str );
28
+ #endif
27
29
28
30
static void ERR_STATE_free (ERR_STATE * s );
29
31
#ifndef OPENSSL_NO_ERR
@@ -76,9 +78,9 @@ static ERR_STRING_DATA ERR_str_functs[] = {
76
78
{ERR_PACK (0 , SYS_F_BIND , 0 ), "bind" },
77
79
{ERR_PACK (0 , SYS_F_LISTEN , 0 ), "listen" },
78
80
{ERR_PACK (0 , SYS_F_ACCEPT , 0 ), "accept" },
79
- # ifdef OPENSSL_SYS_WINDOWS
81
+ #ifdef OPENSSL_SYS_WINDOWS
80
82
{ERR_PACK (0 , SYS_F_WSASTARTUP , 0 ), "WSAstartup" },
81
- # endif
83
+ #endif
82
84
{ERR_PACK (0 , SYS_F_OPENDIR , 0 ), "opendir" },
83
85
{ERR_PACK (0 , SYS_F_FREAD , 0 ), "fread" },
84
86
{ERR_PACK (0 , SYS_F_GETADDRINFO , 0 ), "getaddrinfo" },
@@ -141,21 +143,26 @@ static int set_err_thread_local;
141
143
static CRYPTO_THREAD_LOCAL err_thread_local ;
142
144
143
145
static CRYPTO_ONCE err_string_init = CRYPTO_ONCE_STATIC_INIT ;
144
- static CRYPTO_RWLOCK * err_string_lock ;
146
+ static CRYPTO_RWLOCK * err_string_lock = NULL ;
145
147
148
+ #ifndef OPENSSL_NO_ERR
146
149
static ERR_STRING_DATA * int_err_get_item (const ERR_STRING_DATA * );
150
+ #endif
147
151
148
152
/*
149
153
* The internal state
150
154
*/
151
155
156
+ #ifndef OPENSSL_NO_ERR
152
157
static LHASH_OF (ERR_STRING_DATA ) * int_error_hash = NULL ;
158
+ #endif
153
159
static int int_err_library_number = ERR_LIB_USER ;
154
160
155
161
static unsigned long get_error_values (int inc , int top , const char * * file ,
156
162
int * line , const char * * data ,
157
163
int * flags );
158
164
165
+ #ifndef OPENSSL_NO_ERR
159
166
static unsigned long err_string_data_hash (const ERR_STRING_DATA * a )
160
167
{
161
168
unsigned long ret , l ;
@@ -184,7 +191,6 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
184
191
return p ;
185
192
}
186
193
187
- #ifndef OPENSSL_NO_ERR
188
194
/* 2019-05-21: Russian and Ukrainian locales on Linux require more than 6,5 kB */
189
195
# define SPACE_SYS_STR_REASONS 8 * 1024
190
196
# define NUM_SYS_STR_REASONS 127
@@ -299,13 +305,15 @@ DEFINE_RUN_ONCE_STATIC(do_err_strings_init)
299
305
err_string_lock = CRYPTO_THREAD_lock_new ();
300
306
if (err_string_lock == NULL )
301
307
return 0 ;
308
+ #ifndef OPENSSL_NO_ERR
302
309
int_error_hash = lh_ERR_STRING_DATA_new (err_string_data_hash ,
303
310
err_string_data_cmp );
304
311
if (int_error_hash == NULL ) {
305
312
CRYPTO_THREAD_lock_free (err_string_lock );
306
313
err_string_lock = NULL ;
307
314
return 0 ;
308
315
}
316
+ #endif
309
317
return 1 ;
310
318
}
311
319
@@ -315,10 +323,13 @@ void err_cleanup(void)
315
323
CRYPTO_THREAD_cleanup_local (& err_thread_local );
316
324
CRYPTO_THREAD_lock_free (err_string_lock );
317
325
err_string_lock = NULL ;
326
+ #ifndef OPENSSL_NO_ERR
318
327
lh_ERR_STRING_DATA_free (int_error_hash );
319
328
int_error_hash = NULL ;
329
+ #endif
320
330
}
321
331
332
+ #ifndef OPENSSL_NO_ERR
322
333
/*
323
334
* Legacy; pack in the library.
324
335
*/
@@ -342,6 +353,7 @@ static int err_load_strings(const ERR_STRING_DATA *str)
342
353
CRYPTO_THREAD_unlock (err_string_lock );
343
354
return 1 ;
344
355
}
356
+ #endif
345
357
346
358
int ERR_load_ERR_strings (void )
347
359
{
@@ -360,24 +372,31 @@ int ERR_load_ERR_strings(void)
360
372
361
373
int ERR_load_strings (int lib , ERR_STRING_DATA * str )
362
374
{
375
+ #ifndef OPENSSL_NO_ERR
363
376
if (ERR_load_ERR_strings () == 0 )
364
377
return 0 ;
365
378
366
379
err_patch (lib , str );
367
380
err_load_strings (str );
381
+ #endif
382
+
368
383
return 1 ;
369
384
}
370
385
371
386
int ERR_load_strings_const (const ERR_STRING_DATA * str )
372
387
{
388
+ #ifndef OPENSSL_NO_ERR
373
389
if (ERR_load_ERR_strings () == 0 )
374
390
return 0 ;
375
391
err_load_strings (str );
392
+ #endif
393
+
376
394
return 1 ;
377
395
}
378
396
379
397
int ERR_unload_strings (int lib , ERR_STRING_DATA * str )
380
398
{
399
+ #ifndef OPENSSL_NO_ERR
381
400
if (!RUN_ONCE (& err_string_init , do_err_strings_init ))
382
401
return 0 ;
383
402
@@ -389,14 +408,14 @@ int ERR_unload_strings(int lib, ERR_STRING_DATA *str)
389
408
for (; str -> error ; str ++ )
390
409
(void )lh_ERR_STRING_DATA_delete (int_error_hash , str );
391
410
CRYPTO_THREAD_unlock (err_string_lock );
411
+ #endif
392
412
393
413
return 1 ;
394
414
}
395
415
396
416
void err_free_strings_int (void )
397
417
{
398
- if (!RUN_ONCE (& err_string_init , do_err_strings_init ))
399
- return ;
418
+ /* obsolete */
400
419
}
401
420
402
421
/********************************************************/
@@ -636,6 +655,7 @@ char *ERR_error_string(unsigned long e, char *ret)
636
655
637
656
const char * ERR_lib_error_string (unsigned long e )
638
657
{
658
+ #ifndef OPENSSL_NO_ERR
639
659
ERR_STRING_DATA d , * p ;
640
660
unsigned long l ;
641
661
@@ -647,10 +667,14 @@ const char *ERR_lib_error_string(unsigned long e)
647
667
d .error = ERR_PACK (l , 0 , 0 );
648
668
p = int_err_get_item (& d );
649
669
return ((p == NULL ) ? NULL : p -> string );
670
+ #else
671
+ return NULL ;
672
+ #endif
650
673
}
651
674
652
675
const char * ERR_func_error_string (unsigned long e )
653
676
{
677
+ #ifndef OPENSSL_NO_ERR
654
678
ERR_STRING_DATA d , * p ;
655
679
unsigned long l , f ;
656
680
@@ -663,10 +687,14 @@ const char *ERR_func_error_string(unsigned long e)
663
687
d .error = ERR_PACK (l , f , 0 );
664
688
p = int_err_get_item (& d );
665
689
return ((p == NULL ) ? NULL : p -> string );
690
+ #else
691
+ return NULL ;
692
+ #endif
666
693
}
667
694
668
695
const char * ERR_reason_error_string (unsigned long e )
669
696
{
697
+ #ifndef OPENSSL_NO_ERR
670
698
ERR_STRING_DATA d , * p = NULL ;
671
699
unsigned long l , r ;
672
700
@@ -683,6 +711,9 @@ const char *ERR_reason_error_string(unsigned long e)
683
711
p = int_err_get_item (& d );
684
712
}
685
713
return ((p == NULL ) ? NULL : p -> string );
714
+ #else
715
+ return NULL ;
716
+ #endif
686
717
}
687
718
688
719
void err_delete_thread_state (void )
0 commit comments