Now that we have ERR_unload_strings(), ERR_load_ERR_strings() must
authorBodo Möller <bodo@openssl.org>
Tue, 4 Sep 2001 11:49:14 +0000 (11:49 +0000)
committerBodo Möller <bodo@openssl.org>
Tue, 4 Sep 2001 11:49:14 +0000 (11:49 +0000)
always load its strings because they might have been unloaded
since the 'init' flag was deleted.

But build_SYS_str_reasons() can use an 'init' flag.

crypto/err/err.c

index 989d4858126085af7b16bb175d49e797fde8c97f..f56576d962d3755ab73a76d63f8a5b84fe299d5b 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
  * [including the GNU Public Licence.]
  */
 /* ====================================================================
- * Copyright (c) 1998-2000 The OpenSSL Project.  All rights reserved.
+ * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
 #include <openssl/bio.h>
 #include <openssl/err.h>
 
 #include <openssl/bio.h>
 #include <openssl/err.h>
 
+static void err_load_strings(int lib, ERR_STRING_DATA *str);
+
 static void ERR_STATE_free(ERR_STATE *s);
 #ifndef OPENSSL_NO_ERR
 static ERR_STRING_DATA ERR_str_libraries[]=
 static void ERR_STATE_free(ERR_STATE *s);
 #ifndef OPENSSL_NO_ERR
 static ERR_STRING_DATA ERR_str_libraries[]=
@@ -275,8 +277,10 @@ static int int_err_library_number=ERR_LIB_USER;
  * the defaults. */
 static void err_fns_check(void)
        {
  * the defaults. */
 static void err_fns_check(void)
        {
+       if (err_fns) return;
+       
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
        CRYPTO_w_lock(CRYPTO_LOCK_ERR);
-       if(!err_fns)
+       if (!err_fns)
                err_fns = &err_defaults;
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        }
                err_fns = &err_defaults;
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
        }
@@ -482,6 +486,9 @@ static void build_SYS_str_reasons()
        /* OPENSSL_malloc cannot be used here, use static storage instead */
        static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
        int i;
        /* OPENSSL_malloc cannot be used here, use static storage instead */
        static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
        int i;
+       static int init = 1;
+
+       if (!init) return;
 
        CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
 
 
        CRYPTO_w_lock(CRYPTO_LOCK_ERR_HASH);
 
@@ -508,6 +515,8 @@ static void build_SYS_str_reasons()
        /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
         * as required by ERR_load_strings. */
 
        /* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
         * as required by ERR_load_strings. */
 
+       init = 0;
+       
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
        }
 #endif
        CRYPTO_w_unlock(CRYPTO_LOCK_ERR_HASH);
        }
 #endif
@@ -537,31 +546,18 @@ static void ERR_STATE_free(ERR_STATE *s)
 
 void ERR_load_ERR_strings(void)
        {
 
 void ERR_load_ERR_strings(void)
        {
-       static int init=1;
-
-       if (init)
-               {
-               init=0;
-               /* We put the first-time check code here to reduce the number of
-                * times it is called (then it doesn't get called from
-                * ERR_load_strings() loads of times). */
-               err_fns_check();
+       err_fns_check();
 #ifndef OPENSSL_NO_ERR
 #ifndef OPENSSL_NO_ERR
-               ERR_load_strings(0,ERR_str_libraries);
-               ERR_load_strings(0,ERR_str_reasons);
-               ERR_load_strings(ERR_LIB_SYS,ERR_str_functs);
-               build_SYS_str_reasons();
-               ERR_load_strings(ERR_LIB_SYS,SYS_str_reasons);
+       err_load_strings(0,ERR_str_libraries);
+       err_load_strings(0,ERR_str_reasons);
+       err_load_strings(ERR_LIB_SYS,ERR_str_functs);
+       build_SYS_str_reasons();
+       err_load_strings(ERR_LIB_SYS,SYS_str_reasons);
 #endif
 #endif
-               }
        }
 
        }
 
-void ERR_load_strings(int lib, ERR_STRING_DATA *str)
+static void err_load_strings(int lib, ERR_STRING_DATA *str)
        {
        {
-       /* Do this if it hasn't been done already (NB: The order of the "init=0"
-        * statement and the recursive calls back to this function prevent a
-        * loop). */
-       ERR_load_ERR_strings();
        while (str->error)
                {
                str->error|=ERR_PACK(lib,0,0);
        while (str->error)
                {
                str->error|=ERR_PACK(lib,0,0);
@@ -570,6 +566,12 @@ void ERR_load_strings(int lib, ERR_STRING_DATA *str)
                }
        }
 
                }
        }
 
+void ERR_load_strings(int lib, ERR_STRING_DATA *str)
+       {
+       err_load_ERR_strings();
+       err_load_strings(lib, str);
+       }
+
 void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
        {
        while(str->error)
 void ERR_unload_strings(int lib, ERR_STRING_DATA *str)
        {
        while(str->error)