On Fri, Mar 24, 2023 at 10:02:05PM +0100, Theo Buehler wrote:
> > Thus, I would suggest to set this constant to ELAST. So, we will avoid
> > useless unknown error strings and a non-zero errno after tls_init().
>
> ELAST isn't portable. It's under __BSD_VISIBLE in sys/errno.h.
>
> It would seem better to use the save_errno idiom to store the errno
> at the start of the loop and restore it at the end.
>
> And yes, we should fix this, after unluck.
ok?
Thanks,
Jan
Index: err/err.c
===================================================================
RCS file: /cvs/src/lib/libcrypto/err/err.c,v
retrieving revision 1.50
diff -u -p -r1.50 err.c
--- err/err.c 26 Dec 2022 07:18:52 -0000 1.50
+++ err/err.c 27 Mar 2023 07:58:25 -0000
@@ -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 = 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 error. */
+ 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. */