forked from openxpki/Crypt-PKCS10
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this was two different leaks rolled into one, which i will explain below. i also have to note the test still leaks *some* objects, but i don't have the time to do full analysis on that modules used to diagnose the leaks: Net::Prometheus, Devel::Gladiator, Devel::FindRef, Devel::Cycle openxpki#1 is the globals in the parser holding on to things normally deciding when to clean these up could be a little tricky, but the parsing appears to be contained entirely within the _new method, so we can declare them local and have perl reset them at the end of scope optimally Convert::ASN1 would take care of this so they're deleted after they're needed; as well as instanced per object or creation of new parsers guarded while one is currently active openxpki#2 is PKCS10 creating the object, running ->find on it, which returns a *shallow* copy with a reference to a config hash in the original object, then puts said shallow copy into the config hash of the original object, which creates a cycle at first i thought weaken would be the more appropriate option here, but that simply crashed on trying to parse certain certs, so a deep clone is used and seems to fix the issue
- Loading branch information
1 parent
83f3f1a
commit 6b54539
Showing
3 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env perl | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Crypt::PKCS10; | ||
|
||
run(); | ||
|
||
sub run { | ||
Crypt::PKCS10->setAPIversion(1); | ||
|
||
my $string = "-----BEGIN NEW CERTIFICATE REQUEST----- | ||
MIIEcTCCA1kCAQAweDELMAkGA1UEBhMCREUxDzANBgNVBAgMBkJheWVybjEQMA4GA1UEBwwHS3JvbmFjaDEgMB4GA1UECgwXTHVj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AAOCAQEAwAKgBQ/OsudTtQ9AiI6bC6Wb0K2uLMabgXvpa06ESZA3YO/Wd70IiAcMVdgdxhMHW+CW78c8YZ/E4JJw4Riu13JTuM3FuWBa/VH3D6TGN7kVGEBEGh98vaxK6RhlqQVdGMpqrOXtPTg5BRQUR4hP3h9fCXqYB59txyWxbG8fJ1YGALNJF95uiG+IE7/N4379hPT68/m4Bj3XLt1SmomtlqO8A+AemXWKZSacaP9KKggFnkxSC9BbjRi6V785URmwPgFwq20mpvIBQWphQKKBzeDoVRThwyI+RzwnX3XeJ8wDPWf/whlxkJfW3EYtGDcRkoMNykdirPE/JbN0MtIgoA== | ||
-----END NEW CERTIFICATE REQUEST-----"; | ||
|
||
my $pkcs10 = Crypt::PKCS10->new($string); | ||
ok( $pkcs10, "got a parse result" ); | ||
is( Crypt::PKCS10->error, undef, "no errors parsing the CSR" ); | ||
|
||
$pkcs10->commonName; | ||
$pkcs10->countryName; | ||
$pkcs10->stateOrProvinceName; | ||
$pkcs10->organizationName; | ||
$pkcs10->emailAddress; | ||
$pkcs10->extensionPresent('subjectAltName'); | ||
$pkcs10->extensionValue('subjectAltName'); | ||
$pkcs10->commonName; | ||
$pkcs10->csrRequest(1); | ||
$pkcs10 = undef; | ||
|
||
if ( not eval { require Net::Prometheus } ) { | ||
diag "Net::Prometheus not installed, skipping leak test"; | ||
ok 1; | ||
} | ||
else { # there are some leaks left, but i ran out of time on those | ||
note $_ for grep /UDAG|Convert::ASN1/, # | ||
split /\n/, | ||
Net::Prometheus->new->render( { perl_collector_detail => 2 } ); | ||
is( | ||
( Net::Prometheus::PerlCollector::count_heap(2) )[3] # | ||
{"Convert::ASN1::parser"}, | ||
undef, | ||
"no leak" | ||
); | ||
} | ||
|
||
done_testing; | ||
|
||
return; | ||
} |