[openssl-commits] [openssl] master update

Richard Levitte levitte at openssl.org
Fri Nov 23 11:34:52 UTC 2018


The branch master has been updated
       via  4b801fdcf4c25f44374eb18cb18f36d904975edd (commit)
       via  2c5b6bbb6797242f43b5a986e1c018943e5c1305 (commit)
      from  b92678f4e94eeec468f194333f874906a6fff7f1 (commit)


- Log -----------------------------------------------------------------
commit 4b801fdcf4c25f44374eb18cb18f36d904975edd
Author: Richard Levitte <levitte at openssl.org>
Date:   Thu Nov 22 10:52:51 2018 +0100

    Add an error message test recipes for system error messages
    
    This ensures we collected them properly and and as completely as can
    be tested safely.
    
    Reviewed-by: Matt Caswell <matt at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/7681)

commit 2c5b6bbb6797242f43b5a986e1c018943e5c1305
Author: Richard Levitte <levitte at openssl.org>
Date:   Wed Nov 21 18:25:53 2018 +0100

    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 at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/7681)

-----------------------------------------------------------------------

Summary of changes:
 crypto/err/err.c              | 19 +++++++++----
 test/recipes/02-test_errstr.t | 66 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 80 insertions(+), 5 deletions(-)
 create mode 100644 test/recipes/02-test_errstr.t

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";
diff --git a/test/recipes/02-test_errstr.t b/test/recipes/02-test_errstr.t
new file mode 100644
index 0000000..3d806f0
--- /dev/null
+++ b/test/recipes/02-test_errstr.t
@@ -0,0 +1,66 @@
+#! /usr/bin/env perl
+# Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
+#
+# Licensed under the OpenSSL license (the "License").  You may not use
+# this file except in compliance with the License.  You can obtain a copy
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+use strict;
+no strict 'refs';               # To be able to use strings as function refs
+use OpenSSL::Test;
+use Errno qw(:POSIX);
+use POSIX qw(strerror);
+
+# We actually have space for up to 4095 error messages,
+# numerically speaking...  but we're currently only using
+# numbers 1 through 127.
+# This constant should correspond to the same constant
+# defined in crypto/err/err.c, or at least must not be
+# assigned a greater number.
+use constant NUM_SYS_STR_REASONS => 127;
+
+setup('test_errstr');
+
+# These are POSIX error names, which Errno implements as functions
+# (this is documented)
+my @posix_errors = @{$Errno::EXPORT_TAGS{POSIX}};
+
+plan tests => scalar @posix_errors
+    +1                          # Checking that error 128 gives 'reason(128)'
+    +1                          # Checking that error 0 gives the library name
+    ;
+
+foreach my $errname (@posix_errors) {
+    my $errnum = "Errno::$errname"->();
+
+ SKIP: {
+        skip "Error $errname ($errnum) isn't within our range", 1
+            if $errnum > NUM_SYS_STR_REASONS;
+
+        my $perr = eval {
+            # Set $! to the error number...
+            local $! = $errnum;
+            # ... and $! will give you the error string back
+            $!
+        };
+
+        # We know that the system reasons are in OpenSSL error library 2
+        my @oerr = run(app([ qw(openssl errstr), sprintf("2%06x", $errnum) ]),
+                       capture => 1);
+        $oerr[0] =~ s|\R$||;
+        $oerr[0] =~ s|.*system library:||g; # The actual message is last
+
+        ok($oerr[0] eq $perr, "($errnum) '$oerr[0]' == '$perr'");
+    }
+}
+
+my @after = run(app([ qw(openssl errstr 2000080) ]), capture => 1);
+$after[0] =~ s|\R$||;
+$after[0] =~ s|.*system library:||g;
+ok($after[0] eq "reason(128)", "(128) '$after[0]' == 'reason(128)'");
+
+my @zero = run(app([ qw(openssl errstr 2000000) ]), capture => 1);
+$zero[0] =~ s|\R$||;
+$zero[0] =~ s|.*system library:||g;
+ok($zero[0] eq "system library", "(0) '$zero[0]' == 'system library'");


More information about the openssl-commits mailing list