From 1e735a3234a159e7d6dbc69d7512969afcdf9702 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 27 Mar 2023 09:15:45 +0000 Subject: [PATCH] Avoid errno is EINVAL after OpenSSL initialization ok tb@ --- lib/libcrypto/err/err.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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. */ -- 2.20.1