-
Notifications
You must be signed in to change notification settings - Fork 1
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
Using old pointer after reallocating new buffer #2
base: EC_MOCK_PEER
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, but the fix can be simplified and corrected according to my comment.
src/objects.c
Outdated
void *ptr = OPENSSL_realloc(key->attrs, sizeof(CK_ATTRIBUTE) * (key->numattrs + add_attrs)); | ||
if (!ptr) { | ||
key->attrs = OPENSSL_realloc(key->attrs, sizeof(CK_ATTRIBUTE) * (key->numattrs + add_attrs)); | ||
if (!key->attrs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On failure realloc will leave the original pointer untouched, so the correct way is to use ptr, and only if it is not null then key->attrs = ptr;
That was the original intention of this code and the bug is the missing overwriting of key->attrs after the null check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @simo5
Updated the code, thanks for the pointer.
Below issue is reported while running TLS1.3:- p11prov_DeriveKey:Host out of memory Issue occurs because we are trying to use deallocated memory pointer after reallocating new memory due to which key->attrs get corrupted and finally cause issue in importing correct peer key. Signed-off-by: Kshitiz Varshney <[email protected]>
21d7789
to
d9e9f47
Compare
Oh I just realized this PR is on my personal repo, I will integrate the original patch and your fix on top of another PR I am working on in the same area, but it may take me a few days. |
Below issue is reported while running TLS1.3:-
p11prov_DeriveKey:Host out of memory
Issue occurs because we are trying to use deallocated memory pointer after reallocating new memory due to which key->attrs get corrupted and finally cause issue in importing correct peer key.