summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorMatt Caswell <matt@openssl.org>2018-11-21 11:44:42 +0000
committerMatt Caswell <matt@openssl.org>2018-12-10 10:22:05 +0000
commit99992ad22019e752c7b103a45f860a48b6bc0972 (patch)
tree27aba4b601955a6516397cc41f033df1b8812677 /crypto
parent4bd0db1feaaf97fbc2bd31f54f1fbdeab80b2b1a (diff)
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: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7680) (cherry picked from commit 71b1ceffc4c795f5db21861dd1016fbe23a53a53)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/err/err.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 1ad18b1924..5cfb02d821 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -21,6 +21,7 @@
#include "internal/thread_once.h"
#include "internal/ctype.h"
#include "internal/constant_time_locl.h"
+#include "e_os.h"
static int err_load_strings(const ERR_STRING_DATA *str);
@@ -206,6 +207,7 @@ static void build_SYS_str_reasons(void)
size_t cnt = 0;
static int init = 1;
int i;
+ int saveerrno = get_last_sys_error();
CRYPTO_THREAD_write_lock(err_string_lock);
if (!init) {
@@ -251,6 +253,8 @@ static void build_SYS_str_reasons(void)
init = 0;
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);
}
#endif