Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial fix of t/local/31_rsa_generate_key.t memory leaks #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nataraj-hates-MS-for-stealing-github
Copy link

@nataraj-hates-MS-for-stealing-github nataraj-hates-MS-for-stealing-github commented Jan 3, 2025

If you build perl and Net::SSLleay with Address Sanitizer and run tests, t/local/31_rsa_generate_key.t will fail with some Memory Leak error messages. There are two parts of this problem.

Second part: You should explicitly free RSA structure created with RSA_generate_key, when it is no longer in use this will prevent unnecessary memory leaks. This patch solves this problem.

First part: Test that checks failure with not-proper callback scalar value

dies_like(sub {
        Net::SSLeay::RSA_generate_key(2048, 0x10001, 1);
}, qr/Undefined subroutine &main::1 called/, 'RSA_generate_key with invalid callback');

also causes memory leak.

As far as I can get this happens because RSA_generate_key from SSLeay.xs allocate something, then calls RSA_generate_key_ex with ssleay_RSA_generate_key_cb_invoke as a callback. And ssleay_RSA_generate_key_cb_invoke calls count = call_sv( cb->func, G_VOID|G_DISCARD ); that throws an exception if cb->func is not a function. Thus we do not free what have been allocated in RSA_generate_key and go straight to dies_like exception catcher.

I guess best solution would be to catch that exception in RSA_generate_key, free the staff, and then rethrow it. Because there can be any exception in a call back, even user generated. But such trick is beyond my power for now.

So this patch will fix only RSA_free related things.

PS You can find instruction on how to build perl in this module using ASan in #469

PPS please refer me as NATARAJ (Nikolay Shaplov) if you ever would like to mention me anywhere...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant