Skip to content

Commit c11c663

Browse files
committed
pkcs7: only set error_string in the error path
Set the error_string attribute to nil if PKCS7_verify() succeeds, since the error queue should be empty in that case. With AWS-LC, OpenSSL::PKCS#verify currently sets error_string to "invalid library (0)" when the verification succeeds, whereas with OpenSSL and LibreSSL, it becomes nil. ERR_reason_error_string() appears to behave differently when an invalid error code is passed. The branch to raise OpenSSL::PKCS7::PKCS7Error is removed because it does not appear to be reachable.
1 parent 85ce82d commit c11c663

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ext/openssl/ossl_pkcs7.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
770770
BIO *in, *out;
771771
PKCS7 *p7;
772772
VALUE data;
773-
const char *msg;
774773

775774
GetPKCS7(self, p7);
776775
rb_scan_args(argc, argv, "22", &certs, &store, &indata, &flags);
@@ -794,14 +793,16 @@ ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
794793
ok = PKCS7_verify(p7, x509s, x509st, in, out, flg);
795794
BIO_free(in);
796795
sk_X509_pop_free(x509s, X509_free);
797-
if (ok < 0) ossl_raise(ePKCS7Error, "PKCS7_verify");
798-
msg = ERR_reason_error_string(ERR_peek_error());
799-
ossl_pkcs7_set_err_string(self, msg ? rb_str_new2(msg) : Qnil);
800-
ossl_clear_error();
801796
data = ossl_membio2str(out);
802797
ossl_pkcs7_set_data(self, data);
803-
804-
return (ok == 1) ? Qtrue : Qfalse;
798+
if (ok != 1) {
799+
const char *msg = ERR_reason_error_string(ERR_peek_error());
800+
ossl_pkcs7_set_err_string(self, msg ? rb_str_new_cstr(msg) : Qnil);
801+
ossl_clear_error();
802+
return Qfalse;
803+
}
804+
ossl_pkcs7_set_err_string(self, Qnil);
805+
return Qtrue;
805806
}
806807

807808
static VALUE

0 commit comments

Comments
 (0)