Rename some occurrences of 'library_context' and 'lib_ctx' to 'libctx'
[openssl.git] / providers / implementations / storemgmt / file_store_der2obj.c
index c7388a9d14162b2739fb78b5071bbe2892b8a019..8c9168b12584a8eb6aa5691f46738e53cb59c93d 100644 (file)
@@ -27,6 +27,8 @@
 #include <openssl/core_object.h>
 #include <openssl/bio.h>
 #include <openssl/buffer.h>
+#include <openssl/err.h>
+#include <openssl/asn1err.h>
 #include <openssl/params.h>
 #include "internal/asn1.h"
 #include "prov/bio.h"
@@ -85,8 +87,21 @@ static int der2obj_decode(void *provctx, OSSL_CORE_BIO *cin,
      */
     BIO *in = (BIO *)cin;
     BUF_MEM *mem = NULL;
-    int ok = (asn1_d2i_read_bio(in, &mem) >= 0);
+    int err, ok;
 
+    ERR_set_mark();
+    ok = (asn1_d2i_read_bio(in, &mem) >= 0);
+    /*
+     * Prune low-level ASN.1 parse errors from error queue, assuming that
+     * this is called by decoder_process() in a loop trying several formats.
+     */
+    err = ERR_peek_last_error();
+    if (ERR_GET_LIB(err) == ERR_LIB_ASN1
+            && (ERR_GET_REASON(err) == ASN1_R_HEADER_TOO_LONG
+                || ERR_GET_REASON(err) == ERR_R_NESTED_ASN1_ERROR))
+        ERR_pop_to_mark();
+    else
+        ERR_clear_last_mark();
     if (ok) {
         OSSL_PARAM params[3];
         int object_type = OSSL_OBJECT_UNKNOWN;
@@ -115,5 +130,5 @@ static const OSSL_DISPATCH der_to_obj_decoder_functions[] = {
     { 0, NULL }
 };
 
-const OSSL_ALGORITHM der_to_obj_algorithm =
+const OSSL_ALGORITHM ossl_der_to_obj_algorithm =
     { "obj", NULL, der_to_obj_decoder_functions };