Skip to content

Commit 0b18d18

Browse files
committed
Merge branch 'maint-2.1' into maint-2.2
* maint-2.1: .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 41587f6 + fef83a1 commit 0b18d18

File tree

4 files changed

+61
-30
lines changed

4 files changed

+61
-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
@@ -403,7 +403,7 @@ ossl_bn_is_negative(VALUE self)
403403
if (!(result = BN_new())) { \
404404
ossl_raise(eBNError, NULL); \
405405
} \
406-
if (!BN_##func(result, bn, ossl_bn_ctx)) { \
406+
if (BN_##func(result, bn, ossl_bn_ctx) <= 0) { \
407407
BN_free(result); \
408408
ossl_raise(eBNError, NULL); \
409409
} \
@@ -429,7 +429,7 @@ BIGNUM_1c(sqr)
429429
if (!(result = BN_new())) { \
430430
ossl_raise(eBNError, NULL); \
431431
} \
432-
if (!BN_##func(result, bn1, bn2)) { \
432+
if (BN_##func(result, bn1, bn2) <= 0) { \
433433
BN_free(result); \
434434
ossl_raise(eBNError, NULL); \
435435
} \
@@ -462,7 +462,7 @@ BIGNUM_2(sub)
462462
if (!(result = BN_new())) { \
463463
ossl_raise(eBNError, NULL); \
464464
} \
465-
if (!BN_##func(result, bn1, bn2, ossl_bn_ctx)) { \
465+
if (BN_##func(result, bn1, bn2, ossl_bn_ctx) <= 0) { \
466466
BN_free(result); \
467467
ossl_raise(eBNError, NULL); \
468468
} \
@@ -506,11 +506,21 @@ BIGNUM_2c(gcd)
506506
BIGNUM_2c(mod_sqr)
507507

508508
/*
509-
* Document-method: OpenSSL::BN#mod_inverse
510509
* call-seq:
511-
* bn.mod_inverse(bn2) => aBN
510+
* bn.mod_inverse(bn2) => aBN
512511
*/
513-
BIGNUM_2c(mod_inverse)
512+
static VALUE
513+
ossl_bn_mod_inverse(VALUE self, VALUE other)
514+
{
515+
BIGNUM *bn1, *bn2 = GetBNPtr(other), *result;
516+
VALUE obj;
517+
GetBN(self, bn1);
518+
obj = NewBN(rb_obj_class(self));
519+
if (!(result = BN_mod_inverse(NULL, bn1, bn2, ossl_bn_ctx)))
520+
ossl_raise(eBNError, "BN_mod_inverse");
521+
SetBN(obj, result);
522+
return obj;
523+
}
514524

515525
/*
516526
* call-seq:
@@ -559,7 +569,7 @@ ossl_bn_div(VALUE self, VALUE other)
559569
if (!(result = BN_new())) { \
560570
ossl_raise(eBNError, NULL); \
561571
} \
562-
if (!BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx)) { \
572+
if (BN_##func(result, bn1, bn2, bn3, ossl_bn_ctx) <= 0) { \
563573
BN_free(result); \
564574
ossl_raise(eBNError, NULL); \
565575
} \
@@ -601,7 +611,7 @@ BIGNUM_3c(mod_exp)
601611
{ \
602612
BIGNUM *bn; \
603613
GetBN(self, bn); \
604-
if (!BN_##func(bn, NUM2INT(bit))) { \
614+
if (BN_##func(bn, NUM2INT(bit)) <= 0) { \
605615
ossl_raise(eBNError, NULL); \
606616
} \
607617
return self; \
@@ -661,7 +671,7 @@ ossl_bn_is_bit_set(VALUE self, VALUE bit)
661671
if (!(result = BN_new())) { \
662672
ossl_raise(eBNError, NULL); \
663673
} \
664-
if (!BN_##func(result, bn, b)) { \
674+
if (BN_##func(result, bn, b) <= 0) { \
665675
BN_free(result); \
666676
ossl_raise(eBNError, NULL); \
667677
} \
@@ -691,7 +701,7 @@ BIGNUM_SHIFT(rshift)
691701
int b; \
692702
b = NUM2INT(bits); \
693703
GetBN(self, bn); \
694-
if (!BN_##func(bn, bn, b)) \
704+
if (BN_##func(bn, bn, b) <= 0) \
695705
ossl_raise(eBNError, NULL); \
696706
return self; \
697707
}
@@ -730,7 +740,7 @@ BIGNUM_SELF_SHIFT(rshift)
730740
if (!(result = BN_new())) { \
731741
ossl_raise(eBNError, NULL); \
732742
} \
733-
if (!BN_##func(result, b, top, bottom)) { \
743+
if (BN_##func(result, b, top, bottom) <= 0) { \
734744
BN_free(result); \
735745
ossl_raise(eBNError, NULL); \
736746
} \
@@ -759,7 +769,7 @@ BIGNUM_RAND(pseudo_rand)
759769
if (!(result = BN_new())) { \
760770
ossl_raise(eBNError, NULL); \
761771
} \
762-
if (!BN_##func##_range(result, bn)) { \
772+
if (BN_##func##_range(result, bn) <= 0) { \
763773
BN_free(result); \
764774
ossl_raise(eBNError, NULL); \
765775
} \

ext/openssl/ossl_ssl.c

+15
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,11 @@ ossl_start_ssl(VALUE self, int (*func)(), const char *funcname, VALUE opts)
16911691
rb_io_wait_readable(fptr->fd);
16921692
continue;
16931693
case SSL_ERROR_SYSCALL:
1694+
#ifdef __APPLE__
1695+
/* See ossl_ssl_write_internal() */
1696+
if (errno == EPROTOTYPE)
1697+
continue;
1698+
#endif
16941699
if (errno) rb_sys_fail(funcname);
16951700
ossl_raise(eSSLError, "%s SYSCALL returned=%d errno=%d state=%s", funcname, ret2, errno, SSL_state_string_long(ssl));
16961701
#if defined(SSL_R_CERTIFICATE_VERIFY_FAILED)
@@ -1982,6 +1987,16 @@ ossl_ssl_write_internal(VALUE self, VALUE str, VALUE opts)
19821987
rb_io_wait_readable(fptr->fd);
19831988
continue;
19841989
case SSL_ERROR_SYSCALL:
1990+
#ifdef __APPLE__
1991+
/*
1992+
* It appears that send syscall can return EPROTOTYPE if the
1993+
* socket is being torn down. Retry to get a proper errno to
1994+
* make the error handling in line with the socket library.
1995+
* [Bug #14713] https://bugs.ruby-lang.org/issues/14713
1996+
*/
1997+
if (errno == EPROTOTYPE)
1998+
continue;
1999+
#endif
19852000
if (errno) rb_sys_fail(0);
19862001
default:
19872002
ossl_raise(eSSLError, "SSL_write");

ext/openssl/ossl_x509store.c

+16-5
Original file line numberDiff line numberDiff line change
@@ -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
*/
522524
static VALUE
523525
ossl_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

Comments
 (0)