提交 99992ad2 编写于 作者: M Matt Caswell

Make sure build_SYS_str_reasons() preserves errno

This function can end up being called during ERR_get_error() if we are
initialising. ERR_get_error() must preserve errno since it gets called via
SSL_get_error(). If that function returns SSL_ERROR_SYSCALL then you are
supposed to inspect errno.
Reviewed-by: NRichard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7680)

(cherry picked from commit 71b1ceffc4c795f5db21861dd1016fbe23a53a53)
上级 4bd0db1f
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "internal/thread_once.h" #include "internal/thread_once.h"
#include "internal/ctype.h" #include "internal/ctype.h"
#include "internal/constant_time_locl.h" #include "internal/constant_time_locl.h"
#include "e_os.h"
static int err_load_strings(const ERR_STRING_DATA *str); static int err_load_strings(const ERR_STRING_DATA *str);
...@@ -206,6 +207,7 @@ static void build_SYS_str_reasons(void) ...@@ -206,6 +207,7 @@ static void build_SYS_str_reasons(void)
size_t cnt = 0; size_t cnt = 0;
static int init = 1; static int init = 1;
int i; int i;
int saveerrno = get_last_sys_error();
CRYPTO_THREAD_write_lock(err_string_lock); CRYPTO_THREAD_write_lock(err_string_lock);
if (!init) { if (!init) {
...@@ -251,6 +253,8 @@ static void build_SYS_str_reasons(void) ...@@ -251,6 +253,8 @@ static void build_SYS_str_reasons(void)
init = 0; init = 0;
CRYPTO_THREAD_unlock(err_string_lock); CRYPTO_THREAD_unlock(err_string_lock);
/* openssl_strerror_r could change errno, but we want to preserve it */
set_sys_error(saveerrno);
err_load_strings(SYS_str_reasons); err_load_strings(SYS_str_reasons);
} }
#endif #endif
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
# define get_last_sys_error() errno # define get_last_sys_error() errno
# define clear_sys_error() errno=0 # define clear_sys_error() errno=0
# define set_sys_error(e) errno=(e)
/******************************************************************** /********************************************************************
The Microsoft section The Microsoft section
...@@ -66,8 +67,10 @@ ...@@ -66,8 +67,10 @@
# ifdef WIN32 # ifdef WIN32
# undef get_last_sys_error # undef get_last_sys_error
# undef clear_sys_error # undef clear_sys_error
# undef set_sys_error
# define get_last_sys_error() GetLastError() # define get_last_sys_error() GetLastError()
# define clear_sys_error() SetLastError(0) # define clear_sys_error() SetLastError(0)
# define set_sys_error(e) SetLastError(e)
# if !defined(WINNT) # if !defined(WINNT)
# define WIN_CONSOLE_BUG # define WIN_CONSOLE_BUG
# endif # endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册