@@ -517,7 +517,9 @@ static VALUE ossl_x509stctx_set_time(VALUE, VALUE);
517517
518518/*
519519 * call-seq:
520- * StoreContext.new(store, cert = nil, chain = nil)
520+ * StoreContext.new(store, cert = nil, untrusted = nil)
521+ *
522+ * Sets up a StoreContext for a verification of the X.509 certificate _cert_.
521523 */
522524static VALUE
523525ossl_x509stctx_initialize (int argc , VALUE * argv , VALUE self )
@@ -527,15 +529,24 @@ ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
527529 X509_STORE * x509st ;
528530 X509 * x509 = NULL ;
529531 STACK_OF (X509 ) * x509s = NULL ;
532+ int state ;
530533
531534 rb_scan_args (argc , argv , "12" , & store , & cert , & chain );
532535 GetX509StCtx (self , ctx );
533536 GetX509Store (store , x509st );
534- if (!NIL_P (cert )) x509 = DupX509CertPtr (cert ); /* NEED TO DUP */
535- if (!NIL_P (chain )) x509s = ossl_x509_ary2sk (chain );
536- if (X509_STORE_CTX_init (ctx , x509st , x509 , x509s ) != 1 ){
537+ if (!NIL_P (cert ))
538+ x509 = DupX509CertPtr (cert ); /* NEED TO DUP */
539+ if (!NIL_P (chain )) {
540+ x509s = ossl_protect_x509_ary2sk (chain , & state );
541+ if (state ) {
542+ X509_free (x509 );
543+ rb_jump_tag (state );
544+ }
545+ }
546+ if (X509_STORE_CTX_init (ctx , x509st , x509 , x509s ) != 1 ){
547+ X509_free (x509 );
537548 sk_X509_pop_free (x509s , X509_free );
538- ossl_raise (eX509StoreError , NULL );
549+ ossl_raise (eX509StoreError , "X509_STORE_CTX_init" );
539550 }
540551 if (!NIL_P (t = rb_iv_get (store , "@time" )))
541552 ossl_x509stctx_set_time (self , t );
0 commit comments