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

RolesAnywhere-4976: Fix failures when module.GetAttributeValue modifies #60

Merged
merged 2 commits into from
Nov 17, 2023

Conversation

13ajay
Copy link
Contributor

@13ajay 13ajay commented Oct 30, 2023

Description of changes:

  • The previous code would reuse slices of type []*pkcs11.Attribute when attempting to find the values of attributes associated with objects in PKCS#11.

  • The current version will reassign the entire slice to the variable used in the call to module.GetAttributeValue. This prevents potential index out of bounds accesses when assigning to individual elements in the slice (which could've been modified by the previous module.GetAttributeValue call).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

the size of the slice parameter

 * The previous code would reuse slices of type []*pkcs11.Attribute when
   attempting to find the values of attributes associated with objects
   in PKCS#11.

 * The current version will reassign the entire slice to the variable
   used in the call to module.GetAttributeValue. This prevents potential
   index out of bounds accesses when assigning to individual elements in
   the slice (which could've been modified by the previous
   module.GetAttributeValue call).
@@ -286,13 +286,17 @@ func getCertsInSession(module *pkcs11.Ctx, slotId uint, session pkcs11.SessionHa
// Fetch the CKA_ID and CKA_LABEL of the matching cert(s), so
// that they can be used later when hunting for the matching
// key.
crtAttributes[0] = pkcs11.NewAttribute(pkcs11.CKA_ID, 0)
crtAttributes = []*pkcs11.Attribute{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the implication for memory? I suspect that it's really minor, but I don't know the Go memory model well enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it's minor. The object that gets lost through the assignment here (since it can no longer be referenced later in the code) should be garbage collected later on.

@13ajay 13ajay merged commit 43f2060 into main Nov 17, 2023
1 check passed
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.

2 participants