ERR: Add ERR_pop()
authorHugo Landau <hlandau@openssl.org>
Thu, 9 Nov 2023 10:27:14 +0000 (10:27 +0000)
committerHugo Landau <hlandau@openssl.org>
Thu, 21 Dec 2023 08:12:06 +0000 (08:12 +0000)
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/22674)

crypto/err/err_mark.c
doc/man3/ERR_set_mark.pod
include/openssl/err.h.in
util/libcrypto.num

index 82dc4764c498b0d403dd35b6bf2e3008dd67a499..cb01a1f4f699a5d18f920caec29552805e9a0cc7 100644 (file)
@@ -26,6 +26,19 @@ int ERR_set_mark(void)
     return 1;
 }
 
+int ERR_pop(void)
+{
+    ERR_STATE *es;
+
+    es = ossl_err_get_state_int();
+    if (es == NULL || es->bottom == es->top)
+        return 0;
+
+    err_clear(es, es->top, 0);
+    es->top = es->top > 0 ? es->top - 1 : ERR_NUM_ERRORS - 1;
+    return 1;
+}
+
 int ERR_pop_to_mark(void)
 {
     ERR_STATE *es;
index b2c0f7de0a18fac6cee19025c88614eea4f58e71..d6d715e2f69657a19c7a7f4723c8981b81ca79b6 100644 (file)
@@ -2,8 +2,8 @@
 
 =head1 NAME
 
-ERR_set_mark, ERR_clear_last_mark, ERR_pop_to_mark, ERR_count_to_mark - set
-mark, clear mark and pop errors until mark
+ERR_set_mark, ERR_clear_last_mark, ERR_pop_to_mark, ERR_count_to_mark, ERR_pop -
+set mark, clear mark and pop errors until mark
 
 =head1 SYNOPSIS
 
@@ -13,6 +13,7 @@ mark, clear mark and pop errors until mark
  int ERR_pop_to_mark(void);
  int ERR_clear_last_mark(void);
  int ERR_count_to_mark(void);
+ int ERR_pop(void);
 
 =head1 DESCRIPTION
 
@@ -28,6 +29,9 @@ ERR_count_to_mark() returns the number of entries on the error stack above the
 most recently marked entry, not including that entry. If there is no mark in the
 error stack, the number of entries in the error stack is returned.
 
+ERR_pop() unconditionally pops a single error entry from the top of the error
+stack (which is the entry obtainable via L<ERR_peek_last_error(3)>).
+
 =head1 RETURN VALUES
 
 ERR_set_mark() returns 0 if the error stack is empty, otherwise 1.
@@ -38,6 +42,12 @@ error stack, which implies that the stack became empty, otherwise 1.
 ERR_count_to_mark() returns the number of error stack entries found above the
 most recent mark, if any, or the total number of error stack entries.
 
+ERR_pop() returns 1 if an error was popped or 0 if the error stack was empty.
+
+=head1 HISTORY
+
+ERR_pop() was added in OpenSSL 3.3.
+
 =head1 COPYRIGHT
 
 Copyright 2003-2023 The OpenSSL Project Authors. All Rights Reserved.
index 1ef09de02e02ecc4738e810cc6d414b557138d9b..9143704c098e2218e69f1e34191da0e39d476736 100644 (file)
@@ -486,6 +486,7 @@ int ERR_set_mark(void);
 int ERR_pop_to_mark(void);
 int ERR_clear_last_mark(void);
 int ERR_count_to_mark(void);
+int ERR_pop(void);
 
 ERR_STATE *OSSL_ERR_STATE_new(void);
 void OSSL_ERR_STATE_save(ERR_STATE *es);
index 60f320c33a711d4586af35df1c5cf1f2067cffed..0b72559f86ae1883b30b031b49d637996b4fb451 100644 (file)
@@ -5541,3 +5541,4 @@ OSSL_CMP_HDR_get0_geninfo_ITAVs         ? 3_3_0   EXIST::FUNCTION:CMP
 OSSL_CMP_ITAV_new0_certProfile          ?      3_3_0   EXIST::FUNCTION:CMP
 OSSL_CMP_ITAV_get0_certProfile          ?      3_3_0   EXIST::FUNCTION:CMP
 EVP_DigestSqueeze                       ?      3_3_0   EXIST::FUNCTION:
+ERR_pop                                 ?      3_3_0   EXIST::FUNCTION: