Skip to content

Commit bdf060f

Browse files
authored
Merge pull request ruby#677 from rhenium/ky/remove-mdebug
Remove OSSL_DEBUG compile-time option
2 parents 3784b27 + 8c7a6a1 commit bdf060f

File tree

7 files changed

+9
-141
lines changed

7 files changed

+9
-141
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ jobs:
5858
if: runner.os == 'Windows' && matrix.ruby == '3.2'
5959

6060
- name: compile
61-
run: rake compile -- --enable-debug
61+
run: rake compile
6262

6363
- name: test
64-
run: rake test TESTOPTS="-v --no-show-detail-immediately" OSSL_MDEBUG=1
64+
run: rake test TESTOPTS="-v --no-show-detail-immediately"
6565
timeout-minutes: 5
6666

6767
test-openssls:
@@ -169,10 +169,10 @@ jobs:
169169
if: ${{ !matrix.skip-warnings }}
170170

171171
- name: compile
172-
run: rake compile -- --enable-debug --with-openssl-dir=$HOME/.openssl/${{ matrix.openssl }}
172+
run: rake compile -- --with-openssl-dir=$HOME/.openssl/${{ matrix.openssl }}
173173

174174
- name: test
175-
run: rake test TESTOPTS="-v --no-show-detail-immediately" OSSL_MDEBUG=1
175+
run: rake test TESTOPTS="-v --no-show-detail-immediately"
176176
timeout-minutes: 5
177177
if: ${{ !matrix.fips-enabled }}
178178

ext/openssl/extconf.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@
4545

4646
Logging::message "=== OpenSSL for Ruby configurator ===\n"
4747

48-
##
49-
# Adds -DOSSL_DEBUG for compilation and some more targets when GCC is used
50-
# To turn it on, use: --with-debug or --enable-debug
51-
#
52-
if with_config("debug") or enable_config("debug")
53-
$defs.push("-DOSSL_DEBUG")
54-
end
5548
$defs.push("-D""OPENSSL_SUPPRESS_DEPRECATED")
5649

5750
have_func("rb_io_descriptor")

ext/openssl/ossl.c

Lines changed: 0 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -463,75 +463,6 @@ ossl_fips_mode_set(VALUE self, VALUE enabled)
463463
#endif
464464
}
465465

466-
#if defined(OSSL_DEBUG)
467-
#if !defined(LIBRESSL_VERSION_NUMBER) && \
468-
(OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \
469-
defined(CRYPTO_malloc_debug_init))
470-
/*
471-
* call-seq:
472-
* OpenSSL.mem_check_start -> nil
473-
*
474-
* Calls CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON). Starts tracking memory
475-
* allocations. See also OpenSSL.print_mem_leaks.
476-
*
477-
* This is available only when built with a capable OpenSSL and --enable-debug
478-
* configure option.
479-
*/
480-
static VALUE
481-
mem_check_start(VALUE self)
482-
{
483-
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
484-
return Qnil;
485-
}
486-
487-
/*
488-
* call-seq:
489-
* OpenSSL.print_mem_leaks -> true | false
490-
*
491-
* For debugging the Ruby/OpenSSL library. Calls CRYPTO_mem_leaks_fp(stderr).
492-
* Prints detected memory leaks to standard error. This cleans the global state
493-
* up thus you cannot use any methods of the library after calling this.
494-
*
495-
* Returns +true+ if leaks detected, +false+ otherwise.
496-
*
497-
* This is available only when built with a capable OpenSSL and --enable-debug
498-
* configure option.
499-
*
500-
* === Example
501-
* OpenSSL.mem_check_start
502-
* NOT_GCED = OpenSSL::PKey::RSA.new(256)
503-
*
504-
* END {
505-
* GC.start
506-
* OpenSSL.print_mem_leaks # will print the leakage
507-
* }
508-
*/
509-
static VALUE
510-
print_mem_leaks(VALUE self)
511-
{
512-
#if OPENSSL_VERSION_NUMBER >= 0x10100000
513-
int ret;
514-
#endif
515-
516-
#ifndef HAVE_RB_EXT_RACTOR_SAFE
517-
// for Ruby 2.x
518-
void ossl_bn_ctx_free(void); // ossl_bn.c
519-
ossl_bn_ctx_free();
520-
#endif
521-
522-
#if OPENSSL_VERSION_NUMBER >= 0x10100000
523-
ret = CRYPTO_mem_leaks_fp(stderr);
524-
if (ret < 0)
525-
ossl_raise(eOSSLError, "CRYPTO_mem_leaks_fp");
526-
return ret ? Qfalse : Qtrue;
527-
#else
528-
CRYPTO_mem_leaks_fp(stderr);
529-
return Qnil;
530-
#endif
531-
}
532-
#endif
533-
#endif
534-
535466
#if !defined(HAVE_OPENSSL_110_THREADING_API)
536467
/**
537468
* Stores locks needed for OpenSSL thread safety
@@ -1239,40 +1170,4 @@ Init_openssl(void)
12391170
Init_ossl_provider();
12401171
Init_ossl_asn1();
12411172
Init_ossl_kdf();
1242-
1243-
#if defined(OSSL_DEBUG)
1244-
/*
1245-
* For debugging Ruby/OpenSSL. Enable only when built with --enable-debug
1246-
*/
1247-
#if !defined(LIBRESSL_VERSION_NUMBER) && \
1248-
(OPENSSL_VERSION_NUMBER >= 0x10100000 && !defined(OPENSSL_NO_CRYPTO_MDEBUG) || \
1249-
defined(CRYPTO_malloc_debug_init))
1250-
rb_define_module_function(mOSSL, "mem_check_start", mem_check_start, 0);
1251-
rb_define_module_function(mOSSL, "print_mem_leaks", print_mem_leaks, 0);
1252-
1253-
#if defined(CRYPTO_malloc_debug_init) /* <= 1.0.2 */
1254-
CRYPTO_malloc_debug_init();
1255-
#endif
1256-
1257-
#if defined(V_CRYPTO_MDEBUG_ALL) /* <= 1.0.2 */
1258-
CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
1259-
#endif
1260-
1261-
#if OPENSSL_VERSION_NUMBER < 0x10100000 /* <= 1.0.2 */
1262-
{
1263-
int i;
1264-
/*
1265-
* See crypto/ex_data.c; call def_get_class() immediately to avoid
1266-
* allocations. 15 is the maximum number that is used as the class index
1267-
* in OpenSSL 1.0.2.
1268-
*/
1269-
for (i = 0; i <= 15; i++) {
1270-
if (CRYPTO_get_ex_new_index(i, 0, (void *)"ossl-mdebug-dummy", 0, 0, 0) < 0)
1271-
rb_raise(rb_eRuntimeError, "CRYPTO_get_ex_new_index for "
1272-
"class index %d failed", i);
1273-
}
1274-
}
1275-
#endif
1276-
#endif
1277-
#endif
12781173
}

test/openssl/test_engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_openssl_engine_cipher_rc4
8282

8383
# this is required because OpenSSL::Engine methods change global state
8484
def with_openssl(code, **opts)
85-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts)
85+
assert_separately(["-ropenssl"], <<~"end;", **opts)
8686
#{code}
8787
end;
8888
end

test/openssl/test_fips.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def test_fips_mode_get_is_true_on_fips_mode_enabled
99
omit "Only for FIPS mode environment"
1010
end
1111

12-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
12+
assert_separately(["-ropenssl"], <<~"end;")
1313
assert OpenSSL.fips_mode == true, ".fips_mode should return true on FIPS mode enabled"
1414
end;
1515
end
@@ -19,7 +19,7 @@ def test_fips_mode_get_is_false_on_fips_mode_disabled
1919
omit "Only for non-FIPS mode environment"
2020
end
2121

22-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
22+
assert_separately(["-ropenssl"], <<~"end;")
2323
message = ".fips_mode should return false on FIPS mode disabled. " \
2424
"If you run the test on FIPS mode, please set " \
2525
"TEST_RUBY_OPENSSL_FIPS_ENABLED=true"
@@ -35,7 +35,7 @@ def test_fips_mode_is_reentrant
3535
def test_fips_mode_get_with_fips_mode_set
3636
omit('OpenSSL is not FIPS-capable') unless OpenSSL::OPENSSL_FIPS
3737

38-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;")
38+
assert_separately(["-ropenssl"], <<~"end;")
3939
begin
4040
OpenSSL.fips_mode = true
4141
assert OpenSSL.fips_mode == true, ".fips_mode should return true when .fips_mode=true"

test/openssl/test_provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def test_openssl_legacy_provider
5858

5959
# this is required because OpenSSL::Provider methods change global state
6060
def with_openssl(code, **opts)
61-
assert_separately([{ "OSSL_MDEBUG" => nil }, "-ropenssl"], <<~"end;", **opts)
61+
assert_separately(["-ropenssl"], <<~"end;", **opts)
6262
#{code}
6363
end;
6464
end

test/openssl/utils.rb

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,6 @@
44
rescue LoadError
55
end
66

7-
# Compile OpenSSL with crypto-mdebug and run this test suite with OSSL_MDEBUG=1
8-
# environment variable to enable memory leak check.
9-
if ENV["OSSL_MDEBUG"] == "1"
10-
if OpenSSL.respond_to?(:print_mem_leaks)
11-
OpenSSL.mem_check_start
12-
13-
END {
14-
GC.start
15-
case OpenSSL.print_mem_leaks
16-
when nil
17-
warn "mdebug: check what is printed"
18-
when true
19-
raise "mdebug: memory leaks detected"
20-
end
21-
}
22-
else
23-
warn "OSSL_MDEBUG=1 is specified but OpenSSL is not built with crypto-mdebug"
24-
end
25-
end
26-
277
require "test/unit"
288
require "core_assertions"
299
require "tempfile"

0 commit comments

Comments
 (0)