Skip to content

Commit cde6e4a

Browse files
committed
Merge branch 'maint-2.2'
* maint-2.2: .github/workflows: update Ruby and OpenSSL/LibreSSL versions bn: check -1 return from BIGNUM functions .github/workflows: disable pkg-config on Windows tests ssl: retry write on EPROTOTYPE on macOS x509store: fix memory leak in X509::StoreContext.new .github/workflows/test.yml: use GitHub Actions Skip one assertion for OpenSSL::PKey::EC::Point#mul on LibreSSL
2 parents bd9f5c3 + 0b18d18 commit cde6e4a

File tree

4 files changed

+59
-30
lines changed

4 files changed

+59
-30
lines changed

.github/workflows/test.yml

+8-13
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fail-fast: false
1212
matrix:
1313
os: [ ubuntu-latest, macos-latest ]
14-
ruby: [ head, 2.7, 2.6, 2.5, 2.4, 2.3 ]
14+
ruby: [ head, "3.0", "2.7", "2.6", "2.5", "2.4", "2.3" ]
1515
steps:
1616
- name: repo checkout
1717
uses: actions/checkout@v2
@@ -38,7 +38,7 @@ jobs:
3838
fail-fast: false
3939
matrix:
4040
os: [ windows-latest ]
41-
ruby: [ mswin, mingw, 2.7, 2.6, 2.5, 2.4, 2.3 ]
41+
ruby: [ mswin, mingw, "3.0", "2.7", "2.6", "2.5", "2.4", "2.3" ]
4242
steps:
4343
- name: repo checkout
4444
uses: actions/checkout@v2
@@ -52,10 +52,11 @@ jobs:
5252
- name: depends
5353
run: rake install_dependencies
5454

55+
# pkg-config is disabled because it can pick up the different OpenSSL installation
5556
# SSL_DIR is set as needed by MSP-Greg/setup-ruby-pkgs
5657
# only used with mswin
5758
- name: compile
58-
run: rake compile -- --enable-debug $env:SSL_DIR
59+
run: rake compile -- --enable-debug --without-pkg-config $env:SSL_DIR
5960

6061
- name: test
6162
run: rake test TESTOPTS="-v --no-show-detail-immediately" OSSL_MDEBUG=1
@@ -68,21 +69,15 @@ jobs:
6869
fail-fast: false
6970
matrix:
7071
os: [ ubuntu-latest ]
71-
ruby: [ 2.7 ]
72+
ruby: [ "3.0" ]
7273
openssl:
7374
- openssl-1.0.1u # EOL
7475
- openssl-1.0.2u # EOL
7576
- openssl-1.1.0l # EOL
76-
- openssl-1.1.1g
77-
# - libressl-2.3.7 # EOL
78-
# - libressl-2.4.5 # EOL
79-
# - libressl-2.5.5 # EOL
80-
# - libressl-2.6.5 # EOL
81-
# - libressl-2.7.5 # EOL
82-
# - libressl-2.8.3 # EOL
77+
- openssl-1.1.1j
8378
- libressl-2.9.2 # EOL
84-
- libressl-3.0.2
85-
- libressl-3.1.1
79+
- libressl-3.1.5
80+
- libressl-3.2.0
8681
steps:
8782
- name: repo checkout
8883
uses: actions/checkout@v2

ext/openssl/ossl_bn.c

