[openssl] master update

Richard Levitte levitte at openssl.org
Tue Jun 18 21:22:23 UTC 2019


The branch master has been updated
       via  8908d18cb1020f225170dd9090206842dbb6bbe6 (commit)
      from  7f02a0932c8c182bc2f6320748d81e86d650c1a6 (commit)


- Log -----------------------------------------------------------------
commit 8908d18cb1020f225170dd9090206842dbb6bbe6
Author: Rich Salz <rsalz at akamai.com>
Date:   Tue Jun 18 12:06:17 2019 -0400

    Change ERR_add_error_[v]data to append
    
    The "add error data" functions now append to the current error.
    Add a test for this.
    Cleanup some of the ERR_put functions.
    In the FIPS module, always append "(in the FIPS module)" to any errors.
    
    Reviewed-by: Bernd Edlinger <bernd.edlinger at hotmail.de>
    Reviewed-by: Richard Levitte <levitte at openssl.org>
    (Merged from https://github.com/openssl/openssl/pull/9181)

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

Summary of changes:
 crypto/err/err.c           | 41 +++++++++++++++++++++++++----------------
 doc/man3/ERR_put_error.pod |  1 +
 providers/fips/fipsprov.c  |  2 ++
 test/errtest.c             | 13 +++++++++++++
 4 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/crypto/err/err.c b/crypto/err/err.c
index 196f782..9eb477c 100644
--- a/crypto/err/err.c
+++ b/crypto/err/err.c
@@ -850,32 +850,41 @@ void ERR_add_error_data(int num, ...)
 
 void ERR_add_error_vdata(int num, va_list args)
 {
-    int i, n, s;
-    char *str, *p, *a;
+    int i, len, size;
+    char *str, *p, *arg;
+    ERR_STATE *es;
+
+    /* Get the current error data; if an allocated string get it. */
+    es = ERR_get_state();
+    if (es == NULL)
+        return;
+    i = es->top;
+    p = es->err_data_flags[i] == (ERR_TXT_MALLOCED | ERR_TXT_STRING)
+            ? es->err_data[i] : "";
 
-    s = 80;
-    if ((str = OPENSSL_malloc(s + 1)) == NULL) {
+    /* Start with initial (or empty) string and allocate a new buffer */
+    size = 80 + strlen(p);
+    if ((str = OPENSSL_malloc(size + 1)) == NULL) {
         /* ERRerr(ERR_F_ERR_ADD_ERROR_VDATA, ERR_R_MALLOC_FAILURE); */
         return;
     }
-    str[0] = '\0';
-
-    n = 0;
-    for (i = 0; i < num; i++) {
-        a = va_arg(args, char *);
-        if (a == NULL)
-            a = "<NULL>";
-        n += strlen(a);
-        if (n > s) {
-            s = n + 20;
-            p = OPENSSL_realloc(str, s + 1);
+    strcpy(str, p);
+
+    for (len = 0; --num >= 0; ) {
+        arg = va_arg(args, char *);
+        if (arg == NULL)
+            arg = "<NULL>";
+        len += strlen(arg);
+        if (len > size) {
+            size = len + 20;
+            p = OPENSSL_realloc(str, size + 1);
             if (p == NULL) {
                 OPENSSL_free(str);
                 return;
             }
             str = p;
         }
-        OPENSSL_strlcat(str, a, (size_t)s + 1);
+        OPENSSL_strlcat(str, arg, (size_t)size + 1);
     }
     if (!err_set_error_data_int(str, ERR_TXT_MALLOCED | ERR_TXT_STRING))
         OPENSSL_free(str);
diff --git a/doc/man3/ERR_put_error.pod b/doc/man3/ERR_put_error.pod
index abc9805..31a0e76 100644
--- a/doc/man3/ERR_put_error.pod
+++ b/doc/man3/ERR_put_error.pod
@@ -23,6 +23,7 @@ This function is usually called by a macro.
 ERR_add_error_data() associates the concatenation of its B<num> string
 arguments with the error code added last.
 ERR_add_error_vdata() is similar except the argument is a B<va_list>.
+Multiple calls to these functions append to the current top of the error queue.
 
 L<ERR_load_strings(3)> can be used to register
 error strings so that the application can a generate human-readable
diff --git a/providers/fips/fipsprov.c b/providers/fips/fipsprov.c
index 9f9b428..a30ece8 100644
--- a/providers/fips/fipsprov.c
+++ b/providers/fips/fipsprov.c
@@ -326,11 +326,13 @@ void ERR_put_error(int lib, int func, int reason, const char *file, int line)
      * so we'll need to come up with something else for them.
      */
     c_put_error(lib, func, reason, file, line);
+    ERR_add_error_data(1, "(in the FIPS module)");
 }
 
 void ERR_add_error_data(int num, ...)
 {
     va_list args;
+
     va_start(args, num);
     ERR_add_error_vdata(num, args);
     va_end(args);
diff --git a/test/errtest.c b/test/errtest.c
index 39017da..df222da 100644
--- a/test/errtest.c
+++ b/test/errtest.c
@@ -32,8 +32,21 @@ static int preserves_system_error(void)
 #endif
 }
 
+/* Test that calls to ERR_add_error_[v]data append */
+static int vdata_appends(void)
+{
+    const char *data;
+
+    CRYPTOerr(0, ERR_R_MALLOC_FAILURE);
+    ERR_add_error_data(1, "hello ");
+    ERR_add_error_data(1, "world");
+    ERR_get_error_line_data(NULL, NULL, &data, NULL);
+    return TEST_str_eq(data, "hello world");
+}
+
 int setup_tests(void)
 {
     ADD_TEST(preserves_system_error);
+    ADD_TEST(vdata_appends);
     return 1;
 }


More information about the openssl-commits mailing list