summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan Klemkow <jan@cvs.openbsd.org>2023-03-27 09:15:46 +0000
committerJan Klemkow <jan@cvs.openbsd.org>2023-03-27 09:15:46 +0000
commitcad03087710d81ce91d0dd48205787163473ccda (patch)
treefd8847da3ab2ca4c8452fa9307acf1b0038ff244 /lib
parent4af9cbf45c712155eaeb7281cc4f9f8269590eb4 (diff)
Avoid errno is EINVAL after OpenSSL initialization
ok tb@
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/err/err.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/libcrypto/err/err.c b/lib/libcrypto/err/err.c
index 403fcd46077..2eca16d77c6 100644
--- a/lib/libcrypto/err/err.c
+++ b/lib/libcrypto/err/err.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: err.c,v 1.50 2022/12/26 07:18:52 jmc Exp $ */
+/* $OpenBSD: err.c,v 1.51 2023/03/27 09:15:45 jan Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@@ -580,6 +580,7 @@ build_SYS_str_reasons(void)
static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
int i;
static int init = 1;
+ int save_errno;
CRYPTO_r_lock(CRYPTO_LOCK_ERR);
if (!init) {
@@ -594,6 +595,8 @@ build_SYS_str_reasons(void)
return;
}
+ /* strerror(3) will set errno to EINVAL when i is an unknown errno. */
+ save_errno = errno;
for (i = 1; i <= NUM_SYS_STR_REASONS; i++) {
ERR_STRING_DATA *str = &SYS_str_reasons[i - 1];
@@ -610,6 +613,7 @@ build_SYS_str_reasons(void)
if (str->string == NULL)
str->string = "unknown";
}
+ errno = save_errno;
/* Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL},
* as required by ERR_load_strings. */