diff options
author | tb <> | 2025-05-20 09:25:40 +0000 |
---|---|---|
committer | tb <> | 2025-05-20 09:25:40 +0000 |
commit | c83a8e02e51e7ea9d6fe6162492db7c1dca3725c (patch) | |
tree | 9f1a6fcc3d3e1e72bdabb71164cc66a0463a75b6 /src/lib/libcrypto/err/err.c | |
parent | 4620613ff561cb9d45b87ebb7d5bde20fe93ce45 (diff) | |
download | openbsd-c83a8e02e51e7ea9d6fe6162492db7c1dca3725c.tar.gz openbsd-c83a8e02e51e7ea9d6fe6162492db7c1dca3725c.tar.bz2 openbsd-c83a8e02e51e7ea9d6fe6162492db7c1dca3725c.zip |
Simplify err_build_SYS_str_reasons
This is currently done in a rather silly way. Shift the index by 1
and avoid weird pointer dances. Rather than relying on static
initialization, use code to obviate a comment.
ok beck joshua jsing
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/err/err.c | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 25fbb03875..f03a4431e7 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: err.c,v 1.75 2024/11/02 12:46:36 tb Exp $ */ | 1 | /* $OpenBSD: err.c,v 1.76 2025/05/20 09:25:40 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -484,33 +484,27 @@ err_build_SYS_str_reasons(void) | |||
484 | { | 484 | { |
485 | /* malloc cannot be used here, use static storage instead */ | 485 | /* malloc cannot be used here, use static storage instead */ |
486 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; | 486 | static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; |
487 | const char *errstr; | ||
487 | int save_errno; | 488 | int save_errno; |
488 | int i; | 489 | int i; |
489 | 490 | ||
490 | /* strerror(3) will set errno to EINVAL when i is an unknown errno. */ | 491 | /* strerror(3) will set errno to EINVAL when i is an unknown errno. */ |
491 | save_errno = errno; | 492 | save_errno = errno; |
492 | for (i = 1; i <= NUM_SYS_STR_REASONS; i++) { | 493 | for (i = 0; i < NUM_SYS_STR_REASONS; i++) { |
493 | ERR_STRING_DATA *str = &SYS_str_reasons[i - 1]; | 494 | ERR_STRING_DATA *str = &SYS_str_reasons[i]; |
494 | 495 | ||
495 | str->error = (unsigned long)i; | 496 | str->error = i + 1; |
496 | if (str->string == NULL) { | 497 | str->string = "unknown"; |
497 | char (*dest)[LEN_SYS_STR_REASON] = | 498 | |
498 | &(strerror_tab[i - 1]); | 499 | if ((errstr = strerror((int)str->error)) != NULL) { |
499 | const char *src = strerror(i); | 500 | strlcpy(strerror_tab[i], errstr, sizeof(strerror_tab[i])); |
500 | if (src != NULL) { | 501 | str->string = strerror_tab[i]; |
501 | strlcpy(*dest, src, sizeof *dest); | ||
502 | str->string = *dest; | ||
503 | } | ||
504 | } | 502 | } |
505 | if (str->string == NULL) | ||
506 | str->string = "unknown"; | ||
507 | } | 503 | } |
508 | errno = save_errno; | 504 | errno = save_errno; |
509 | 505 | ||
510 | /* | 506 | SYS_str_reasons[NUM_SYS_STR_REASONS].error = 0; |
511 | * Now we still have SYS_str_reasons[NUM_SYS_STR_REASONS] = {0, NULL}, | 507 | SYS_str_reasons[NUM_SYS_STR_REASONS].string = NULL; |
512 | * as required by ERR_load_strings. | ||
513 | */ | ||
514 | } | 508 | } |
515 | #endif | 509 | #endif |
516 | 510 | ||