Skip to content

fix: return no slots when C_GetSlotList counts none - #382

Open
davidgraeff wants to merge 1 commit into
parallaxsecond:mainfrom
davidgraeff:fix/get-slots-zero-count
Open

davidgraeff wants to merge 1 commit into
parallaxsecond:mainfrom
davidgraeff:fix/get-slots-zero-count

Conversation

@davidgraeff

Copy link
Copy Markdown
  • get_slots, which backs get_all_slots and get_slots_with_token, first asks C_GetSlotList for the count. It then calls again with a buffer of that size, and loops while the module answers CKR_BUFFER_TOO_SMALL.
  • With no slots, the second call passes an empty buffer. p11-kit's client module (p11-kit-client.so, talking to a p11-kit server that exports no token) answers that with CKR_BUFFER_TOO_SMALL and a count of 0. The loop never ends: the caller spins at full CPU, and so does the server answering it.
  • Fix: return an empty list when the first call counts no slots, since there is nothing to fetch.
  • Testing: cargo build, cargo fmt --check and cargo clippy --all-targets -D warnings pass. SoftHSM always offers a free slot, so the test suite cannot reach this path.

With no slots, get_slots asked again with an empty buffer. p11-kit's
client module answers that with CKR_BUFFER_TOO_SMALL and a count of 0,
so the retry loop never ended and the caller spun at full CPU.

Signed-off-by: David Gräff <66436+davidgraeff@users.noreply.github.com>
@davidgraeff
davidgraeff force-pushed the fix/get-slots-zero-count branch from 8dc9605 to 60f5d76 Compare November 18, 2026 20:51
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