+22-12
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ ossl_bn_is_negative(VALUE self)
453453
if (!(result = BN_new())) { \
454454
ossl_raise(eBNError, NULL); \
455455
} \
456-
if (!BN_##func(result, bn, ossl_bn_ctx)) { \
456+
if (BN_##func(result, bn, ossl_bn_ctx) <= 0) { \
457457
BN_free(result); \
458458
ossl_raise(eBNError, NULL); \
459459
} \
@@ -479,7 +479,7 @@ BIGNUM_1c(sqr)
479479
if (!(result = BN_new())) { \
480480
ossl_raise(eBNError, NULL); \
481481
} \
482-
if (!BN_##func(result, bn1, bn2)) { \
482+
if (BN_##func(result, bn1, bn2) <= 0) { \
483483
BN_free(result); \
484484
ossl_raise(eBNError, NULL); \
485485
} \
@@ -512,7 +512,7 @@ BIGNUM_2(sub)
512512
if (!(result = BN_new())) { \
513513
ossl_raise(eBNError, NULL); \
514514
} \
515-
if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) { \
515+
if (BN_##func(result, bn1, bn2, ossl_bn_ctx) <= 0) { \
516516
BN_free(result); \
517517
ossl_raise(eBNError, NULL); \
518518
} \
@@ -556,11 +556,21 @@ BIGNUM_2c(gcd)
556556
BIGNUM_2c(mod_sqr)
557557

558558
/*
559-
* Document-method: OpenSSL::BN#mod_inverse
560559
* call-seq:
561-
* bn.mod_inverse(bn2) => aBN
560+
* bn.mod_inverse(bn2) => aBN
562561
*/
563-
BIGNUM_2c(mod_inverse)
562+
static VALUE
563+
ossl_bn_mod_inverse(VALUE self, VALUE other)
564+
{
565+
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result;
566+
VALUE obj;
567+
GetBN(self, bn1);
568+
obj = NewBN(rb_obj_class(self));
569+
if (!(result = BN_mod_inverse(NULL, bn1, bn2, ossl_bn_ctx)))
570+
ossl_raise(eBNError, "BN_mod_inverse");
571+
SetBN(obj, result);
572+
return obj;
573+
}
564574

565575
/*
566576
* call-seq:
@@ -609,7 +619,7 @@ ossl_bn_div(VALUE self, VALUE other)
609619
if (!(result = BN_new())) { \
610620
ossl_raise(eBNError, NULL); \
611621
} \
612-
if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) { \
622+
if (BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx) <= 0) { \
613623
BN_free(result); \
614624
ossl_raise(eBNError, NULL); \
615625
} \
@@ -651,7 +661,7 @@ BIGNUM_3c(mod_exp)
651661
{ \
652662
BIGNUM *bn; \
653663
GetBN(self, bn); \
654-
if (!BN_##func(bn, NUM2INT(bit))) { \
664+
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
655665
ossl_raise(eBNError, NULL); \
656666
} \
657667
return self; \
@@ -711,7 +721,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
711721
if (!(result = BN_new())) { \
712722
ossl_raise(eBNError, NULL); \
713723
} \
714-
if (!BN_##func(result, bn, b)) { \
724+
if (BN_##func(result, bn, b) <= 0) { \
715725
BN_free(result); \
716726
ossl_raise(eBNError, NULL); \
717727
} \
@@ -741,7 +751,7 @@ BIGNUM_SHIFT(rshift)
741751
int b; \
742752
b = NUM2INT(bits); \
743753
GetBN(self, bn); \
744-
if (!BN_##func(bn, bn, b)) \
754+
if (BN_##func(bn, bn, b) <= 0) \
745755
ossl_raise(eBNError, NULL); \
746756
return self; \
747757
}
@@ -780,7 +790,7 @@ BIGNUM_SELF_SHIFT(rshift)
780790
if (!(result = BN_new())) { \
781791
ossl_raise(eBNError, NULL); \
782792
} \
783-
if (!BN_##func(result, b, top, bottom)) { \
793+
if (BN_##func(result, b, top, bottom) <= 0) { \
784794
BN_free(result); \
785795
ossl_raise(eBNError, NULL); \
786796
} \
@@ -809,7 +819,7 @@ BIGNUM_RAND(pseudo_rand)
809819
if (!(result = BN_new())) { \
810820
ossl_raise(eBNError, NULL); \
811821
} \
812-
if (!BN_##func##_range(result, bn)) { \
822+
if (BN_##func##_range(result, bn) <= 0) { \
813823
BN_free(result); \
814824
ossl_raise(eBNError, NULL); \
815825
} \

ext/openssl/ossl_ssl.c

+15
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,11 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
16471647
rb_io_wait_readable(fptr->fd);
16481648
continue;
16491649
case SSL_ERROR_SYSCALL:
1650+
#ifdef __APPLE__
1651+
/* See ossl_ssl_write_internal() */
1652+
if (errno == EPROTOTYPE)
1653+
continue;
1654+
#endif
16501655
if (errno) rb_sys_fail(funcname);
16511656
ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
16521657
#if defined(SSL_R_CERTIFICATE_VERIFY_FAILED)
@@ -1938,6 +1943,16 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
19381943
rb_io_wait_readable(fptr->fd);
19391944
continue;
19401945
case SSL_ERROR_SYSCALL:
1946+
#ifdef __APPLE__
1947+
/*
1948+
* It appears that send syscall can return EPROTOTYPE if the
1949+
* socket is being torn down. Retry to get a proper errno to
1950+
* make the error handling in line with the socket library.
1951+
* [Bug #14713] https://bugs.ruby-lang.org/issues/14713
1952+
*/
1953+
if (errno == EPROTOTYPE)
1954+
continue;
1955+
#endif
19411956
if (errno) rb_sys_fail(0);
19421957
default:
19431958
ossl_raise(eSSLError, "SSL_write");

ext/openssl/ossl_x509store.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ static VALUE ossl_x509stctx_set_time(VALUE, VALUE);
546546

547547
/*
548548
* call-seq:
549-
* StoreContext.new(store, cert = nil, chain = nil)
549+
* StoreContext.new(store, cert = nil, untrusted = nil)
550550
*
551551
* Sets up a StoreContext for a verification of the X.509 certificate _cert_.
552552
*/
@@ -558,15 +558,24 @@ ossl_x509stctx_initialize(int argc, VALUE *argv, VALUE self)
558558
X509_STORE *x509st;
559559
X509 *x509 = NULL;
560560
STACK_OF(X509) *x509s = NULL;
561+
int state;
561562

562563
rb_scan_args(argc, argv, "12", &store, &cert, &chain);
563564
GetX509StCtx(self, ctx);
564565
GetX509Store(store, x509st);
565-
if(!NIL_P(cert)) x509 = DupX509CertPtr(cert); /* NEED TO DUP */
566-
if(!NIL_P(chain)) x509s = ossl_x509_ary2sk(chain);
567-
if(X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
566+
if (!NIL_P(cert))
567+
x509 = DupX509CertPtr(cert); /* NEED TO DUP */
568+
if (!NIL_P(chain)) {
569+
x509s = ossl_protect_x509_ary2sk(chain, &state);
570+
if (state) {
571+
X509_free(x509);
572+
rb_jump_tag(state);
573+
}
574+
}
575+
if (X509_STORE_CTX_init(ctx, x509st, x509, x509s) != 1){
576+
X509_free(x509);
568577
sk_X509_pop_free(x509s, X509_free);
569-
ossl_raise(eX509StoreError, NULL);
578+
ossl_raise(eX509StoreError, "X509_STORE_CTX_init");
570579
}
571580
if (!NIL_P(t = rb_iv_get(store, "@time")))
572581
ossl_x509stctx_set_time(self, t);

0 commit comments

Comments
 (0)