Add ERR_clear_last_mark()
authorRichard Levitte <levitte@openssl.org>
Sat, 5 Aug 2017 19:47:00 +0000 (21:47 +0200)
committerRichard Levitte <levitte@openssl.org>
Tue, 15 Aug 2017 12:26:12 +0000 (14:26 +0200)
This allows callers to set a mark, and then clear it without removing
the errors.  Useful in case an error is encountered that should be
returned up the call stack.

Reviewed-by: Andy Polyakov <appro@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/4094)

CHANGES
crypto/err/err.c
include/openssl/err.h
util/libcrypto.num

diff --git a/CHANGES b/CHANGES
index ce2d9c565b61e8304a9795cd165e7b473df172a0..f9b58f9a314c77c56f58b078c2f2acfc28263090 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -9,6 +9,10 @@
 
  Changes between 1.1.0f and 1.1.1 [xx XXX xxxx]
 
+  *) Add ERR_clear_last_mark(), to allow callers to clear the last mark
+     without clearing the errors.
+     [Richard Levitte]
+
   *) Add "atfork" functions.  If building on a system that without
      pthreads, see doc/man3/OPENSSL_fork_prepare.pod for application
      requirements.  The RAND facility now uses/requires this.
index 9db3530330b4f6e82679fa7c72cea3db74cec923..07911e25b22b844fbcbf6342ff692ac39c6b771e 100644 (file)
@@ -812,3 +812,26 @@ int ERR_pop_to_mark(void)
     es->err_flags[es->top] &= ~ERR_FLAG_MARK;
     return 1;
 }
+
+int ERR_clear_last_mark(void)
+{
+    ERR_STATE *es;
+    int top;
+
+    es = ERR_get_state();
+    if (es == NULL)
+        return 0;
+
+    top = es->top;
+    while (es->bottom != top
+           && (es->err_flags[top] & ERR_FLAG_MARK) == 0) {
+        top -= 1;
+        if (top == -1)
+            top = ERR_NUM_ERRORS - 1;
+    }
+
+    if (es->bottom == top)
+        return 0;
+    es->err_flags[top] &= ~ERR_FLAG_MARK;
+    return 1;
+}
index 8b266f9d5c69d4563829c7b41bb19043aad36483..a602660c14523daddd749073189072f2100c3c7b 100644 (file)
@@ -262,6 +262,7 @@ int ERR_get_next_error_library(void);
 
 int ERR_set_mark(void);
 int ERR_pop_to_mark(void);
+int ERR_clear_last_mark(void);
 
 #ifdef  __cplusplus
 }
index 995cbc6672919a1b89462f5d7a7d8338abeac06e..c7f1905d44c4ed37faefd824ae06d2c3d75fff28 100644 (file)
@@ -4381,3 +4381,4 @@ ASN1_TIME_cmp_time_t                    4324      1_1_1   EXIST::FUNCTION:
 ASN1_TIME_compare                       4325   1_1_1   EXIST::FUNCTION:
 EVP_PKEY_CTX_ctrl_uint64                4326   1_1_1   EXIST::FUNCTION:
 EVP_DigestFinalXOF                      4327   1_1_1   EXIST::FUNCTION:
+ERR_clear_last_mark                     4328   1_1_1   EXIST::FUNCTION: