Skip to content

Commit eb962a7

Browse files
Sashant8m
authored andcommitted
remove all atexit() tests in shlibloadtest
The shlibloadtest used atexit() handler to verify library pinning works as expected. The libcrypto no longer arms atexit handler which also used to fire upon shlib unload. We can not use the atexit mechansim to test shared library pinning. If the shlibload test does not crash on exit, then library pinning must work. Fixes openssl/project#1869 Reviewed-by: Neil Horman <nhorman@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> MergeDate: Fri Feb 13 15:15:04 2026 (Merged from #29987)
1 parent d2f54e1 commit eb962a7

File tree

2 files changed

+15
-81
lines changed

2 files changed

+15
-81
lines changed

test/recipes/90-test_shlibload.t

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,47 +23,20 @@ plan skip_all => "Test is disabled on AIX" if config('target') =~ m|^aix|;
2323
plan skip_all => "Test is disabled on NonStop" if config('target') =~ m|^nonstop|;
2424
plan skip_all => "Test only supported in a dso build" if disabled("dso");
2525
plan skip_all => "Test is disabled in an address sanitizer build" unless disabled("asan");
26-
plan skip_all => "Test is disabled in no-atexit build" if disabled("atexit");
2726

28-
plan tests => 8;
27+
plan tests => 4;
2928

3029
my $libcrypto = platform->sharedlib('libcrypto');
3130
my $libssl = platform->sharedlib('libssl');
32-
my $atexit_outfile;
3331

34-
$atexit_outfile = 'atexit-cryptofirst.txt';
35-
1 while unlink $atexit_outfile;
36-
ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $atexit_outfile])),
37-
"running shlibloadtest -crypto_first $atexit_outfile");
38-
ok(check_atexit($atexit_outfile));
32+
ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl])),
33+
"running shlibloadtest -crypto_first");
3934

40-
$atexit_outfile = 'atexit-sslfirst.txt';
41-
1 while unlink $atexit_outfile;
42-
ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $atexit_outfile])),
43-
"running shlibloadtest -ssl_first $atexit_outfile");
44-
ok(check_atexit($atexit_outfile));
35+
ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl])),
36+
"running shlibloadtest -ssl_first");
4537

46-
$atexit_outfile = 'atexit-justcrypto.txt';
47-
1 while unlink $atexit_outfile;
48-
ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $atexit_outfile])),
49-
"running shlibloadtest -just_crypto $atexit_outfile");
50-
ok(check_atexit($atexit_outfile));
38+
ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl])),
39+
"running shlibloadtest -just_crypto");
5140

52-
$atexit_outfile = 'atexit-dsoref.txt';
53-
1 while unlink $atexit_outfile;
54-
ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $atexit_outfile])),
55-
"running shlibloadtest -dso_ref $atexit_outfile");
56-
ok(check_atexit($atexit_outfile));
57-
58-
sub check_atexit {
59-
my $filename = shift;
60-
61-
open my $fh, '<', $filename;
62-
return 0 unless defined $fh;
63-
64-
my $data = <$fh>;
65-
66-
return 1 if (defined $data && $data =~ m/atexit\(\) run/);
67-
68-
return 0;
69-
}
41+
ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl])),
42+
"running shlibloadtest -dso_ref");

test/shlibloadtest.c

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,9 @@ typedef enum test_types_en {
3838
static TEST_TYPE test_type;
3939
static const char *path_crypto;
4040
static const char *path_ssl;
41-
static const char *path_atexit;
4241

4342
#ifdef SD_INIT
4443

45-
static int atexit_handler_done = 0;
46-
47-
static void atexit_handler(void)
48-
{
49-
FILE *atexit_file = fopen(path_atexit, "w");
50-
51-
if (atexit_file == NULL)
52-
return;
53-
54-
fprintf(atexit_file, "atexit() run\n");
55-
fclose(atexit_file);
56-
atexit_handler_done++;
57-
}
58-
5944
static int test_lib(void)
6045
{
6146
SD ssllib = SD_INIT;
@@ -143,23 +128,17 @@ static int test_lib(void)
143128
goto end;
144129
}
145130

146-
if (atexit(atexit_handler) != 0) {
147-
fprintf(stderr, "Failed to register atexit handler\n");
148-
goto end;
149-
}
150-
151131
if (test_type == DSO_REFTEST) {
152132
#ifdef DSO_DLFCN
153133
DSO_dsobyaddr_t myDSO_dsobyaddr;
154134
DSO_free_t myDSO_free;
155135

156136
/*
157-
* This is resembling the code used in ossl_init_base() and
158-
* atexit() to block unloading the library after dlclose().
159-
* We are not testing this on Windows, because it is done there in a
160-
* completely different way. Especially as a call to DSO_dsobyaddr()
161-
* will always return an error, because DSO_pathbyaddr() is not
162-
* implemented there.
137+
* This is resembling the code used in ossl_init_base() to block
138+
* unloading the library after dlclose(). We are not testing this on
139+
* Windows, because it is done there in a completely different way.
140+
* Especially as a call to DSO_dsobyaddr() will always return an error,
141+
* because DSO_pathbyaddr() is not implemented there.
163142
*/
164143
if (!sd_sym(cryptolib, "DSO_dsobyaddr", &symbols[0].sym)
165144
|| !sd_sym(cryptolib, "DSO_free", &symbols[1].sym)) {
@@ -197,23 +176,6 @@ static int test_lib(void)
197176
ssllib = SD_INIT;
198177
}
199178

200-
#if defined(OPENSSL_NO_PINSHARED) \
201-
&& defined(__GLIBC__) \
202-
&& defined(__GLIBC_PREREQ) \
203-
&& defined(OPENSSL_SYS_LINUX)
204-
#if __GLIBC_PREREQ(2, 3)
205-
/*
206-
* If we didn't pin the so then we are hopefully on a platform that supports
207-
* running atexit() on so unload. If not we might crash. We know this is
208-
* true on linux since glibc 2.2.3
209-
*/
210-
if (atexit_handler_done != 1) {
211-
fprintf(stderr, "atexit() handler did not run\n");
212-
goto end;
213-
}
214-
#endif
215-
#endif
216-
217179
result = 1;
218180
end:
219181
if (cryptolib != SD_INIT)
@@ -233,7 +195,7 @@ int main(int argc, char *argv[])
233195
{
234196
const char *p;
235197

236-
if (argc != 5) {
198+
if (argc != 4) {
237199
fprintf(stderr, "Incorrect number of arguments\n");
238200
return 1;
239201
}
@@ -254,7 +216,6 @@ int main(int argc, char *argv[])
254216
}
255217
path_crypto = argv[2];
256218
path_ssl = argv[3];
257-
path_atexit = argv[4];
258219
if (path_crypto == NULL || path_ssl == NULL) {
259220
fprintf(stderr, "Invalid libcrypto/libssl path\n");
260221
return 1;

0 commit comments

Comments
 (0)