Skip to content

Fix bugs found with static analysis#168

Merged
dgarske merged 11 commits intowolfSSL:masterfrom
LinuxJedi:f-fixes
Mar 19, 2026
Merged

Fix bugs found with static analysis#168
dgarske merged 11 commits intowolfSSL:masterfrom
LinuxJedi:f-fixes

Conversation

@LinuxJedi
Copy link
Copy Markdown
Member

  • Set slotID in C_GetSessionInfo response
  • Guard CKA_EXTRACTABLE from being changed FALSE to TRUE
  • Fix several memory leaks on error paths
  • Fix CKM_RSA_PKCS_PSS mechanism info size
  • Fix SHA1 hash error handling
  • Fix C_FindObjectsInit to allow NULL template with zero count

C_GetSessionInfo never populated pInfo->slotID, leaving it uninitialized.
Add WP11_Session_GetSlotId() accessor and set the field. Add test
assertion to verify slotID matches the slot used to open the session.

F-813
Per PKCS#11 spec section 4.7, once CKA_EXTRACTABLE is set to FALSE
it must not be changed back to TRUE. Add a guard in SetAttributeValue()                                  matching the existing CKA_SENSITIVE protection, gated on !newObject so
it only applies to C_SetAttributeValue, not C_CreateObject. Add test
to verify both directions (FALSE->TRUE rejected, TRUE->FALSE allowed).

F-819
Per PKCS#11 spec, C_FindObjectsInit(hSession, NULL_PTR, 0) should
match all objects. The implementation unconditionally rejected
pTemplate == NULL with CKR_ARGUMENTS_BAD, even when ulCount == 0.

Change the check to only reject NULL when ulCount != 0 (a genuine
error). Add test that verifies both the match-all case and the
NULL-with-nonzero-count error case.

F-816
Copilot AI review requested due to automatic review settings March 18, 2026 15:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a set of PKCS#11 correctness issues found via static analysis, and adds/extends test coverage for the affected behaviors.

Changes:

  • Populate slotID in C_GetSessionInfo and add a corresponding session accessor + test assertion.
  • Prevent changing CKA_EXTRACTABLE from FALSE to TRUE and add a regression test for it.
  • Improve error-path cleanup (AES free, object free) and align C_FindObjectsInit(NULL, 0) with PKCS#11 v3.0 by adding a dedicated test program.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
wolfpkcs11/internal.h Declares new session accessor for slot id.
src/internal.c Implements slot id accessor, fixes SHA1 hash error handling, frees AES context.
src/slot.c Fixes RSA-PSS mechanism info bounds; sets slotID in session info.
src/crypto.c Enforces CKA_EXTRACTABLE immutability (FALSE→TRUE), fixes leaks on error paths, adjusts C_FindObjectsInit NULL-template handling.
tests/pkcs11test.c Adds assertions for slotID and new extractable attribute regression test.
tests/include.am Adds a new test program build target.
tests/find_objects_null_template_test.c New test for C_FindObjectsInit(NULL, 0) behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread tests/include.am
Comment thread src/crypto.c
Comment thread src/internal.c
Comment thread tests/find_objects_null_template_test.c Outdated
Comment thread tests/find_objects_null_template_test.c
* `getVarLen` should be re-initialized before the second
`WP11_Object_GetAttr` call.

* Session leaks if `C_Login` fails.
@dgarske dgarske merged commit 3543f30 into wolfSSL:master Mar 19, 2026
70 checks 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.

4 participants