aboutsummaryrefslogtreecommitdiff
path: root/crypto/err
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2018-11-21 18:25:53 +0100
committerRichard Levitte <levitte@openssl.org>2018-11-23 12:34:45 +0100
commit2c5b6bbb6797242f43b5a986e1c018943e5c1305 (patch)
tree28dd642ffd0ffb837c8c3ee106376397d67f0a28 /crypto/err
parentb92678f4e94eeec468f194333f874906a6fff7f1 (diff)
downloadopenssl-2c5b6bbb6797242f43b5a986e1c018943e5c1305.zip
openssl-2c5b6bbb6797242f43b5a986e1c018943e5c1305.tar.gz
openssl-2c5b6bbb6797242f43b5a986e1c018943e5c1305.tar.bz2
Smarter build of system error text database
We stored copies of the system error texts in a fixed line size array, which is a huge waste. Instead, use a static memory pool and pack all the string in there. The wasted space at the end, if any, gives us some leeway for longer strings than we have measured so far. Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7681)
Diffstat (limited to 'crypto/err')
-rw-r--r--crypto/err/err.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/crypto/err/err.c b/crypto/err/err.c
index 03cbd73..ffdc140 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -181,8 +181,9 @@ static ERR_STRING_DATA *int_err_get_item(const ERR_STRING_DATA *d)
}
#ifndef OPENSSL_NO_ERR
+/* A measurement on Linux 2018-11-21 showed about 3.5kib */
+# define SPACE_SYS_STR_REASONS 4 * 1024
# define NUM_SYS_STR_REASONS 127
-# define LEN_SYS_STR_REASON 32
static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
/*
@@ -198,7 +199,9 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
static void build_SYS_str_reasons(void)
{
/* OPENSSL_malloc cannot be used here, use static storage instead */
- static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
+ static char strerror_pool[SPACE_SYS_STR_REASONS];
+ char *cur = strerror_pool;
+ size_t cnt = 0;
static int init = 1;
int i;
@@ -213,9 +216,15 @@ static void build_SYS_str_reasons(void)
str->error = ERR_PACK(ERR_LIB_SYS, 0, i);
if (str->string == NULL) {
- char (*dest)[LEN_SYS_STR_REASON] = &(strerror_tab[i - 1]);
- if (openssl_strerror_r(i, *dest, sizeof(*dest)))
- str->string = *dest;
+ if (openssl_strerror_r(i, cur, sizeof(strerror_pool) - cnt)) {
+ size_t l = strlen(cur) + 1;
+
+ str->string = cur;
+ cnt += l;
+ if (cnt > sizeof(strerror_pool))
+ cnt = sizeof(strerror_pool);
+ cur += l;
+ }
}
if (str->string == NULL)
str->string = "unknown";